Documentation ¶
Index ¶
- type Config
- type Listener
- type Server
- func (server *Server) Accept() (*player.Player, error)
- func (server *Server) Close() error
- func (server *Server) CloseOnProgramEnd()
- func (server *Server) JoinMessage(message string)
- func (server *Server) Listen(l Listener)
- func (server *Server) MaxPlayerCount() int
- func (server *Server) Player(uuid uuid.UUID) (*player.Player, bool)
- func (server *Server) PlayerByName(name string) (*player.Player, bool)
- func (server *Server) PlayerCount() int
- func (server *Server) PlayerProvider(provider player.Provider)
- func (server *Server) Players() []*player.Player
- func (server *Server) QuitMessage(message string)
- func (server *Server) Run() error
- func (server *Server) SetName(a ...interface{})
- func (server *Server) SetNamef(format string, a ...interface{})
- func (server *Server) Start() error
- func (server *Server) Uptime() time.Duration
- func (server *Server) World() *world.World
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // Network holds settings related to network aspects of the server. Network struct { // Address is the address on which the server should listen. Players may connect to this address in // order to join. Address string } Server struct { // Name is the name of the server as it shows up in the server list. Name string // ShutdownMessage is the message shown to players when the server shuts down. If empty, players will // be directed to the menu screen right away. ShutdownMessage string // AuthEnabled controls whether or not players must be connected to Xbox Live in order to join the server. AuthEnabled bool // JoinMessage is the message that appears when a player joins the server. Leave this empty to disable it. // %v is the placeholder for the username of the player JoinMessage string // QuitMessage is the message that appears when a player leaves the server. Leave this empty to disable it. // %v is the placeholder for the username of the player QuitMessage string } World struct { // Name is the name of the world that the server holds. A world with this name will be loaded and // the name will be displayed at the top of the player list in the in-game pause menu. Name string // Folder is the folder that the data of the world resides in. Folder string // SimulationDistance is the maximum distance in chunks that a chunk must be to a player in order for // it to receive random ticks. This field may be set to 0 to disable random block updates altogether. SimulationDistance int } Players struct { // MaxCount is the maximum amount of players allowed to join the server at the same time. If set // to 0, the amount of maximum players will grow every time a player joins. MaxCount int // MaximumChunkRadius is the maximum chunk radius that players may set in their settings. If they try // to set it above this number, it will be capped and set to the max. MaximumChunkRadius int // SaveData controls whether or not a player's data will be saved and loaded. If true, the server // will use the default LevelDB data provider and if false, an empty provider will be used. To use your // own provider, turn this value to false as you will still be able to pass your own provider. SaveData bool // Folder controls where the player data will be stored by the default LevelDB // player provider if it is enabled. Folder string } }
Config is the configuration of a Dragonfly server. It holds settings that affect different aspects of the server, such as its name and maximum players.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a configuration with the default values filled out.
type Listener ¶
type Listener interface { // Accept blocks until the next connection is established and returns it. An error is returned if the Listener was // closed using Close. Accept() (session.Conn, error) // Disconnect disconnects a connection from the Listener with a reason. Disconnect(conn session.Conn, reason string) error io.Closer }
Listener is a source for connections that may be listened on by a Server using Server.Listen. Proxies can use this to provide players from a different source.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server implements a Dragonfly server. It runs the main server loop and handles the connections of players trying to join the server.
func New ¶
New returns a new server using the Config passed. If nil is passed, a default configuration is returned. (A call to server.DefaultConfig().) The Logger passed will be used to log errors and information to. If nil is passed, a default Logger is used by calling logrus.New(). Note that no two servers should be active at the same time. Doing so anyway will result in unexpected behaviour.
func (*Server) Accept ¶
Accept accepts an incoming player into the server. It blocks until a player connects to the server. Accept returns an error if the Server is closed using a call to Close.
func (*Server) CloseOnProgramEnd ¶
func (server *Server) CloseOnProgramEnd()
CloseOnProgramEnd closes the server right before the program ends, so that all data of the server are saved properly.
func (*Server) JoinMessage ¶
JoinMessage changes the join message for all players on the server. Leave this empty to disable it. %v is the placeholder for the username of the player
func (*Server) Listen ¶
Listen makes the Server listen for new connections from the Listener passed. This may be used to listen for players on different interfaces. Note that the maximum player count of additional Listeners added is not enforced automatically. The limit must be enforced by the Listener.
func (*Server) MaxPlayerCount ¶
MaxPlayerCount returns the maximum amount of players that are allowed to play on the server at the same time. Players trying to join when the server is full will be refused to enter. If the config has a maximum player count set to 0, MaxPlayerCount will return Server.PlayerCount + 1.
func (*Server) Player ¶
Player looks for a player on the server with the UUID passed. If found, the player is returned and the bool returns holds a true value. If not, the bool returned is false and the player is nil.
func (*Server) PlayerByName ¶
PlayerByName looks for a player on the server with the name passed. If found, the player is returned and the bool returns holds a true value. If not, the bool is false and the player is nil
func (*Server) PlayerCount ¶
PlayerCount returns the current player count of the server. It is equivalent to calling len(server.Players()).
func (*Server) PlayerProvider ¶
PlayerProvider changes the data provider of a player to the provider passed. The provider will dictate the behaviour of player saving and loading. If nil is passed, the NopProvider will be used which does not read or write any data.
func (*Server) Players ¶
Players returns a list of all players currently connected to the server. Note that the slice returned is not updated when new players join or leave, so it is only valid for as long as no new players join or players leave.
func (*Server) QuitMessage ¶
QuitMessage changes the leave message for all players on the server. Leave this empty to disable it. %v is the placeholder for the username of the player
func (*Server) Run ¶
Run runs the server and blocks until it is closed using a call to Close(). When called, the server will accept incoming connections. Run will block the current goroutine until the server is stopped. To start the server on a different goroutine, use (*Server).Start() instead. After a call to Run, calls to Server.Accept() may be made to accept players into the server.
func (*Server) SetName ¶
func (server *Server) SetName(a ...interface{})
SetName sets the name of the Server, also known as the MOTD. This name is displayed in the server list. The formatting of the name passed follows the rules of fmt.Sprint.
func (*Server) SetNamef ¶
SetNamef sets the name of the Server, also known as the MOTD. This name is displayed in the server list. The formatting of the name passed follows the rules of fmt.Sprintf.
func (*Server) Start ¶
Start runs the server but does not block, unlike Run, but instead accepts connections on a different goroutine. Connections will be accepted until the listener is closed using a call to Close. Once started, players may be accepted using Server.Accept().
Directories ¶
Path | Synopsis |
---|---|
Package cmd implements a Minecraft specific command system, which may be used simply by 'plugging' it in and sending commands registered in an AvailableCommandsPacket.
|
Package cmd implements a Minecraft specific command system, which may be used simply by 'plugging' it in and sending commands registered in an AvailableCommandsPacket. |