dragonfly

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2021 License: MIT Imports: 28 Imported by: 0

Documentation

Index

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
		// MaximumPlayers 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.
		MaximumPlayers int
		// 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
		// 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
		// 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
	}
}

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 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

func New(c *Config, log *logrus.Logger) *Server

New returns a new server using the Config passed. If nil is passed, a default configuration is returned. (A call to dragonfly.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

func (server *Server) Accept() (*player.Player, error)

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) Close

func (server *Server) Close() error

Close closes the server, making any call to Run/Accept cancel immediately.

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

func (server *Server) JoinMessage(message string)

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) MaxPlayerCount

func (server *Server) MaxPlayerCount() int

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

func (server *Server) Player(uuid uuid.UUID) (*player.Player, bool)

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

func (server *Server) PlayerByName(name string) (*player.Player, bool)

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

func (server *Server) PlayerCount() int

PlayerCount returns the current player count of the server. It is equivalent to calling len(server.Players()).

func (*Server) Players

func (server *Server) Players() []*player.Player

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

func (server *Server) QuitMessage(message string)

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

func (server *Server) Run() error

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

func (server *Server) SetNamef(format string, a ...interface{})

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

func (server *Server) Start() error

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. One started, players may be accepted using Server.Accept().

func (*Server) Uptime

func (server *Server) Uptime() time.Duration

Uptime returns the duration that the server has been running for. Measurement starts the moment a call to Server.Start or Server.Run is made.

func (*Server) World

func (server *Server) World() *world.World

World returns the world of the server. Players will be spawned in this world and this world will be read from and written to when the world is edited.

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.
internal

Jump to

Keyboard shortcuts

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