proto

package
v0.0.0-...-0659192 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Forward       = errors.New("forward")
	UnknownPacket = errors.New("unknown packet")
)

Functions

This section is empty.

Types

type Conn

type Conn struct {

	// Closer is called when the connection is closed.
	// Kite guarantees that it will be called, so it may be used for necessary cleanup.
	Closer func()
	// contains filtered or unexported fields
}

A Conn is a connection that can send and process packets. Typically, a Conn exists for both the client<>proxy and proxy<>server connections. When connecting to a new server, a new Conn will be created before the old one is closed.

A Handler is used to process packets received by the Conn.

A Conn should be informed of the remote connection to allow packet forwarding.

func CreateServerConn

func CreateServerConn(ctx context.Context, address string, port uint16, profile *packet.GameProfile, secret string, handleFunc func(*Conn, context.CancelCauseFunc, *packet.GameProfile, string) Handler) (context.Context, *Conn, error)

CreateServerConn connects to a remote server and returns a context which completes either when an error occurs or the connection is ready to enter the config phase. The returned context has a cause (see context.Cause). If the cause is not context.Canceled, the connection has been closed.

func NewConn

func NewConn(direction packet.Direction, conn net.Conn) (*Conn, func())

func (*Conn) Close

func (c *Conn) Close()

func (*Conn) EnableEncryption

func (c *Conn) EnableEncryption(sharedSecret []byte) error

func (*Conn) GetRemote

func (c *Conn) GetRemote() *Conn

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

func (*Conn) SendPacket

func (c *Conn) SendPacket(pkt packet.Packet) (err error)

func (*Conn) SetRemote

func (c *Conn) SetRemote(remote *Conn)

func (*Conn) SetState

func (c *Conn) SetState(state packet.State, handler Handler)

type ConnHandlerFunc

type ConnHandlerFunc func(*Conn) Handler

type Handler

type Handler interface {
	// HandlePacket is called for each packet received from the protocol side.
	//
	// The handler should return nil if the packet was handled successfully. It may also return
	// Forward to indicate that the packet should be forwarded as is to the other side of the connection.
	HandlePacket(pp Packet) error
}

Handler is a basic interface for something which can handle a protocol state. There is always a single handler set for each player at a given time.

A handler is specific to one side of the protocol traffic, for example there will be separate a "play" handler for both client packets and server packets.

type Packet

type Packet struct {
	Id int32
	// contains filtered or unexported fields
}

func (Packet) Consume

func (p Packet) Consume()

Consume marks the entire content of the buffer as read.

This is pretty much to require explicit consumption of an unused packet.

func (Packet) Read

func (p Packet) Read(t packet.Packet) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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