proto

package
v0.39.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2024 License: Apache-2.0 Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
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.
const (
	ClientBound Direction = iota // A packet is bound to a client.
	ServerBound                  // A packet is bound to a server.
)

Available packet bound directions.

func (Direction) String

func (d Direction) String() string

String implements fmt.Stringer.

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.

func (PacketID) String

func (id PacketID) String() string

String implements fmt.Stringer.

type PacketType

type PacketType reflect.Type

PacketType is the non-pointer reflect.Type of a packet. Use TypeOf helper function to for convenience.

func TypeOf

func TypeOf(p Packet) PacketType

TypeOf returns a non-pointer type of p.

type PacketWriter added in v0.19.1

type PacketWriter interface {
	WritePacket(Packet) error
}

PacketWriter can write packets.

type Protocol

type Protocol int

Protocol is a Minecraft edition agnostic protocol version id specified by Mojang.

func (Protocol) Greater

func (p Protocol) Greater(then *Version) bool

Greater is true when this Protocol is greater then another Version's Protocol.

func (Protocol) GreaterEqual

func (p Protocol) GreaterEqual(then *Version) bool

GreaterEqual is true when this Protocol is greater or equal then another Version's Protocol.

func (Protocol) Lower

func (p Protocol) Lower(then *Version) bool

Lower is true when this Protocol is lower then another Version's Protocol.

func (Protocol) LowerEqual

func (p Protocol) LowerEqual(then *Version) bool

LowerEqual is true when this Protocol is lower or equal then another Version's Protocol.

func (Protocol) String

func (p Protocol) String() string

String implements fmt.Stringer.

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

func (v *Version) FirstName() string

FirstName returns the user-friendly name of the version this protocol was introduced in.

func (*Version) LastName added in v0.12.0

func (v *Version) LastName() string

LastName returns the user-friendly name of the last version of this protocol.

func (Version) String

func (v Version) String() string

String returns the user-friendly name of this protocol version. If this version has multiple names it returns {first}-{last} version.

Jump to

Keyboard shortcuts

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