packet

package
v0.0.0-...-10637f8 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ResponseSuccess = iota
	ResponseUnauthorized
	ResponseFail
)
View Source
const (
	IDConnectionRequest = iota
	IDConnectionResponse
	IDKick
	IDTransfer
)

Variables

This section is empty.

Functions

func ReadString

func ReadString(buf *bytes.Buffer) string

ReadString reads a string from buf, where the string is prefixed with its length encoded as an uint32 in little-endian order.

func Register

func Register(id uint32, factory func() Packet)

Register registers a packet factory function for a given ID.

func WriteString

func WriteString(buf *bytes.Buffer, s string)

WriteString writes the string s to buf, prefixing it with its length encoded as an uint32 in little-endian order.

Types

type ConnectionRequest

type ConnectionRequest struct {
	// Token is the client's token which is used for authorization.
	Token string
}

ConnectionRequest is sent by clients to connect and authenticate with the service using a token. The service responds to this request with a ConnectionResponse.

func (*ConnectionRequest) Decode

func (pk *ConnectionRequest) Decode(buf *bytes.Buffer)

Decode ...

func (*ConnectionRequest) Encode

func (pk *ConnectionRequest) Encode(buf *bytes.Buffer)

Encode ...

func (*ConnectionRequest) ID

func (pk *ConnectionRequest) ID() uint32

ID ...

type ConnectionResponse

type ConnectionResponse struct {
	// Response indicates the status of the connection request.
	Response uint8
}

ConnectionResponse represents the response sent by the API service in reply to a ConnectionRequest.

func (*ConnectionResponse) Decode

func (pk *ConnectionResponse) Decode(buf *bytes.Buffer)

Decode ...

func (*ConnectionResponse) Encode

func (pk *ConnectionResponse) Encode(buf *bytes.Buffer)

Encode ...

func (*ConnectionResponse) ID

func (pk *ConnectionResponse) ID() uint32

ID ...

type Kick

type Kick struct {
	// Reason is the reason displayed in the disconnection screen for the kick.
	Reason string
	// Username is the username of the player to be kicked.
	Username string
}

Kick is sent by the client to initiate the removal of a specific player from the proxy.

func (*Kick) Decode

func (pk *Kick) Decode(buf *bytes.Buffer)

Decode ...

func (*Kick) Encode

func (pk *Kick) Encode(buf *bytes.Buffer)

Encode ...

func (*Kick) ID

func (pk *Kick) ID() uint32

ID ...

type Packet

type Packet interface {
	// ID returns the unique identifier of the packet.
	ID() uint32
	// Encode will encode the packet into binary form and write it to buf.
	Encode(buf *bytes.Buffer)
	// Decode will decode binary data from buf into the packet.
	Decode(buf *bytes.Buffer)
}

Packet represents a protocol packet that can be sent over an API connection. It defines methods for identifying the packet, encoding itself to binary, and decoding itself from binary.

type Pool

type Pool map[uint32]func() Packet

Pool is a map holding packet factory functions indexed by their ID.

func NewPool

func NewPool() Pool

NewPool creates a new Pool populated with registered packet factories.

type Transfer

type Transfer struct {
	// Addr is the address of the new server.
	Addr string
	// Username is the username of the player to be transferred.
	Username string
}

Transfer is sent by the client to initiate the transfer of a specific player to another server.

func (*Transfer) Decode

func (pk *Transfer) Decode(buf *bytes.Buffer)

Decode ...

func (*Transfer) Encode

func (pk *Transfer) Encode(buf *bytes.Buffer)

Encode ...

func (*Transfer) ID

func (pk *Transfer) ID() uint32

ID ...

Jump to

Keyboard shortcuts

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