Documentation ¶
Index ¶
- Variables
- type Conn
- func (c *Conn) Close()
- func (c *Conn) EnableEncryption(sharedSecret []byte) error
- func (c *Conn) GetRemote() *Conn
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) SendPacket(pkt packet.Packet) (err error)
- func (c *Conn) SetRemote(remote *Conn)
- func (c *Conn) SetState(state packet.State, handler Handler)
- type ConnHandlerFunc
- type Handler
- type Packet
Constants ¶
This section is empty.
Variables ¶
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 (*Conn) EnableEncryption ¶
func (*Conn) RemoteAddr ¶
type ConnHandlerFunc ¶
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.