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 | | +--------------------+------------+----+---------------+--------------+ | MojangLoginHandler | PingInfo | PlayerList | Others.... | +--------------------+------------+--------------------+--------------+
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 will provide later.
Index ¶
- Constants
- type Component
- type Game
- type GamePlay
- type GlobalChat
- type KeepAlive
- type Level
- type LevelInfo
- type ListPingHandler
- type LoginChecker
- type LoginHandler
- type MojangLoginHandler
- type Packet757
- type Packet758
- type PacketHandler
- type PacketQueue
- type PingInfo
- type Player
- type PlayerDelaySource
- type PlayerInfo
- type PlayerList
- func (p *PlayerList) AddPlayer(player *Player)
- func (p *PlayerList) CheckPlayer(name string, id uuid.UUID, protocol int32) (ok bool, reason chat.Message)
- func (p *PlayerList) Init(*Game)
- func (p *PlayerList) MaxPlayer() int
- func (p *PlayerList) OnlinePlayer() int
- func (p *PlayerList) PlayerSamples() (sample []PlayerSample)
- func (p *PlayerList) RemovePlayer(player *Player)
- func (p *PlayerList) Run(context.Context)
- type PlayerSample
- type Server
- type SimpleDim
- type WritePacketError
Constants ¶
const ProtocolName = "1.18.2"
const ProtocolVersion = 758
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Game ¶ added in v1.18.1
type Game struct { Dim Level // contains filtered or unexported fields }
func (*Game) AcceptPlayer ¶ added in v1.18.1
func (*Game) AddHandler ¶ added in v1.18.1
func (g *Game) AddHandler(ph *PacketHandler)
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, protocol int32, conn *net.Conn) }
type GlobalChat ¶ added in v1.18.1
type GlobalChat struct {
// contains filtered or unexported fields
}
func NewGlobalChat ¶ added in v1.18.1
func NewGlobalChat() *GlobalChat
func (*GlobalChat) AddPlayer ¶ added in v1.18.1
func (g *GlobalChat) AddPlayer(player *Player)
func (*GlobalChat) Init ¶ added in v1.18.1
func (g *GlobalChat) Init(game *Game)
func (*GlobalChat) RemovePlayer ¶ added in v1.18.1
func (g *GlobalChat) RemovePlayer(p *Player)
func (*GlobalChat) Run ¶ added in v1.18.1
func (g *GlobalChat) Run(ctx context.Context)
type KeepAlive ¶ added in v1.18.1
type KeepAlive struct {
// contains filtered or unexported fields
}
func NewKeepAlive ¶ added in v1.18.1
func NewKeepAlive() (k *KeepAlive)
func (*KeepAlive) AddPlayerDelayUpdateHandler ¶ added in v1.18.1
func (*KeepAlive) RemovePlayer ¶ added in v1.18.1
RemovePlayer implement Component for KeepAlive
type ListPingHandler ¶
type ListPingHandler interface { // Name of the server version Name() string // Protocol number Protocol() int MaxPlayer() int OnlinePlayer() int // PlayerSamples is a short list of some player in the server PlayerSamples() []PlayerSample 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 ¶ added in v1.18.1
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 client by "LoginDisconnect" packet.
type LoginHandler ¶
type LoginHandler interface {
AcceptLogin(conn *net.Conn, protocol int32) (name string, id uuid.UUID, 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 // 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 optional field and can be set to nil. LoginChecker }
MojangLoginHandler is a standard LoginHandler that implement both online and offline login progress. This implementation also support custom LoginChecker. None of Custom login packet (also called LoginPluginRequest/Response) is support by this implementation. To do that, implement your own LoginHandler imitate this code.
func (*MojangLoginHandler) AcceptLogin ¶
func (d *MojangLoginHandler) AcceptLogin(conn *net.Conn, protocol int32) (name string, id uuid.UUID, err error)
AcceptLogin implement LoginHandler for MojangLoginHandler
type Packet758 ¶ added in v1.18.2
Packet758 is a packet in protocol 757. We are using type system to force programmers to update packets.
type PacketHandler ¶ added in v1.18.1
type PacketHandler struct { ID int32 F packetHandlerFunc }
type PacketQueue ¶ added in v1.18.1
type PacketQueue struct {
// contains filtered or unexported fields
}
func NewPacketQueue ¶ added in v1.18.1
func NewPacketQueue() (p *PacketQueue)
func (*PacketQueue) Close ¶ added in v1.18.1
func (p *PacketQueue) Close()
func (*PacketQueue) Pull ¶ added in v1.18.1
func (p *PacketQueue) Pull() (packet pk.Packet, ok bool)
func (*PacketQueue) Push ¶ added in v1.18.1
func (p *PacketQueue) Push(packet pk.Packet)
type PingInfo ¶ added in v1.18.1
type PingInfo struct { *PlayerList // contains filtered or unexported fields }
PingInfo implement ListPingHandler.
func NewPingInfo ¶ added in v1.18.1
func NewPingInfo(list *PlayerList, name string, protocol int, motd chat.Message, icon image.Image) (p *PingInfo, err error)
NewPingInfo crate a new PingInfo, the icon can be nil.
func (*PingInfo) Description ¶ added in v1.18.1
type Player ¶ added in v1.18.1
type Player struct { *net.Conn Name string uuid.UUID EntityID int32 Gamemode byte // contains filtered or unexported fields }
func (*Player) WritePacket ¶ added in v1.18.1
WritePacket to player client. The type of parameter will update per version.
type PlayerDelaySource ¶ added in v1.18.2
type PlayerInfo ¶ added in v1.18.2
type PlayerInfo struct {
// contains filtered or unexported fields
}
func NewPlayerInfo ¶ added in v1.18.2
func NewPlayerInfo(updateFreq time.Duration, delaySource PlayerDelaySource) *PlayerInfo
func (*PlayerInfo) AddPlayer ¶ added in v1.18.2
func (p *PlayerInfo) AddPlayer(player *Player)
func (*PlayerInfo) Init ¶ added in v1.18.2
func (p *PlayerInfo) Init(*Game)
func (*PlayerInfo) RemovePlayer ¶ added in v1.18.2
func (p *PlayerInfo) RemovePlayer(player *Player)
func (*PlayerInfo) Run ¶ added in v1.18.2
func (p *PlayerInfo) Run(ctx context.Context)
type PlayerList ¶ added in v1.18.1
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 ¶ added in v1.18.1
func NewPlayerList(maxPlayers int) *PlayerList
NewPlayerList create a PlayerList which implement ListPingHandler.
func (*PlayerList) AddPlayer ¶ added in v1.18.1
func (p *PlayerList) AddPlayer(player *Player)
AddPlayer implement Component for PlayerList
func (*PlayerList) CheckPlayer ¶ added in v1.18.1
func (p *PlayerList) CheckPlayer(name string, id uuid.UUID, protocol int32) (ok bool, reason chat.Message)
CheckPlayer implement LoginChecker for PlayerList
func (*PlayerList) Init ¶ added in v1.18.1
func (p *PlayerList) Init(*Game)
Init implement Component for PlayerList
func (*PlayerList) MaxPlayer ¶ added in v1.18.1
func (p *PlayerList) MaxPlayer() int
func (*PlayerList) OnlinePlayer ¶ added in v1.18.1
func (p *PlayerList) OnlinePlayer() int
func (*PlayerList) PlayerSamples ¶ added in v1.18.1
func (p *PlayerList) PlayerSamples() (sample []PlayerSample)
func (*PlayerList) RemovePlayer ¶ added in v1.18.1
func (p *PlayerList) RemovePlayer(player *Player)
RemovePlayer implement Component for PlayerList
func (*PlayerList) Run ¶ added in v1.18.1
func (p *PlayerList) Run(context.Context)
Run implement Component for PlayerList
type PlayerSample ¶
type Server ¶
type Server struct { ListPingHandler LoginHandler GamePlay }
type SimpleDim ¶ added in v1.18.1
type SimpleDim struct {
// contains filtered or unexported fields
}
func NewSimpleDim ¶ added in v1.18.1
func (*SimpleDim) PlayerJoin ¶ added in v1.18.1
func (*SimpleDim) PlayerQuit ¶ added in v1.18.1
type WritePacketError ¶ added in v1.18.1
func (WritePacketError) Error ¶ added in v1.18.1
func (s WritePacketError) Error() string
func (WritePacketError) Unwrap ¶ added in v1.18.1
func (s WritePacketError) Unwrap() error