mcproto

package
v1.36.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package mcproto provides functions to read types and decode frames declared at https://minecraft.wiki/w/Java_Edition_protocol

Index

Constants

View Source
const (
	PacketIdHandshake            = 0x00
	PacketIdLogin                = 0x00 // during StateLogin
	PacketIdLegacyServerListPing = 0xFE
)
View Source
const MaxFrameLength = 2097151

MaxFrameLength is declared at https://minecraft.wiki/w/Java_Edition_protocol#Packet_format to be 2^21 - 1

View Source
const (
	PacketLengthFieldBytes = 1
)

Variables

This section is empty.

Functions

func ReadBoolean

func ReadBoolean(reader io.Reader) (bool, error)

func ReadByte

func ReadByte(reader io.Reader) (byte, error)

func ReadByteArray

func ReadByteArray(reader io.Reader, length int) ([]byte, error)

func ReadLong

func ReadLong(reader io.Reader) (int64, error)

func ReadString

func ReadString(reader io.Reader) (string, error)

func ReadUTF16BEString

func ReadUTF16BEString(reader io.Reader, symbolLen uint16) (string, error)

func ReadUnsignedInt

func ReadUnsignedInt(reader io.Reader) (uint32, error)

func ReadUnsignedShort

func ReadUnsignedShort(reader io.Reader) (uint16, error)

func ReadUuid

func ReadUuid(reader io.Reader) (uuid.UUID, error)

func ReadVarInt

func ReadVarInt(reader io.Reader) (int, error)

Types

type ByteReader

type ByteReader interface {
	ReadByte() (byte, error)
}

type Frame

type Frame struct {
	Length  int
	Payload []byte
}

func ReadFrame

func ReadFrame(reader io.Reader, addr net.Addr) (*Frame, error)

func (*Frame) String

func (f *Frame) String() string

type Handshake

type Handshake struct {
	ProtocolVersion ProtocolVersion
	ServerAddress   string
	ServerPort      uint16
	NextState       State
}

func DecodeHandshake

func DecodeHandshake(data interface{}) (*Handshake, error)

DecodeHandshake takes the Packet.Data bytes and decodes a Handshake message from it

type LegacyServerListPing

type LegacyServerListPing struct {
	ProtocolVersion int
	ServerAddress   string
	ServerPort      uint16
}

type LoginStart

type LoginStart struct {
	Name       string
	PlayerUuid uuid.UUID
}

func DecodeLoginStart

func DecodeLoginStart(protocolVersion ProtocolVersion, data interface{}) (*LoginStart, error)

DecodeLoginStart takes the Packet.Data bytes and decodes a LoginStart message from it

func NewLoginStart

func NewLoginStart() *LoginStart

type Packet

type Packet struct {
	Length   int
	PacketID int
	// Data is either a byte slice of raw content or a decoded message
	Data interface{}
}

func ReadLegacyServerListPing

func ReadLegacyServerListPing(reader *bufio.Reader, addr net.Addr) (*Packet, error)

func ReadPacket

func ReadPacket(reader *bufio.Reader, addr net.Addr, state State) (*Packet, error)

ReadPacket reads a packet from the given reader based on the provided connection state. Returns a pointer to the Packet and an error if reading fails. Handles legacy server list ping packet when in the handshaking state. The provided addr is used for logging purposes.

func (*Packet) String

func (p *Packet) String() string

type ProtocolVersion

type ProtocolVersion int
const (
	// ProtocolVersion1_18_2 is the protocol version for Minecraft 1.18.2
	// Docs: https://minecraft.wiki/w/Java_Edition_protocol/Packets?oldid=2772791
	ProtocolVersion1_18_2 ProtocolVersion = 758
	// ProtocolVersion1_19 is the protocol version for Minecraft 1.19
	// Docs: https://minecraft.wiki/w/Java_Edition_protocol/Packets?oldid=2772904
	ProtocolVersion1_19 ProtocolVersion = 759
	// ProtocolVersion1_19_2 is the protocol version for Minecraft 1.19.2
	// Docs: https://minecraft.wiki/w/Java_Edition_protocol/Packets?oldid=2772944
	ProtocolVersion1_19_2 ProtocolVersion = 760
	// ProtocolVersion1_19_2 is the protocol version for Minecraft 1.19.3
	ProtocolVersion1_19_3 ProtocolVersion = 761
	// ProtocolVersion1_20_2 is the protocol version for Minecraft 1.20.2
	ProtocolVersion1_20_2 ProtocolVersion = 764
	// ProtocolVersion1_21_5 is the protocol version for Minecraft 1.21.5
	ProtocolVersion1_21_5 ProtocolVersion = 770
)

Source: https://minecraft.wiki/w/Minecraft_Wiki:Projects/wiki.vg_merge/Protocol_History

type State

type State int
const (
	StateHandshaking State = 0
	StateStatus      State = 1
	StateLogin       State = 2
)

Handshaking -> Status Handshaking -> Login -> ...

Jump to

Keyboard shortcuts

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