Documentation
¶
Overview ¶
Package packets contains the necessary magic to create, parse, serialize and register Minecraft packets.
Index ¶
- Constants
- Variables
- func PutUvarint(buf []byte, x uint64) int
- func PutVarint(buf []byte, x int64) int
- func ReadBool(r io.Reader) (bool, error)
- func ReadString(r io.Reader) (string, error)
- func ReadUvarint(r io.Reader) (uint64, error)
- func ReadVarint(r io.Reader) (int64, error)
- func Register(state State, dir PacketDirection, id byte, f PacketFunc)
- func Uvarint(buf []byte) (uint64, int)
- func Varint(buf []byte) (int64, int)
- func WriteBool(w io.Writer, b bool) error
- func WriteString(w io.Writer, s string) error
- func WriteVarint(w io.Writer, v VarInt) error
- type Angle
- type Chat
- type Packet
- type PacketDirection
- type PacketFunc
- type Parser
- type Position
- type State
- type UUID
- type VarInt
- type VarLong
Constants ¶
const ( NumStates int = 4 NumDirections = 3 )
Variables ¶
var ( ErrNegativeLength = errors.New("kyubu: packet has negative length") ErrUnknownPacket = errors.New("kyubu: packet has unknown id") ErrLostSync = errors.New("kyubu: lost sync on packets") ErrNotCompressed = errors.New("kyubu: packet not compressed correctly") )
var Endianness = binary.BigEndian
var Packets [NumStates][NumDirections]map[byte]PacketFunc
Packets is a multidimensional array/map used to store packet factories. [4] = how many states there are [3] = how many directions there are [b] = packet ID byte
Functions ¶
func PutUvarint ¶
PutUvarint encodes a uint64 into buf and returns the number of bytes written. If the buffer is too small, PutUvarint will panic.
func PutVarint ¶
PutVarint encodes an int64 into buf and returns the number of bytes written. If the buffer is too small, PutVarint will panic.
func ReadUvarint ¶
ReadUvarint reads an encoded unsigned integer from r and returns it as a uint64.
func ReadVarint ¶
ReadVarint reads an encoded signed integer from r and returns it as an int64.
func Register ¶
func Register(state State, dir PacketDirection, id byte, f PacketFunc)
XXX: Catch panics in case of out of bounds? Is that even possible?
func Uvarint ¶
Uvarint decodes a uint64 from buf and returns that value and the number of bytes read (> 0). If an error occurred, the value is 0 and the number of bytes n is <= 0 meaning:
n == 0: buf too small n < 0: value larger than 64 bits (overflow) and -n is the number of bytes read
func Varint ¶
Varint decodes an int64 from buf and returns that value and the number of bytes read (> 0). If an error occurred, the value is 0 and the number of bytes n is <= 0 with the following meaning:
n == 0: buf too small n < 0: value larger than 64 bits (overflow) and -n is the number of bytes read
Types ¶
type Angle ¶
type Angle uint8
(1) Rotation angle in steps of 1/256 of a full turn Unsigned to get 0-255, rather than -128 to 127
type Chat ¶
type Chat format.AnyComponent
type PacketDirection ¶
type PacketDirection int
PacketDirection lets us define whether packets are purely C->S or S->C. This will change what the parser reads, depending on its direction.
const ( ServerBound PacketDirection = iota ClientBound // Anomalous shouldn't come up usually. If it does, something is broken, // and you'll probably want to panic() out. Anomalous )
ServerBound and ClientBound let us designate a parser's direction. This defines what kind of packets it'll parse/serialize.
func (*PacketDirection) Flip ¶
func (p *PacketDirection) Flip() PacketDirection
type PacketFunc ¶
type PacketFunc func() Packet
type Parser ¶
type Parser struct { State State Direction PacketDirection // contains filtered or unexported fields }
func (*Parser) EnableEncryption ¶
func (*Parser) SetCompression ¶
type Position ¶
type Position uint64
(8) x (-33554432 to 33554431), y (-2048 to 2047), z (-33554432 to 33554431) x as a 26-bit integer, followed by y as a 12-bit integer, followed by z as a 26-bit integer Code lifted from thinkofdeath/steven:protocol/handshaking.go