Expand description
Minecraft Java Edition framing for the Server List Ping and the front of login: VarInt
length-prefixed packets, the handshake, status JSON, ping/pong, Login Start, the login
Disconnect, and the pre-1.7 legacy ping (0xFE) with its 0xFF kick reply.
Shared by the server and the client. Every length the peer announces is checked against a bound before anything is allocated for it.
Structs§
- Handshake
- Legacy
Ping - What a legacy (
0xFE) ping carried. - Reader
- A cursor over one packet’s body.
Constants§
- DEFAULT_
PROTOCOL - DEFAULT_
VERSION_ NAME - The version reported when the handler names none: 1.21.1.
- IO_
TIMEOUT - Deadline for each read and write, as the vanilla server’s read timeout.
- LEGACY_
PING_ PROTOCOL - Protocol a 1.6 legacy ping carries.
- LEGACY_
TAIL_ WAIT - How long the legacy ping’s optional tail (
01, thenFA+ MC|PingHost) is waited for. - MAX_
ADDRESS_ CHARS - Handshake server address, in characters.
- MAX_
CLIENTBOUND_ PACKET - Largest packet the client accepts: a status response is one String of at most 32767 chars.
- MAX_
JSON_ CHARS - A Java
Stringfield holds at most 32767 UTF-16 units; the status JSON and a disconnect reason are both bounded by it. - MAX_
LEGACY_ PAYLOAD - Bytes of a 1.6 MC|PingHost payload accepted.
- MAX_
SAMPLE - Players listed in a status sample.
- MAX_
SERVERBOUND_ PACKET - Largest packet a client may send the server (handshake, Login Start, ping are all tiny).
- MAX_
USERNAME_ CHARS - Login Start player name, in characters.
- STATE_
LOGIN - STATE_
STATUS - STATE_
TRANSFER
Functions§
- decode_
legacy_ reply - Decode a
0xFFkick reply (after the0xFFand the u16 length) into status fields. - disconnect_
json - A login Disconnect reason as the JSON text component the client renders.
- encode_
handshake - encode_
legacy_ ping - The 1.6 client’s legacy ping:
FE 01 FA+ MC|PingHost naminghost:port. - encode_
legacy_ reply - The
0xFFkick packet answering a legacy ping. 1.4+ clients get§1\0protocol\0version\0motd\0online\0max; a bare0xFEgetsmotd§online§max, where§is the separator and is therefore removed from the MOTD. - encode_
login_ start - Login Start as a client of
protocolsends it. - format_
uuid - frame
- A complete packet (length prefix included) from an id and body.
- get_
varint - Decode a VarInt from the front of
buf: (value, bytes used). - parse_
handshake - parse_
login_ start - Login Start: the name, and the UUID when the version’s layout carries one. The layout changed four times; the trailing bytes are read by shape rather than by version number.
- parse_
uuid - plain_
text - Flatten a chat component (a string, an object with text/translate/extra, or an array) to plain text. Nesting beyond 32 levels is cut off rather than followed.
- put_
string - put_
varint - read_
legacy_ ping - Read the rest of a legacy ping after its
0xFE: the optional0x01, then the optional 1.60xFAMC|PingHost plugin message. Each tail is waited for briefly, as the vanilla server does, because older clients send nothing more. - read_
packet - Read one uncompressed packet’s id and body.
Noneon a clean EOF between packets. - read_
raw - Read one packet’s bytes after its length prefix; the announced length is checked against
maxbefore any of it is read.Noneon a clean EOF between packets. - split_
id - Split an uncompressed packet into its id and body.
- status_
json - The status JSON for a
minecraft_statusaction;client_protocolis unused unless the handler asks to echo it (protocol: "echo").