minecraft

package
v0.0.0-...-80caa2b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2022 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultServerJar        = "server.jar"
	DefaultServerProperties = "server.properties"
	DefaultLog4JConf        = "mcvisor_log4J.xml"
	JaveHomeEnvName         = "JAVA_HOME"
)
View Source
const (
	Stopped     Status = "stopped"
	Starting    Status = "starting"
	Started     Status = "started"
	Ready       Status = "ready"
	Unreachable Status = "unreachable"
	Stopping    Status = "stopping"

	StartTarget    Target = "start"
	StopTarget     Target = "stop"
	RestartTarget  Target = "restart"
	ShutdownTarget Target = "shutdown"

	StatusCommand   commands.Name = "status"
	StartCommand    commands.Name = "start"
	StopCommand     commands.Name = "stop"
	RestartCommand  commands.Name = "restart"
	ShutdownCommand commands.Name = "shutdown"
	ConsoleCommand  commands.Name = "console"
)
View Source
const JavaCmd string = "bin/java"
View Source
const (
	OnlineCommand commands.Name = "online"
)

Variables

View Source
var (
	ErrPingDisabled = errors.New("both query and status are disabled server-side")
	ErrPingNever    = errors.New("status unknown")
)
View Source
var (
	ConsoleCommandTimeout = 5 * time.Second

	ErrStoppedServer = errors.New("server is stopped")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Server *ServerConfig `json:"server"`
	Java   *JavaConfig   `json:"java"`
}

func NewConfig

func NewConfig(baseDir string) *Config

func (Config) Command

func (c Config) Command() []string

func (Config) Env

func (c Config) Env() []string

func (Config) WorkingDir

func (c Config) WorkingDir() string

type JavaConfig

type JavaConfig struct {
	Home    string   `json:"home,omitempty" validate:"dir"`
	Options []string `json:"options"`
}

func (JavaConfig) AbsJavaCommand

func (c JavaConfig) AbsJavaCommand() string

func (JavaConfig) Command

func (c JavaConfig) Command() []string

type NetworkConfig

type NetworkConfig struct {
	Host              string        `json:"host,omitempty" validate:"omitempty,ip|hostname|fqdn"`
	Port              uint16        `json:"port,omitempty"`
	PingPeriod        time.Duration `json:"ping_interval"`
	ConnectionTimeout time.Duration `json:"connection_timeout"`
	ResponseTimeout   time.Duration `json:"response_timeout"`
}

type PingFailed

type PingFailed struct {
	When   time.Time
	Reason error
}

func (*PingFailed) Error

func (p *PingFailed) Error() string

func (*PingFailed) Fields

func (p *PingFailed) Fields() log.Fields

func (PingFailed) IsSuccess

func (PingFailed) IsSuccess() bool

type PingSucceeded

type PingSucceeded struct {
	When          time.Time
	Latency       time.Duration
	MaxPlayers    uint
	OnlinePlayers uint
	PlayerList    []string
}

func (*PingSucceeded) Fields

func (p *PingSucceeded) Fields() log.Fields

func (PingSucceeded) IsSuccess

func (PingSucceeded) IsSuccess() bool

func (*PingSucceeded) String

func (p *PingSucceeded) String() string

type Pinger

type Pinger struct {
	*ServerConfig
	*events.Dispatcher
	// contains filtered or unexported fields
}

func NewPinger

func NewPinger(config *ServerConfig, statuser Statuser, dispatcher *events.Dispatcher) *Pinger

func (*Pinger) Ping

func (p *Pinger) Ping(when time.Time, ctx context.Context)

func (*Pinger) Serve

func (p *Pinger) Serve(ctx context.Context) (err error)

type PingerEvent

type PingerEvent interface {
	IsSuccess() bool
}

type Server

type Server struct {
	*Config
	// contains filtered or unexported fields
}

func NewServer

func NewServer(conf *Config, dispatcher *events.Dispatcher) *Server

func (*Server) Serve

func (s *Server) Serve(ctx context.Context) (err error)

func (*Server) Shutdown

func (s *Server) Shutdown()

func (*Server) Start

func (s *Server) Start()

func (*Server) Status

func (s *Server) Status() Status

type ServerConfig

type ServerConfig struct {
	BaseDir    string         `json:"-"`
	WorkingDir string         `json:"working_dir,omitempty"`
	Jar        string         `json:"jar,omitempty"`
	Properties string         `json:"properties,omitempty"`
	Log4JConf  string         `json:"log4jxml,omitempty"`
	Options    []string       `json:"options"`
	Network    *NetworkConfig `json:"network"`
}

func (ServerConfig) AbsLog4JConf

func (c ServerConfig) AbsLog4JConf() string

func (ServerConfig) AbsServerProperties

func (c ServerConfig) AbsServerProperties() string

func (ServerConfig) AbsWorkingDir

func (c ServerConfig) AbsWorkingDir() string

func (ServerConfig) Command

func (c ServerConfig) Command() []string

type ServerOutput

type ServerOutput string

type Status

type Status string

func (Status) DiscordNotification

func (s Status) DiscordNotification() string

func (Status) DiscordStatus

func (s Status) DiscordStatus() string

func (Status) IsOneOf

func (s Status) IsOneOf(status ...Status) bool

func (Status) IsRunning

func (s Status) IsRunning() bool

type Statuser

type Statuser interface {
	Status() Status
}

type Target

type Target string

func (Target) DiscordNotification

func (t Target) DiscordNotification() string

func (Target) MustStart

func (t Target) MustStart() bool

func (Target) MustStop

func (t Target) MustStop() bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL