api

package
v0.0.24 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2024 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

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

API represents a service that enables servers to communicate with the proxy over the TCP protocol. It supports operations such as transferring and kicking players, and allows for the registration of custom packets via packet.Register(). Packets can be handled using RegisterHandler().

func NewAPI

func NewAPI(registry *session.Registry, logger *slog.Logger, authentication Authentication) *API

NewAPI creates a new API service instance using the provided session.Registry.

func (*API) Accept

func (a *API) Accept() (err error)

Accept accepts an incoming client connection and handles it.

func (*API) Close

func (a *API) Close() (err error)

Close closes the listener and all connected clients.

func (*API) Listen

func (a *API) Listen(addr string) (err error)

Listen sets up a net.Listener for incoming connections based on the specified address.

func (*API) RegisterHandler added in v0.0.20

func (a *API) RegisterHandler(packet uint32, h handler)

RegisterHandler registers a handler for the specified packet.

type Authentication added in v0.0.4

type Authentication interface {
	// Authenticate checks if the provided token is valid.
	Authenticate(token string) bool
}

Authentication defines an interface for authentication methods.

type Client added in v0.0.11

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

Client represents a connection to the API service, managing packet reading and writing over an underlying net.Conn.

func NewClient added in v0.0.11

func NewClient(conn net.Conn, pool packet.Pool) *Client

NewClient creates a new Client instance using the provided net.Conn. It is used for reading and writing packets to the underlying connection.

func (*Client) Close added in v0.0.12

func (c *Client) Close() error

Close closes the underlying connection.

func (*Client) ReadPacket added in v0.0.11

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

ReadPacket reads the next available packet from the connection and decodes it.

func (*Client) WritePacket added in v0.0.11

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

WritePacket encodes and writes the provided packet to the underlying connection.

type SecretBasedAuthentication added in v0.0.5

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

SecretBasedAuthentication implements the Authentication interface using a secret token for authentication.

func NewSecretBasedAuthentication added in v0.0.5

func NewSecretBasedAuthentication(secret string) *SecretBasedAuthentication

NewSecretBasedAuthentication creates a new SecretBasedAuthentication instance with the given secret token.

func (*SecretBasedAuthentication) Authenticate added in v0.0.5

func (authentication *SecretBasedAuthentication) Authenticate(token string) bool

Authenticate ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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