Documentation ¶
Overview ¶
Package server provide a minecraft server framework. You can build the server you want by combining the various functional modules provided here. An example can be found in examples/frameworkServer.
This package is under rapid development, and any API may be subject to break changes ¶
A server is roughly divided into two parts: Gate and GamePlay
+------------------------------------------------------------------------------+ | Go-MC Server Framework | |--------------------------------------+---------------------------------------| | Gate | GamePlay | |--------------------+-----------------+---------------+-----------------------| | LoginHandler | ListPingHandler | Others.. | |--------------------|------------+----+---------------|-----------------------+ | MojangLoginHandler | PingInfo | PlayerList | [go-mc/server], etc. | +--------------------+------------+--------------------+-----------------------+
Gate, which is used to respond to the client login request, provide login verification, respond to the List Ping Request and providing the online players' information.
Gameplay, which is used to handle all things after a player successfully logs in (that is, after the LoginSuccess package is sent), and is responsible for functions including player status, chunk management, keep alive, chat, etc.
The implement of Gameplay is provided at go-mc/server. You can also write your version.
Index ¶
- Constants
- type GamePlay
- type GameProfile
- type KeepAlive
- func (k *KeepAlive) AddPlayerDelayUpdateHandler(f func(c KeepAliveClient, delay time.Duration))
- func (k *KeepAlive) ClientJoin(client KeepAliveClient)
- func (k *KeepAlive) ClientLeft(client KeepAliveClient)
- func (k *KeepAlive) ClientTick(client KeepAliveClient)
- func (k *KeepAlive) Run(ctx context.Context)
- type KeepAliveClient
- type ListPingHandler
- type LoginChecker
- type LoginFailErr
- type LoginHandler
- type MojangLoginHandler
- type Packet757
- type Packet758
- type PacketQueue
- type PingInfo
- type PlayerList
- func (p *PlayerList) CheckPlayer(string, uuid.UUID, int32) (ok bool, reason chat.Message)
- func (p *PlayerList) ClientJoin(client PlayerListClient, player PlayerSample)
- func (p *PlayerList) ClientLeft(client PlayerListClient)
- func (p *PlayerList) Len() int
- func (p *PlayerList) MaxPlayer() int
- func (p *PlayerList) OnlinePlayer() int
- func (p *PlayerList) PlayerSamples() (sample []PlayerSample)
- func (p *PlayerList) Range(f func(PlayerListClient, PlayerSample))
- type PlayerListClient
- type PlayerSample
- type Pos
- type Rot
- type Server
- type WritePacketError
Constants ¶
const ( ProtocolName = "1.19.4" ProtocolVersion = 762 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GamePlay ¶
type GamePlay interface { // AcceptPlayer handle everything after "LoginSuccess" is sent. // // Note: the connection will be closed after this function returned. // You don't need to close the connection, but to keep not returning while the player is playing. AcceptPlayer(name string, id uuid.UUID, profilePubKey *user.PublicKey, properties []user.Property, protocol int32, conn *net.Conn) }
type GameProfile ¶
type KeepAlive ¶
type KeepAlive struct {
// contains filtered or unexported fields
}
func NewKeepAlive ¶
func NewKeepAlive() (k *KeepAlive)
func (*KeepAlive) AddPlayerDelayUpdateHandler ¶
func (k *KeepAlive) AddPlayerDelayUpdateHandler(f func(c KeepAliveClient, delay time.Duration))
func (*KeepAlive) ClientJoin ¶
func (k *KeepAlive) ClientJoin(client KeepAliveClient)
func (*KeepAlive) ClientLeft ¶
func (k *KeepAlive) ClientLeft(client KeepAliveClient)
func (*KeepAlive) ClientTick ¶
func (k *KeepAlive) ClientTick(client KeepAliveClient)
type KeepAliveClient ¶
type ListPingHandler ¶
type ListPingHandler interface { // Name of the server. // Vanilla server uses its version name, like "1.19.3". Name() string // The Protocol number. // Usually implemented as returning the protocol number the server currently used. // If the server supports multiple protocols, should be implemented as returning clientProtocol Protocol(clientProtocol int32) int MaxPlayer() int OnlinePlayer() int // PlayerSamples is a short list of players in the server. // Vanilla server returns up to 10 players in the list. PlayerSamples() []PlayerSample // Description also called MOTD, Message Of The Day. Description() *chat.Message // FavIcon should be a PNG image that is Base64 encoded // (without newlines: \n, new lines no longer work since 1.13) // and prepended with "data:image/png;base64,". // // This method can return empty string if no icon is set. FavIcon() string }
ListPingHandler collect server running status info which is used to handle client ping and list progress.
type LoginChecker ¶
type LoginChecker interface {
CheckPlayer(name string, id uuid.UUID, protocol int32) (ok bool, reason chat.Message)
}
LoginChecker is the interface to check if a player is allowed to log in the server. The checking could be anything, server player number, protocol version, blacklist or whitelist. If a player is not allowed to, the reason should be returned and will be sent to the client by "LoginDisconnect" packet.
type LoginFailErr ¶
type LoginFailErr struct {
// contains filtered or unexported fields
}
func (LoginFailErr) Error ¶
func (l LoginFailErr) Error() string
type LoginHandler ¶
type LoginHandler interface {
AcceptLogin(conn *net.Conn, protocol int32) (name string, id uuid.UUID, profilePubKey *user.PublicKey, properties []user.Property, err error)
}
LoginHandler is used to handle player login process, that is, from clientbound "LoginStart" packet to serverbound "LoginSuccess" packet.
type MojangLoginHandler ¶
type MojangLoginHandler struct { // OnlineMode enables to check player's account. // And also encrypt the connection after login. OnlineMode bool // EnforceSecureProfile enforce to check the player's profile public key EnforceSecureProfile bool // Threshold set the smallest size of raw network payload to compress. // Set to 0 to compress all packets. Set to -1 to disable compression. Threshold int // LoginChecker is used to apply some checks before sending "LoginSuccess" packet // (e.g., blacklist or is server full). // This is an optional field and can be set to nil. LoginChecker // contains filtered or unexported fields }
MojangLoginHandler is a standard LoginHandler that implement both online and offline login progress. This implementation also supports custom LoginChecker. None of Custom login packets (also called LoginPluginRequest/Response) is supported for this implementation. To do that, implement your own LoginHandler imitate this code.
type Packet757 ¶
Packet758 is a packet in protocol 757. We are using type system to force programmers to update packets.
type Packet758 ¶
Packet758 is a packet in protocol 757. We are using type system to force programmers to update packets.
type PingInfo ¶
type PingInfo struct {
// contains filtered or unexported fields
}
PingInfo implement ListPingHandler.
func NewPingInfo ¶
NewPingInfo crate a new PingInfo, the icon can be nil. Panic if icon's size is not 64x64.
func (*PingInfo) Description ¶
type PlayerList ¶
type PlayerList struct {
// contains filtered or unexported fields
}
PlayerList is a player list based on linked-list. This struct should not be copied after used.
func NewPlayerList ¶
func NewPlayerList(maxPlayers int) *PlayerList
NewPlayerList create a PlayerList which implement ListPingHandler.
func (*PlayerList) CheckPlayer ¶
CheckPlayer implements LoginChecker for PlayerList
func (*PlayerList) ClientJoin ¶
func (p *PlayerList) ClientJoin(client PlayerListClient, player PlayerSample)
func (*PlayerList) ClientLeft ¶
func (p *PlayerList) ClientLeft(client PlayerListClient)
func (*PlayerList) Len ¶
func (p *PlayerList) Len() int
func (*PlayerList) MaxPlayer ¶
func (p *PlayerList) MaxPlayer() int
func (*PlayerList) OnlinePlayer ¶
func (p *PlayerList) OnlinePlayer() int
func (*PlayerList) PlayerSamples ¶
func (p *PlayerList) PlayerSamples() (sample []PlayerSample)
func (*PlayerList) Range ¶
func (p *PlayerList) Range(f func(PlayerListClient, PlayerSample))
type PlayerListClient ¶
type PlayerSample ¶
type Server ¶
type Server struct { *log.Logger ListPingHandler LoginHandler GamePlay }
func (*Server) AcceptConn ¶
type WritePacketError ¶
func (WritePacketError) Error ¶
func (s WritePacketError) Error() string
func (WritePacketError) Unwrap ¶
func (s WritePacketError) Unwrap() error