server

package
v0.0.38 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2025 License: MIT Imports: 18 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) Conn added in v0.0.25

func (c *Conn) Conn() io.ReadWriteCloser

Conn returns the underlying connection. Direct access to the underlying connection through this method is strongly discouraged due to the potential for unpredictable behavior. Use this method only when absolutely necessary.

func (*Conn) Connect added in v0.0.13

func (c *Conn) Connect() error

Connect initiates the connection sequence with a default timeout of 1 minute.

func (*Conn) ConnectContext added in v0.0.23

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

ConnectContext initiates the connection sequence using the provided context for cancellation.

func (*Conn) ConnectTimeout added in v0.0.23

func (c *Conn) ConnectTimeout(duration time.Duration) error

ConnectTimeout initiates the connection sequence with the specified timeout duration.

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

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

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

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