socket

package
v1.0.16 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: Apache-2.0 Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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.

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, srv Server, c *Client) error

Handle ...

func (*AuthRequestHandler) RequiresAuth added in v0.2.0

func (*AuthRequestHandler) RequiresAuth() bool

RequiresAuth ...

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, log internal.Logger, readerLimits bool) *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) Authenticate added in v0.2.0

func (c *Client) Authenticate(name string)

Authenticate marks the client as authenticated and gives it the provided name.

func (*Client) Authenticated added in v0.2.0

func (c *Client) Authenticated() bool

Authenticated returns if the client has been authenticated or not.

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() (pk packet.Packet, err 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 DefaultServer added in v0.2.0

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

DefaultServer represents a basic TCP socket server implementation. It allows external connections to connect and authenticate to be able to communicate with the proxy.

func NewDefaultServer added in v0.2.0

func NewDefaultServer(addr, secret string, sessionStore *session.Store, serverRegistry *server.Registry, log internal.Logger, readerLimits bool) *DefaultServer

NewDefaultServer creates a new default server to be used for accepting socket connections.

func (*DefaultServer) Authenticate added in v0.2.0

func (s *DefaultServer) Authenticate(c *Client, name string)

Authenticate ...

func (*DefaultServer) Client added in v0.2.0

func (s *DefaultServer) Client(name string) (*Client, bool)

Client ...

func (*DefaultServer) Clients added in v0.2.0

func (s *DefaultServer) Clients() (clients []*Client)

Clients ...

func (*DefaultServer) Listen added in v0.2.0

func (s *DefaultServer) Listen() error

Listen ...

func (*DefaultServer) Logger added in v0.2.0

func (s *DefaultServer) Logger() internal.Logger

Logger ...

func (*DefaultServer) ReportPlayerLatency added in v0.2.0

func (s *DefaultServer) ReportPlayerLatency(interval time.Duration)

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

func (*DefaultServer) Secret added in v0.2.0

func (s *DefaultServer) Secret() string

Secret ...

func (*DefaultServer) ServerRegistry added in v0.2.0

func (s *DefaultServer) ServerRegistry() *server.Registry

ServerRegistry ...

func (*DefaultServer) SessionStore added in v0.2.0

func (s *DefaultServer) SessionStore() *session.Store

SessionStore ...

type FindPlayerRequestHandler

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

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

func (*FindPlayerRequestHandler) Handle

Handle ...

func (*FindPlayerRequestHandler) RequiresAuth added in v0.2.0

func (*FindPlayerRequestHandler) RequiresAuth() bool

RequiresAuth ...

type PacketHandler

type PacketHandler interface {
	// Handle is responsible for handling an incoming packet for the client.
	Handle(p packet.Packet, src Server, c *Client) error
	// RequiresAuth returns if the client must be authenticated in order for the handler to be triggered.
	RequiresAuth() bool
}

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

type PlayerInfoRequestHandler

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

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

func (*PlayerInfoRequestHandler) Handle

Handle ...

func (*PlayerInfoRequestHandler) RequiresAuth added in v0.2.0

func (*PlayerInfoRequestHandler) RequiresAuth() bool

RequiresAuth ...

type RegisterServerHandler added in v0.2.0

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

RegisterServerHandler is responsible for handling the RegisterServer packet sent by servers.

func (*RegisterServerHandler) Handle added in v0.2.0

func (*RegisterServerHandler) Handle(p packet.Packet, srv Server, c *Client) error

Handle ...

func (*RegisterServerHandler) RequiresAuth added in v0.2.0

func (*RegisterServerHandler) RequiresAuth() bool

RequiresAuth ...

type Server added in v0.2.0

type Server interface {
	// Listen starts listening for connections on an address.
	Listen() error

	// Logger returns the logger attached to the socket server.
	Logger() internal.Logger

	// Secret returns the secret required for connections to authenticate.
	Secret() string

	// Clients returns all the clients that are connected to the socket server.
	Clients() []*Client
	// Client attempts to return a client from the provided name, case-sensitive.
	Client(name string) (*Client, bool)
	// Authenticate marks the client as authenticated with the provided name. It is safe to assume that the provided
	// name is not in use, unless called by places other than the socket server.
	Authenticate(c *Client, name string)

	// SessionStore returns the store used to hold the open sessions on the proxy.
	SessionStore() *session.Store
	// ServerRegistry returns the registry used to store available servers on the proxy.
	ServerRegistry() *server.Registry
}

type ServerListRequestHandler

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

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

func (*ServerListRequestHandler) Handle

Handle ...

func (*ServerListRequestHandler) RequiresAuth added in v0.2.0

func (*ServerListRequestHandler) RequiresAuth() bool

RequiresAuth ...

type TransferRequestHandler

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

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

func (*TransferRequestHandler) Handle

func (*TransferRequestHandler) Handle(p packet.Packet, srv Server, c *Client) error

Handle ...

func (*TransferRequestHandler) RequiresAuth added in v0.2.0

func (*TransferRequestHandler) RequiresAuth() bool

RequiresAuth ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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