Documentation
¶
Overview ¶
Package mcproto provides functions to read types and decode frames declared at https://minecraft.wiki/w/Java_Edition_protocol
Index ¶
- Constants
- func ReadBoolean(reader io.Reader) (bool, error)
- func ReadByte(reader io.Reader) (byte, error)
- func ReadByteArray(reader io.Reader, length int) ([]byte, error)
- func ReadLong(reader io.Reader) (int64, error)
- func ReadString(reader io.Reader) (string, error)
- func ReadUTF16BEString(reader io.Reader, symbolLen uint16) (string, error)
- func ReadUnsignedInt(reader io.Reader) (uint32, error)
- func ReadUnsignedShort(reader io.Reader) (uint16, error)
- func ReadUuid(reader io.Reader) (uuid.UUID, error)
- func ReadVarInt(reader io.Reader) (int, error)
- func WriteLegacySLPResponse(w io.Writer, protocol int, version string, motd string, online int, max int) error
- func WritePongPacket(w io.Writer, timestamp int64) error
- func WriteStatusFromStruct(w io.Writer, status StatusResponse) error
- func WriteStatusJSONPacket(w io.Writer, jsonString string) error
- func WriteString(w io.Writer, s string) error
- func WriteVarInt(w io.Writer, value int32) error
- type ByteReader
- type Frame
- type Handshake
- type LegacyServerListPing
- type LoginStart
- type Packet
- type PingPayload
- type ProtocolVersion
- type State
- type StatusResponse
Constants ¶
const ( PacketIdHandshake = 0x00 PacketIdLogin = 0x00 // during StateLogin PacketIdLegacyServerListPing = 0xFE PacketIdStatusRequest = 0x00 PacketIdPingRequest = 0x01 )
const ( PacketIdStatusResponse = 0x00 PackedIdPongResponse = 0x01 )
const MaxFrameLength = 2097151
MaxFrameLength is declared at https://minecraft.wiki/w/Java_Edition_protocol#Packet_format to be 2^21 - 1
const (
PacketLengthFieldBytes = 1
)
Variables ¶
This section is empty.
Functions ¶
func WriteLegacySLPResponse ¶ added in v1.38.0
func WriteLegacySLPResponse(w io.Writer, protocol int, version string, motd string, online int, max int) error
WriteLegacySLPResponse writes the 1.6-compatible legacy response packet (0xFF) Format: FF, [length short], UTF16BE string beginning with "\u00A7\u0031\u0000" then null-delimited fields fields: protocol, version, motd, online, max
func WritePongPacket ¶ added in v1.38.0
WritePongPacket writes Pong (packet 0x01) with the same payload
func WriteStatusFromStruct ¶ added in v1.38.0
func WriteStatusFromStruct(w io.Writer, status StatusResponse) error
WriteStatusFromStruct writes a Status Response from a struct
func WriteStatusJSONPacket ¶ added in v1.38.0
WriteStatusJSONPacket writes a Status Response (packet 0x00) with the provided JSON string
func WriteString ¶ added in v1.38.0
WriteString writes a Minecraft length-prefixed string
Types ¶
type ByteReader ¶
type Handshake ¶
type Handshake struct {
ProtocolVersion ProtocolVersion
ServerAddress string
ServerPort uint16
NextState State
}
func DecodeHandshake ¶
DecodeHandshake takes the Packet.Data bytes and decodes a Handshake message from it
type LegacyServerListPing ¶
type LoginStart ¶
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 ReadPacket ¶
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.
type PingPayload ¶ added in v1.38.0
type PingPayload struct {
Timestamp int64
}
PingPayload represents the status ping payload (packet 0x01)
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 StatusResponse ¶ added in v1.38.0
type StatusResponse struct {
Version struct {
Name string `json:"name"`
Protocol int `json:"protocol"`
} `json:"version"`
Players struct {
Max int `json:"max"`
Online int `json:"online"`
Sample []struct {
Name string `json:"name"`
ID string `json:"id"`
} `json:"sample,omitempty"`
} `json:"players"`
Description map[string]interface{} `json:"description"`
Favicon string `json:"favicon,omitempty"`
EnforcesSecureChat *bool `json:"enforcesSecureChat,omitempty"`
}
StatusResponse is a minimal structure for the status JSON