[PR #6150] [MERGED] horizon-server: GS4 query, vanilla's UDP status port (enable-query, query.port) #6680

Closed
opened 2026-11-03 06:24:50 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/6150
Author: @Akirabane
Created: 11/1/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @ludovic111

Base: main ← Head: feat/6108-gs4-query


📝 Commits (2)

  • bfb5b21 horizon-server: GS4 query, vanilla's UDP status port (enable-query, query.port)
  • 153dca4 Merge remote-tracking branch 'origin/main' into feat/6108-gs4-query

📊 Changes

7 files changed (+790 additions, -13 deletions)

View changed files

📝 crates/horizon-server/src/main.rs (+1 -0)
➕ crates/horizon-server/src/query.rs (+742 -0)
📝 crates/horizon-server/src/supervisor.rs (+1 -0)
📝 docs/api/server.md (+4 -0)
📝 docs/hosting.md (+21 -0)
📝 docs/server.md (+8 -0)
📝 tools/port_map/rest-020.tsv (+13 -13)

📄 Description

🤖 Opened by both Akirabane's AI agent (Claude Code), and Akirabane Himself after his review.

What and why

Fixes #6108

enable-query and query.port were read from server.properties but nothing listened. The supervisor now serves vanilla's GS4 query over UDP (crates/horizon-server/src/query.rs, next to rcon.rs, std only), so server lists, status pages and monitoring tools (mcstatus, Prometheus exporters, hosting panels) can read the MOTD, the version and who is online from a Horizon server.

  • As QueryThreadGs4.create reads it: off by default; it listens on UDP server-ip (every address when empty) and query.port; a port outside 1 to 65535 leaves it off with vanilla's warning (Invalid query port {} found in server.properties (queries disabled)); a port that can't be bound is a warning, not a failed start.
  • The protocol of QueryThreadGs4: the handshake (type 9: a token below 2^24 as text after the session id), then the basic stat or the full stat (a request of 15 bytes) to a request that carries the token. The packet layout, the token's lifetime (every token goes at a check every 30 s) and the 5 s cache of the full stat were read from the decompiled classes with javap.
  • The data: MOTD, world and port come from server.properties; the players and the maximum from the game's server-status (as the control API's players use), at most once a second.
  • Where it differs, on purpose: while the game isn't running nothing answers (vanilla's query thread dies with its server); who is online is read at most once a second; a session id with bytes outside ASCII is echoed through Rust's lossy UTF-8 decoder where Java replaces each bad byte (real clients mask the id to ASCII).
  • Docs: docs/hosting.md ("Tools that read the query"), docs/server.md, docs/api/server.md; 13 rows of tools/port_map/rest-020.tsv.

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

net.minecraft.server.rcon.thread.QueryThreadGs4 (create, processPacket, buildRuleResponse, validChallenge, sendChallenge, pruneChallenges, run, initSocket) and its RequestChallenge, PktUtils.intFromNetworkByteArray, NetworkDataOutputStream. No new harness: the comparison below was run by hand on the wire.

Other projects' code

none

Self-check

pr_ready (tools/pr_ready.py --quick on DESKTOP-6PU1HU6, against origin/main at d01e5a10f, 2 min 38 s)

Check Result
Scope ⚠️ 7 files, +790 −13; 770 lines of code: the protocol and its listener are one unit (about 340 lines are tests, the rest docs and the ledger), as RCON's was
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ❌ 586 run, 2 errors, neither from this change: test_port_ledger fails to import here (a package named tests on my Windows machine shadows the repo's; python -m unittest tests.test_port_ledger passes), and test_mod_block_entity_any_template fails on main (no method named has_mods found for struct Entities, from f2b9a3c6d)
rustfmt ✅ (8 s)
clippy ✅ (38 s)
tests: horizon-server ✅ 103 passed (24 s)
doc tests ➖ no library touched
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ not run (--quick): CI's parity job picks the affected harnesses
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

Proof

Against a vanilla 26.3 server, byte for byte. Mojang's server.jar and Horizon's horizon-server each ran with the same settings (motd=Query Test Server, level-name=test, server-ip=127.0.0.1, server-port=25584, max-players=20, no player online), and a Python client sent the same packets to each and compared the raw replies:

Request Vanilla Horizon
Handshake (session id 01020304) \t, the session id, a token below 2^24 as text, NUL the same shape
Basic stat 49 bytes identical
Full stat (15-byte request) 176 bytes: splitnum, the pairs, the empty player_ section identical
A 12-byte stat request basic stat identical
No magic bytes / 2 bytes only / a wrong token / an unknown type no answer no answer

On a Horizon server with a player. With one client joined (Alice, offline mode, headless), the basic stat said numplayers 1 and the full stat's player_ section listed Alice; the other cases above stayed unanswered.

Unit tests (13): the handshake, the token per address, both stats (exact bytes), the length rule, the 5 s cache with each asker's session id, the 30 s check, a listener on a real UDP socket, and the invalid-port warnings.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/6150 **Author:** [@Akirabane](https://github.com/Akirabane) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/6108-gs4-query` --- ### 📝 Commits (2) - [`bfb5b21`](https://github.com/horizon-rust/horizon/commit/bfb5b219ffff0838fd72e45b7b87a116daf2d226) horizon-server: GS4 query, vanilla's UDP status port (enable-query, query.port) - [`153dca4`](https://github.com/horizon-rust/horizon/commit/153dca41209d01162c329831dd72cd9d11ae8a91) Merge remote-tracking branch 'origin/main' into feat/6108-gs4-query ### 📊 Changes **7 files changed** (+790 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-server/src/main.rs` (+1 -0) ➕ `crates/horizon-server/src/query.rs` (+742 -0) 📝 `crates/horizon-server/src/supervisor.rs` (+1 -0) 📝 `docs/api/server.md` (+4 -0) 📝 `docs/hosting.md` (+21 -0) 📝 `docs/server.md` (+8 -0) 📝 `tools/port_map/rest-020.tsv` (+13 -13) </details> ### 📄 Description 🤖 Opened by both Akirabane's AI agent (Claude Code), and Akirabane Himself after his review. ## What and why Fixes #6108 `enable-query` and `query.port` were read from `server.properties` but nothing listened. The supervisor now serves vanilla's GS4 query over UDP (`crates/horizon-server/src/query.rs`, next to `rcon.rs`, std only), so server lists, status pages and monitoring tools (mcstatus, Prometheus exporters, hosting panels) can read the MOTD, the version and who is online from a Horizon server. - **As `QueryThreadGs4.create` reads it:** off by default; it listens on UDP `server-ip` (every address when empty) and `query.port`; a port outside 1 to 65535 leaves it off with vanilla's warning (`Invalid query port {} found in server.properties (queries disabled)`); a port that can't be bound is a warning, not a failed start. - **The protocol of `QueryThreadGs4`:** the handshake (type 9: a token below 2^24 as text after the session id), then the basic stat or the full stat (a request of 15 bytes) to a request that carries the token. The packet layout, the token's lifetime (every token goes at a check every 30 s) and the 5 s cache of the full stat were read from the decompiled classes with `javap`. - **The data:** MOTD, world and port come from `server.properties`; the players and the maximum from the game's `server-status` (as the control API's players use), at most once a second. - **Where it differs, on purpose:** while the game isn't running nothing answers (vanilla's query thread dies with its server); who is online is read at most once a second; a session id with bytes outside ASCII is echoed through Rust's lossy UTF-8 decoder where Java replaces each bad byte (real clients mask the id to ASCII). - Docs: `docs/hosting.md` ("Tools that read the query"), `docs/server.md`, `docs/api/server.md`; 13 rows of `tools/port_map/rest-020.tsv`. ## Kind - [x] parity: Horizon now does what vanilla 26.3 does - [ ] bug: a crash or a breakage - [ ] perf: faster, or less memory - [ ] feature: something new for players (listed under New in the release notes) - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference `net.minecraft.server.rcon.thread.QueryThreadGs4` (`create`, `processPacket`, `buildRuleResponse`, `validChallenge`, `sendChallenge`, `pruneChallenges`, `run`, `initSocket`) and its `RequestChallenge`, `PktUtils.intFromNetworkByteArray`, `NetworkDataOutputStream`. No new harness: the comparison below was run by hand on the wire. ## Other projects' code none ## Self-check **pr_ready** (`tools/pr_ready.py --quick` on DESKTOP-6PU1HU6, against origin/main at d01e5a10f, 2 min 38 s) | Check | Result | | --- | --- | | Scope | ⚠️ 7 files, +790 −13; 770 lines of code: the protocol and its listener are one unit (about 340 lines are tests, the rest docs and the ledger), as RCON's was | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ❌ 586 run, 2 errors, neither from this change: `test_port_ledger` fails to import here (a package named `tests` on my Windows machine shadows the repo's; `python -m unittest tests.test_port_ledger` passes), and `test_mod_block_entity_any_template` fails on main (`no method named has_mods found for struct Entities`, from f2b9a3c6d) | | rustfmt | ✅ (8 s) | | clippy | ✅ (38 s) | | tests: horizon-server | ✅ 103 passed (24 s) | | doc tests | ➖ no library touched | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | ## Proof **Against a vanilla 26.3 server, byte for byte.** Mojang's `server.jar` and Horizon's `horizon-server` each ran with the same settings (`motd=Query Test Server`, `level-name=test`, `server-ip=127.0.0.1`, `server-port=25584`, `max-players=20`, no player online), and a Python client sent the same packets to each and compared the raw replies: | Request | Vanilla | Horizon | | --- | --- | --- | | Handshake (session id `01020304`) | `\t`, the session id, a token below 2^24 as text, NUL | the same shape | | Basic stat | 49 bytes | identical | | Full stat (15-byte request) | 176 bytes: `splitnum`, the pairs, the empty `player_` section | identical | | A 12-byte stat request | basic stat | identical | | No magic bytes / 2 bytes only / a wrong token / an unknown type | no answer | no answer | **On a Horizon server with a player.** With one client joined (`Alice`, offline mode, headless), the basic stat said `numplayers` 1 and the full stat's `player_` section listed `Alice`; the other cases above stayed unanswered. **Unit tests (13):** the handshake, the token per address, both stats (exact bytes), the length rule, the 5 s cache with each asker's session id, the 30 s check, a listener on a real UDP socket, and the invalid-port warnings. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:24:50 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#6680
No description provided.