Documentation
¶
Index ¶
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) CloseWithError(err error)
- func (c *Conn) Context() context.Context
- func (c *Conn) DoConnect() error
- func (c *Conn) DoSpawn() error
- func (c *Conn) GameData() minecraft.GameData
- func (c *Conn) OnConnect(fn func(error))
- func (c *Conn) ReadPacket() (any, error)
- func (c *Conn) ShieldID() int32
- func (c *Conn) WaitConnect(ctx context.Context) error
- func (c *Conn) Write(p []byte) error
- func (c *Conn) WritePacket(pk packet.Packet) error
- type Discovery
- type StaticDiscovery
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) CloseWithError ¶ added in v0.0.37
CloseWithError closes the underlying connection.
func (*Conn) Context ¶ added in v0.0.37
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
DoConnect sends a ConnectionRequest packet to initiate the connection sequence.
func (*Conn) DoSpawn ¶ added in v0.0.39
DoSpawn sends a SetLocalPlayerAsInitialised packet to spawn the player in the server and signals that packets can now be read.
func (*Conn) GameData ¶
GameData returns the game data set for the connection by the StartGame packet.
func (*Conn) OnConnect ¶ added in v0.0.40
OnConnect invokes the provided function once the connection sequence is complete or has failed.
func (*Conn) ReadPacket ¶
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
ShieldID returns the shield id set for the connection by the StartGame packet.
func (*Conn) WaitConnect ¶ added in v0.0.40
WaitConnect blocks until the connection sequence has completed or the provided context is canceled.
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 ...