server

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2023 License: MIT Imports: 26 Imported by: 0

README

Server

This package provide a very basic framework for server development.
For more example, go to this repo.

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

View Source
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 GameProfile struct {
	ID   uuid.UUID
	Name string
}

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)

func (*KeepAlive) Run

func (k *KeepAlive) Run(ctx context.Context)

Run implement Component for KeepAlive

type KeepAliveClient

type KeepAliveClient interface {
	SendKeepAlive(id int64)
	SendDisconnect(reason chat.Message)
}

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.

func (*MojangLoginHandler) AcceptLogin

func (d *MojangLoginHandler) AcceptLogin(conn *net.Conn, protocol int32) (name string, id uuid.UUID, profilePubKey *user.PublicKey, properties []user.Property, err error)

AcceptLogin implement LoginHandler for MojangLoginHandler

type Packet757

type Packet757 pk.Packet

Packet758 is a packet in protocol 757. We are using type system to force programmers to update packets.

type Packet758

type Packet758 pk.Packet

Packet758 is a packet in protocol 757. We are using type system to force programmers to update packets.

type PacketQueue

type PacketQueue = queue.Queue[pk.Packet]

type PingInfo

type PingInfo struct {
	// contains filtered or unexported fields
}

PingInfo implement ListPingHandler.

func NewPingInfo

func NewPingInfo(name string, protocol int, motd chat.Message, icon image.Image) (p *PingInfo)

NewPingInfo crate a new PingInfo, the icon can be nil. Panic if icon's size is not 64x64.

func (*PingInfo) Description

func (p *PingInfo) Description() *chat.Message

func (*PingInfo) FavIcon

func (p *PingInfo) FavIcon() string

func (*PingInfo) Name

func (p *PingInfo) Name() string

func (*PingInfo) Protocol

func (p *PingInfo) Protocol(int32) int

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

func (p *PlayerList) CheckPlayer(string, uuid.UUID, int32) (ok bool, reason chat.Message)

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 PlayerListClient interface {
	SendDisconnect(reason chat.Message)
}

type PlayerSample

type PlayerSample struct {
	Name string    `json:"name"`
	ID   uuid.UUID `json:"id"`
}

type Pos

type Pos struct{ X, Y, Z float64 }

type Rot

type Rot struct{ Yaw, Pitch float32 }

type Server

type Server struct {
	*log.Logger
	ListPingHandler
	LoginHandler
	GamePlay
}

func (*Server) AcceptConn

func (s *Server) AcceptConn(conn *net.Conn)

func (*Server) Listen

func (s *Server) Listen(addr string) error

type WritePacketError

type WritePacketError struct {
	Err error
	ID  int32
}

func (WritePacketError) Error

func (s WritePacketError) Error() string

func (WritePacketError) Unwrap

func (s WritePacketError) Unwrap() error

Directories

Path Synopsis
internal
bvh

Jump to

Keyboard shortcuts

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