Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrDecoderLeftBytes = errors.New("decoder did not read all bytes of packet")
ErrDecoderLeftBytes indicates a packet was known and successfully decoded by it's registered decoder, but the decoder has not read all the packet's bytes.
This may happen in cases where
- the decoder has a bug
- the decoder does not handle the case for the new protocol version of the packet changed by Mojang/Minecraft
- someone (server/client) has sent valid bytes in the beginning of the packet's data that the packet's decoder could successfully decode, but then the data contains even more bytes (the left bytes)
Functions ¶
This section is empty.
Types ¶
type Direction ¶
type Direction uint8
Direction is the direction a packet is bound to.
- Receiving a packet from a client is ServerBound.
- Receiving a packet from a server is ClientBound.
- Sending a packet to a client is ClientBound.
- Sending a packet to a server is ServerBound.
type Packet ¶
type Packet interface { // Encode encodes the packet data into the writer. Encode(c *PacketContext, wr io.Writer) error // Decode expected data from a reader into the packet. Decode(c *PacketContext, rd io.Reader) (err error) }
Packet represents a packet type in a Minecraft edition.
It is the data layer of a packet in a and shall support multiple protocols up- and/or downwards by testing the Protocol contained in the passed PacketContext.
The passed PacketContext is read-only and must not be modified.
type PacketContext ¶
type PacketContext struct { Direction Direction // The direction the packet is bound to. Protocol Protocol // The protocol version of the packet. PacketID PacketID // The ID of the packet, is always set. // Is the decoded type that is found by PacketID in the connections // current state.ProtocolRegistry. Otherwise, nil, the PacketID is unknown // and KnownPacket is false. Packet Packet // The unencrypted and uncompressed form of packet id + data. // It contains the actual received payload (maybe longer than what the Packet's Decode read). // This can be used to skip encoding Packet. Payload []byte // Empty when encoding. }
PacketContext carries context information for a received packet or packet that is about to be sent.
func (*PacketContext) KnownPacket ¶
func (c *PacketContext) KnownPacket() bool
KnownPacket indicated whether the PacketID is known in the connection's current state.ProtocolRegistry. If false field Packet is nil, which in most cases indicates a forwarded packet that is just going to be proxy-ed through to client <--> backend connection.
func (*PacketContext) String ¶
func (c *PacketContext) String() string
String implements fmt.Stringer.
type PacketDecoder ¶
type PacketDecoder interface {
Decode() (*PacketContext, error)
}
PacketDecoder decodes packets from an underlying source and returns them with additional context.
type PacketEncoder ¶
type PacketEncoder interface {
Encode(*PacketContext) error
}
PacketEncoder encodes packets to an underlying destination using the additional context.
type PacketID ¶
type PacketID int
PacketID identifies a packet in a protocol version. PacketIDs vary by Protocol version and different packet types exist in each Minecraft edition.
type PacketType ¶
PacketType is the non-pointer reflect.Type of a packet. Use TypeOf helper function to for convenience.
type PacketWriter ¶ added in v0.19.1
PacketWriter can write packets.
type Protocol ¶
type Protocol int
Protocol is a Minecraft edition agnostic protocol version id specified by Mojang.
func (Protocol) Greater ¶
Greater is true when this Protocol is greater then another Version's Protocol.
func (Protocol) GreaterEqual ¶
GreaterEqual is true when this Protocol is greater or equal then another Version's Protocol.
func (Protocol) LowerEqual ¶
LowerEqual is true when this Protocol is lower or equal then another Version's Protocol.
type Version ¶
type Version struct { Protocol // The protocol number of the version. Names []string // The names in this protocol version (at least one). }
Version is a named protocol version.
func (*Version) FirstName ¶ added in v0.12.0
FirstName returns the user-friendly name of the version this protocol was introduced in.