server

package
v0.0.43 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2025 License: MIT Imports: 14 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

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

Conn represents a connection to a server, managing packet reading and writing over an underlying io.ReadWriteCloser.

func NewConn

func NewConn(conn io.ReadWriteCloser, client *minecraft.Conn, logger *slog.Logger, syncProtocol bool, cache []byte) *Conn

NewConn creates a new Conn instance using the provided io.ReadWriteCloser. It is used for reading and writing packets to the underlying connection.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the underlying connection.

func (*Conn) CloseWithError added in v0.0.37

func (c *Conn) CloseWithError(err error)

CloseWithError closes the underlying connection.

func (*Conn) Context added in v0.0.37

func (c *Conn) Context() context.Context

Context returns the connection's context. The context is canceled when the connection is closed, allowing for cancellation of operations that are tied to the lifecycle of the connection.

func (*Conn) DoConnect added in v0.0.40

func (c *Conn) DoConnect() error

DoConnect sends a ConnectionRequest packet to initiate the connection sequence.

func (*Conn) DoSpawn added in v0.0.39

func (c *Conn) DoSpawn() error

DoSpawn sends a SetLocalPlayerAsInitialised packet to spawn the player in the server and signals that packets can now be read.

func (*Conn) GameData

func (c *Conn) GameData() minecraft.GameData

GameData returns the game data set for the connection by the StartGame packet.

func (*Conn) OnConnect added in v0.0.40

func (c *Conn) OnConnect(fn func(error))

OnConnect invokes the provided function once the connection sequence is complete or has failed.

func (*Conn) ReadPacket

func (c *Conn) ReadPacket() (any, error)

ReadPacket reads the next available packet from the connection. If there are deferred packets, it will return one of those first. This method should not be called concurrently from multiple goroutines.

func (*Conn) ShieldID added in v0.0.26

func (c *Conn) ShieldID() int32

ShieldID returns the shield id set for the connection by the StartGame packet.

func (*Conn) WaitConnect added in v0.0.40

func (c *Conn) WaitConnect(ctx context.Context) error

WaitConnect blocks until the connection sequence has completed or the provided context is canceled.

func (*Conn) Write added in v0.0.26

func (c *Conn) Write(p []byte) error

Write writes provided byte slice to the underlying connection.

func (*Conn) WritePacket

func (c *Conn) WritePacket(pk packet.Packet) error

WritePacket encodes and writes the provided packet to the underlying connection.

type Discovery

type Discovery interface {
	// Discover determines the primary server.
	Discover(conn *minecraft.Conn) (string, error)
	// DiscoverFallback determines the fallback server.
	DiscoverFallback(conn *minecraft.Conn) (string, error)
}

Discovery defines an interface for discovering servers based on a player's connection.

type StaticDiscovery

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

StaticDiscovery implements the Discovery interface with static server addresses.

func NewStaticDiscovery

func NewStaticDiscovery(server string, fallbackServer string) *StaticDiscovery

NewStaticDiscovery creates a new StaticDiscovery with the given server addresses.

func (*StaticDiscovery) Discover

func (s *StaticDiscovery) Discover(_ *minecraft.Conn) (string, error)

Discover ...

func (*StaticDiscovery) DiscoverFallback added in v0.0.23

func (s *StaticDiscovery) DiscoverFallback(_ *minecraft.Conn) (string, error)

DiscoverFallback ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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