socket

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2022 License: Apache-2.0 Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Listen

func Listen() error

Listen starts a TCP listener on the configured address to handle incoming connections.

func RegisterHandler

func RegisterHandler(id uint16, h PacketHandler)

RegisterHandler registers a PacketHandler for the provided packet ID. Handlers do not stack, meaning registering multiple handlers for the same id will override the previous one.

func ReportPlayerLatency

func ReportPlayerLatency(interval time.Duration)

ReportPlayerLatency sends the latency of each player to their connected server at the interval provided.

Types

type AuthRequestHandler

type AuthRequestHandler struct{}

AuthRequestHandler is responsible for handling the AuthRequest packet sent by servers.

func (*AuthRequestHandler) Handle

func (*AuthRequestHandler) Handle(p packet.Packet, c *Client) error

Handle ...

type Client

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

Client represents a client connected over the TCP socket system.

func NewClient

func NewClient(conn net.Conn) *Client

NewClient creates a new socket Client with default allocations and required data. It pre-allocates 4096 bytes to prevent allocations during runtime as much as possible.

func (*Client) Close

func (c *Client) Close() error

Close closes the client and related connections.

func (*Client) Name

func (c *Client) Name() string

Name returns the name the client authenticated with.

func (*Client) ReadPacket

func (c *Client) ReadPacket() (packet.Packet, error)

ReadPacket reads a packet from the connection and returns it. The client is expected to prefix the packet payload with 4 bytes for the length of the payload.

func (*Client) WritePacket

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

WritePacket writes a packet to the client. Since it's a TCP connection, the payload is prefixed with a length so the client can read the exact length of the packet.

type FindPlayerRequestHandler

type FindPlayerRequestHandler struct{}

FindPlayerRequestHandler is responsible for handling the FindPlayerRequest packet sent by servers.

func (*FindPlayerRequestHandler) Handle

Handle ...

type PacketHandler

type PacketHandler interface {
	// Handle is responsible for handling an incoming packet for the client.
	Handle(p packet.Packet, c *Client) error
}

PacketHandler represents a type which handles a specific packet coming from a client.

type PlayerInfoRequestHandler

type PlayerInfoRequestHandler struct{}

PlayerInfoRequestHandler is responsible for handling the PlayerInfoRequest packet sent by servers.

func (*PlayerInfoRequestHandler) Handle

Handle ...

type ServerListRequestHandler

type ServerListRequestHandler struct{}

ServerListRequestHandler is responsible for handling the ServerListRequest packet sent by servers.

func (*ServerListRequestHandler) Handle

Handle ...

type TransferRequestHandler

type TransferRequestHandler struct{}

TransferRequestHandler is responsible for handling the TransferRequest packet sent by servers.

func (*TransferRequestHandler) Handle

Handle ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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