sculk.network
Nightly Stable docs
sculkwormnightly · 39a95aaView in Stable docs

Minecraft protocol

sculkworm parses only the first packet of a Minecraft Java Edition TCP connection, the serverbound Handshake packet (0x00). Once the packet is complete and a route matches, sculkworm writes the exact buffered client bytes (including any trailing bytes that arrived in the same TCP read) to the backend and splices the two sockets for the lifetime of the connection.

Because sculkworm never parses packets after the Handshake, it works across protocol versions and does not interfere with online-mode encryption, compression, Configuration, or Play packets.

The closed-mode tunnel between the relay, the agent, and connect uses its own framing, specified in Closed routes. On the public Minecraft port, closed routes are answered directly by the relay (src/closed.rs) as described below and in What a vanilla Minecraft client sees.

Closed-route answers on the Minecraft port#

When the parsed route key matches a dynamic closed route (and no static route with the same hostname takes precedence), Relay::handle_connection never opens a backend socket. Instead it logs level=info event=closed_route_answer host=<host> intent=<intent> protocol=<n> peer=<addr> and answers directly from src/closed.rs:

  • Status (1). The relay reads one Status Request (0x00, empty payload), replies with a Status Response (0x00) whose version.name is "sculkworm", version.protocol echoes the client's Handshake protocol number, players is {"max":0,"online":0}, description.text tells the player to run sculkworm-connect play <route>, and sculkworm carries {"relay":"<SCULKWORM_PUBLIC_URL>","route":"<route>"} (the sculkworm object is omitted when SCULKWORM_TUNNEL_LISTEN / SCULKWORM_PUBLIC_URL is unset, such as for an inactive persisted closed route). If the client then sends one Ping Request (0x01 + 8 opaque bytes), the relay echoes it in a Pong Response (0x01), shuts down its write half, and closes after at most 2 seconds.
  • Login (2) and transfer (3). Without waiting for Login Start, the relay sends a Login Disconnect (0x00) with the JSON text component instructing the player to run sculkworm-connect play <route> and join 127.0.0.1, shuts down its write half, and closes after at most 2 seconds.
  • Unknown hosts. Hostnames that match neither an open route nor a closed route still close immediately with zero bytes written (event=unknown_host).

Handshake packet layout#

Every modern Minecraft Java Edition connection begins with a VarInt-framed Handshake packet:

Field Wire type Notes
Packet Length VarInt Byte length of the remaining packet fields. Must be 1..=4096.
Packet ID VarInt Must be 0x00.
Protocol Version VarInt Signed 32-bit protocol number, logged as protocol=<n>.
Server Address String (VarInt byte length + UTF-8 bytes) Parsed by HostField::parse to derive the route key.
Server Port Unsigned Short (u16, big-endian) Parsed from the packet; not used for routing.
Intent (Next State) VarInt 1 (status), 2 (login), or 3 (transfer).

VarInts are decoded using 7 data bits per byte with the high bit (0x80) as the continuation flag, up to 5 bytes (35 bits).

sculkworm buffers incoming bytes in 4096-byte reads (READ_CHUNK_SIZE) until the full Handshake packet arrives or SCULKWORM_HANDSHAKE_TIMEOUT_SECONDS expires. A Handshake split across multiple TCP segments (even 1 byte per segment) is reassembled before routing.

Size limits#

  • Maximum Handshake packet length (MAX_HANDSHAKE_PACKET_LEN). 4096 bytes for the packet body (excluding the outer Packet Length VarInt). Any Packet Length <= 0 or > 4096 is rejected before reading the rest of the frame. This ceiling accommodates Minecraft 26.4 host strings (up to 1024 characters plus query parameters and Forge markers).
  • VarInt length. At most 5 bytes per VarInt. A 5th byte with its continuation bit set is rejected with varint_too_long.

Host field grammar#

sculkworm parses the UTF-8 Server Address string in three steps (see src/domain.rs). Parsing never returns a Handshake parse error. An empty or malformed host field produces an unroutable sentinel domain and fails lookup with event=unknown_host.

text
server_address := host_and_query [ "\0" fml_suffix ]
host_and_query := raw_domain [ "?" query_pairs ]
query_pairs    := pair *( "&" pair )
pair           := key [ "=" value ]

Step 1. Strip the FML suffix#

If the string contains a NUL byte (\0), sculkworm splits on the first \0, sets fml = true, and discards everything from the first \0 onward for routing (for example alpha.example\0FML\0 or relay.example?_o=beta.example%3A25565\0FML\0). The original unmodified bytes are still replayed to the backend, so Forge and NeoForge backends receive the full FML marker.

Step 2. Split the Minecraft 26.4 query string#

If the remaining string contains ?, sculkworm splits on the first ? into raw_domain and raw_query.

Each non-empty &-separated pair in raw_query is split on the first =:

  • key=value stores both key and value after percent-decoding.
  • key without = stores key with an empty string value.
  • Duplicate keys overwrite earlier values in the BTreeMap.

Percent-decoding replaces %HH sequences (ASCII hex digits) with their byte values. If any % escape is truncated (%2), contains non-hex characters (%ZZ), or decodes to invalid UTF-8 (%FF), percent-decoding falls back and returns the raw input string unchanged for that component.

Step 3. Normalize domains and pick the route key#

Domain::parse applies two normalization rules:

  1. Lowercase the string with Unicode to_lowercase().
  2. Strip at most one trailing dot (.). A string with two trailing dots (alpha.example..) keeps one trailing dot (alpha.example.).

If the result is empty ("" or "."), Domain::parse returns DomainError::Empty.

sculkworm reads two named query parameters:

  • _o (origin). If _o is present, sculkworm splits it on the last : and checks whether the trailing part parses as a u16 port. If it does, the prefix before : is parsed with Domain::parse as the origin domain and the trailing number is recorded as the origin port. Otherwise the entire _o value is parsed with Domain::parse with port = None. If Domain::parse returns Empty (for example _o=), origin is None.
  • _id. Recorded on HostField.id if present. sculkworm does not route on _id and does not parse <token>@<host> prefixes (abc123@alpha.example is treated as a literal domain string).

The route key is origin.domain when origin is Some, and the primary domain otherwise. If the primary domain was empty and no valid _o was supplied, the route key is the empty unroutable sentinel, which cannot match any entry in routes.json and logs event=unknown_host host=<empty>.

Normalization examples#

Raw Server Address FML Origin (_o) Route key
alpha.example false (none) alpha.example
ALPHA.Example. false (none) alpha.example
relay.example?_o=beta.example%3A25565 false beta.example (port 25565) beta.example
relay.example?_o=BETA.example. false beta.example (no port) beta.example
relay.example?_o= false (none) relay.example
alpha.example?_id=abc123 false (none) alpha.example
relay.example?_o=beta.example%3A25565\0FML\0 true beta.example (port 25565) beta.example
abc123@alpha.example false (none) abc123@alpha.example

Rejection reasons#

When reading or parsing the Handshake fails, sculkworm closes the client connection without writing any bytes and logs:

text
level=info event=handshake_rejected reason=<reason> peer=<addr>

HandshakeError reasons (src/handshake.rs)#

Reason string Cause
legacy_ping The connection starts with the three bytes FE 01 FA, the Minecraft 1.6 legacy Server List Ping. A first byte of FE alone is not rejected, because a packet length of 254 is the VarInt FE 01. A shorter legacy ping waits for the handshake timeout.
bad_length Packet Length is <= 0, Packet Length exceeds 4096, or the Server Address string length VarInt is negative.
varint_too_long A VarInt spans more than 5 bytes (5th byte has bit 0x80 set).
unexpected_packet_id The first packet ID is not 0x00.
truncated The framed packet ends before all required fields (Packet ID, Protocol Version, Server Address bytes, 2-byte Port, or Intent) are read.
bad_utf8 The Server Address byte slice is not valid UTF-8.
bad_intent The Intent (Next State) VarInt is not 1 (status), 2 (login), or 3 (transfer).

Transport reasons (src/relay.rs)#

Reason string Cause
timeout A complete Handshake packet did not arrive within SCULKWORM_HANDSHAKE_TIMEOUT_SECONDS.
eof The client closed the TCP connection before sending a complete Handshake packet.
io_error Reading from the client TCP socket returned an OS I/O error.

Verification status#

Reproduce all automated client checks from crates/sculkworm with:

sh
cargo build --locked
npm --prefix tests/clients ci --no-audit --no-fund
node tests/clients/run-all.mjs
  • Verified with minecraft-protocol (1.68.0) on Minecraft 1.21.4 (protocol 769):
    • Status pings routed by hostname to distinct backends and zero-byte close on unknown hostnames (tests/clients/offline-play.mjs, plus Docker image walkthrough).
    • Offline-mode full login through Configuration into Play state, receiving system_chat, completing 3 keepalive roundtrips, and disconnecting cleanly (tests/clients/offline-play.mjs).
    • Online-mode encrypted login through the relay using dev/mock-mojang (tests/clients/online-encrypted.mjs): RSA-1024 Encryption Request/Response, POST /session/minecraft/join, GET /session/minecraft/hasJoined, bidirectional AES-128-CFB8 encryption, and encrypted Configuration + Play traffic (system_chat + 3 keepalive roundtrips). This proves the relay splices encrypted login and Play streams untouched, but does not replace testing with real Mojang sessionserver.mojang.com, Microsoft OAuth tokens, or a real vanilla launcher.
  • Verified at the wire level and in Rust tests (from specification, not a real vanilla client):
    • Handshake framing, 1-byte TCP fragmentation, MAX_HANDSHAKE_PACKET_LEN (4096), 254-byte packet length VarInt (FE 01) vs FE 01 FA legacy ping rejection, Forge \0FML\0 suffix stripping and byte-for-byte replay (src/domain.rs, src/handshake.rs, tests/relay.rs).
    • Minecraft 26.4 _o (origin, percent-encoded and literal :port) and _id query parameters, Transfer intent (3), 1024-character hosts, verbatim Handshake replay, and pre-26.4 SRV target rejection (tests/clients/handshake-26.4-srv.mjs).
      • Source for 26.4 format (checked 2026-11-26): Minecraft Wiki Java Edition 26.4 Snapshot 1 and Java Edition 26.4 — serverbound minecraft:intention host field supports URI-like ?k=v&... percent-encoded parameters up to 1024 characters; <id>@<host> is parsed as <host>?_id=<id>; SRV redirection sends <redirected domain>?_o=<original domain>:<original port> with the resolved port in the packet port field.
      • Source for pre-26.4 SRV behavior (checked 2026-11-26): Minecraft Wiki Java Edition protocol/Packets (MC-278651) — Server Address is the name obtained after SRV resolution on Login (except 1.17), whereas Server List Ping sends the user-entered hostname.
  • Not yet verified with a real vanilla / Prism Launcher Minecraft client (see the Real-client verification runbook):
    • Online-mode encrypted login with a real Mojang/Microsoft account and vanilla client.
    • Minecraft 26.4 _o (origin) and _id Handshake host query parameters from a real 26.4 client.
    • What vanilla Minecraft Java clients older than 26.4 send in the Handshake host field after following a live DNS SRV record.