[PR #4607] [MERGED] Anticheat framework for the dedicated server, off by default, with a timer check #5726

Closed
opened 2026-11-03 05:14:35 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4607
Author: @ludovic111
Created: 10/30/2026
Status: ✅ Merged
Merged: 10/30/2026
Merged by: @ludovic111

Base: main ← Head: feat/anticheat-framework


📝 Commits (1)

  • 876d000 Anticheat framework, off by default, with a timer check

📊 Changes

19 files changed (+939 additions, -3 deletions)

View changed files

📝 AGENTS.md (+2 -1)
📝 Cargo.lock (+10 -0)
📝 Cargo.toml (+1 -0)
➕ crates/horizon-anticheat/Cargo.toml (+14 -0)
➕ crates/horizon-anticheat/src/lib.rs (+295 -0)
➕ crates/horizon-anticheat/src/timer.rs (+111 -0)
📝 crates/horizon-bots/src/main.rs (+11 -1)
📝 crates/horizon-client/Cargo.toml (+2 -0)
📝 crates/horizon-client/src/game/dedicated.rs (+25 -0)
➕ crates/horizon-client/src/lan/anticheat.rs (+168 -0)
📝 crates/horizon-client/src/lan/guest.rs (+3 -0)
📝 crates/horizon-client/src/lan/hub.rs (+5 -0)
📝 crates/horizon-client/src/lan/mod.rs (+1 -0)
📝 crates/horizon-server/Cargo.toml (+2 -0)
📝 crates/horizon-server/src/config.rs (+46 -1)
📝 docs/README.md (+1 -0)
➕ docs/anticheat.md (+71 -0)
➕ tools/anticheat_e2e.py (+159 -0)
📝 tools/server_bench.py (+12 -0)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

What and why

The first piece of a server-side anticheat for Horizon's dedicated server (the official server's owner wanted Grim, a Paper plugin that can't run on Horizon). Off by default, and nothing changes when it's off. The generated server.toml only gets a commented example. A server without [anticheat] holds no anticheat state at all (Hub::anticheat is None), so it does exactly what vanilla's does. Only a server that turns it on (the official one) runs it.

[anticheat]
enabled = true

[anticheat.timer]   # every key optional
setback = 2
alert = 5
kick = 20
decay = 0.02

The framework (crates/horizon-anticheat, no game state, unit-tested; the hub's side is lan/anticheat.rs):

  • per-player violation levels per check, decaying every second;
  • actions by level: from setback, the move is cancelled (sent back); from alert, the console, logs/anticheat.log and online operators (alert_level, default 2) are told, at most once a second; from kick, the player is disconnected. A threshold at 0 turns that action off. Nothing bans;
  • a toggle and thresholds per check. Each check is one entry in a checks! table, with its own settings;
  • horizon-server checks the section before every start (unknown keys and negative levels are refused); the game reads it from server.toml when it starts.

The first check, timer: a sped-up client sends more ticks than the server's clock allows. Vanilla's client ends every tick with ServerboundClientTickEndPacket, at the server's tick rate (Minecraft.tick). Each one spends one tick of a balance that wall-clock time fills; a client more than 300 ms ahead is flagged. The balance is capped (1 s) after each tick's packets are counted, so a slow server tick's backlog and a lag spike aren't flagged, and a pause can't be saved up for a burst. Vanilla already kicks two positions within one client tick (receivedPositionThisTick), so this closes the timer cheat.

Movement, combat, world (with anti-xray) and packet checks follow in their own PRs (docs/anticheat.md). The packet checks that mirror vanilla's own validation will be always on, like vanilla's.

Cost (measured)

60 walking bots, tools/server_bench.py --servers horizon --bots 60 --behaviour walk (new --anticheat), Mac mini under its usual load, 120 s measured after 30 s of warm-up, MSPT from /tick query:

server MSPT avg (run 1 / run 2) P95 P99 flags
main 6.30 / 6.34 7.28 / 7.40 8.17 / 8.27 –
this branch, anticheat off 6.19 / 6.71 7.16 / 8.00 7.79 / 9.65 0 / 0
this branch, anticheat on 6.44 / 6.22 7.50 / 7.22 8.57 / 8.13 0 / 0

Runs were interleaved (main, off, on, then again). The machine was busy, so a run swings by ~0.5 ms: off beat main in round 1 and lost in round 2, and on did the reverse. Off is main within that noise: one Option check a tick and one per ClientTickEnd. On adds a float subtraction per player per tick. None of the 60 legit bots was flagged.

Originality

Written from vanilla 26.3 (Minecraft.tick, ServerGamePacketListenerImpl.handleMovePlayer/handleClientTickEnd, TickRateManager) and the public description of what a timer cheat does. No other anticheat's code or docs were read (Grim, NoCheatPlus, Vulcan, Matrix, Spartan...).

Tests

  • horizon-anticheat unit tests: levels rise, decay and act in order, 0 turns an action off, the section is read and checked; the balance never flags a vanilla client (20 Hz, a 10 TPS server, a 3 s server stall, an 800 ms network stall) and flags 1.1x and 2x clients again and again, and a saved-up pause.
  • horizon-server: [anticheat] is off unless its section turns it on, round-trips through render, and bad keys are refused.
  • tools/anticheat_e2e.py (new), a real dedicated server with horizon-bots (new --timer F):
    • timer: a 1.5x bot is flagged (21 times in 40 s), sent back, alerted on the console and kicked; 6 legit bots walking and exploring are never flagged;
    • off: no [anticheat]: nothing is logged and nobody is kicked, the 1.5x bot included.

pr_ready (tools/pr_ready.py --quick on ludovics-mac-mini, against origin/main at af5528ef2, 15 min 19 s)

Check Result
Scope ⚠️ 19 files, +939 −3; 867 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ changes with a Cargo.toml
Public tree ✅
Python tests ✅ 481 passed (1 min 3 s)
rustfmt ✅ (4 s)
clippy ✅ (1 min 33 s)
tests: workspace ✅ 2817 passed (6 min 55 s)
doc tests ✅ 0 passed (4 s)
content root tests ✅ 6 passed (1 min 26 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ✅ (2 s)
launcher clippy ✅ (1 min 47 s)
launcher tests ✅ 295 passed (2 min 24 s)
Parity ➖ 357 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, arrow, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes, auto_jump, bamboo and 345 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

Also run on the rebased head: python3 tools/parity.py dedicated_server server_entities server_player_damage: 3 passed; tools/anticheat_e2e.py: off and timer pass.

🤖 Generated with Claude Code


🔄 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/4607 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/anticheat-framework` --- ### 📝 Commits (1) - [`876d000`](https://github.com/horizon-rust/horizon/commit/876d0003d5bcbac514cca87fa5d668eadc1a5c76) Anticheat framework, off by default, with a timer check ### 📊 Changes **19 files changed** (+939 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `AGENTS.md` (+2 -1) 📝 `Cargo.lock` (+10 -0) 📝 `Cargo.toml` (+1 -0) ➕ `crates/horizon-anticheat/Cargo.toml` (+14 -0) ➕ `crates/horizon-anticheat/src/lib.rs` (+295 -0) ➕ `crates/horizon-anticheat/src/timer.rs` (+111 -0) 📝 `crates/horizon-bots/src/main.rs` (+11 -1) 📝 `crates/horizon-client/Cargo.toml` (+2 -0) 📝 `crates/horizon-client/src/game/dedicated.rs` (+25 -0) ➕ `crates/horizon-client/src/lan/anticheat.rs` (+168 -0) 📝 `crates/horizon-client/src/lan/guest.rs` (+3 -0) 📝 `crates/horizon-client/src/lan/hub.rs` (+5 -0) 📝 `crates/horizon-client/src/lan/mod.rs` (+1 -0) 📝 `crates/horizon-server/Cargo.toml` (+2 -0) 📝 `crates/horizon-server/src/config.rs` (+46 -1) 📝 `docs/README.md` (+1 -0) ➕ `docs/anticheat.md` (+71 -0) ➕ `tools/anticheat_e2e.py` (+159 -0) 📝 `tools/server_bench.py` (+12 -0) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What and why The first piece of a server-side anticheat for Horizon's dedicated server (the official server's owner wanted Grim, a Paper plugin that can't run on Horizon). **Off by default, and nothing changes when it's off.** The generated `server.toml` only gets a commented example. A server without `[anticheat]` holds no anticheat state at all (`Hub::anticheat` is `None`), so it does exactly what vanilla's does. Only a server that turns it on (the official one) runs it. ```toml [anticheat] enabled = true [anticheat.timer] # every key optional setback = 2 alert = 5 kick = 20 decay = 0.02 ``` **The framework** (`crates/horizon-anticheat`, no game state, unit-tested; the hub's side is `lan/anticheat.rs`): - per-player violation levels per check, decaying every second; - actions by level: from `setback`, the move is cancelled (sent back); from `alert`, the console, `logs/anticheat.log` and online operators (`alert_level`, default 2) are told, at most once a second; from `kick`, the player is disconnected. A threshold at 0 turns that action off. **Nothing bans**; - a toggle and thresholds per check. Each check is one entry in a `checks!` table, with its own settings; - horizon-server checks the section before every start (unknown keys and negative levels are refused); the game reads it from `server.toml` when it starts. **The first check, `timer`:** a sped-up client sends more ticks than the server's clock allows. Vanilla's client ends every tick with `ServerboundClientTickEndPacket`, at the server's tick rate (`Minecraft.tick`). Each one spends one tick of a balance that wall-clock time fills; a client more than 300 ms ahead is flagged. The balance is capped (1 s) after each tick's packets are counted, so a slow server tick's backlog and a lag spike aren't flagged, and a pause can't be saved up for a burst. Vanilla already kicks two positions within one client tick (`receivedPositionThisTick`), so this closes the timer cheat. Movement, combat, world (with anti-xray) and packet checks follow in their own PRs (docs/anticheat.md). The packet checks that mirror vanilla's own validation will be always on, like vanilla's. ## Cost (measured) 60 walking bots, `tools/server_bench.py --servers horizon --bots 60 --behaviour walk` (new `--anticheat`), Mac mini under its usual load, 120 s measured after 30 s of warm-up, MSPT from `/tick query`: | server | MSPT avg (run 1 / run 2) | P95 | P99 | flags | |---|---|---|---|---| | main | 6.30 / 6.34 | 7.28 / 7.40 | 8.17 / 8.27 | – | | this branch, anticheat off | 6.19 / 6.71 | 7.16 / 8.00 | 7.79 / 9.65 | 0 / 0 | | this branch, anticheat on | 6.44 / 6.22 | 7.50 / 7.22 | 8.57 / 8.13 | 0 / 0 | Runs were interleaved (main, off, on, then again). The machine was busy, so a run swings by ~0.5 ms: off beat main in round 1 and lost in round 2, and on did the reverse. Off is main within that noise: one `Option` check a tick and one per `ClientTickEnd`. On adds a float subtraction per player per tick. None of the 60 legit bots was flagged. ## Originality Written from vanilla 26.3 (`Minecraft.tick`, `ServerGamePacketListenerImpl.handleMovePlayer`/`handleClientTickEnd`, `TickRateManager`) and the public description of what a timer cheat does. No other anticheat's code or docs were read (Grim, NoCheatPlus, Vulcan, Matrix, Spartan...). ## Tests - `horizon-anticheat` unit tests: levels rise, decay and act in order, 0 turns an action off, the section is read and checked; the balance never flags a vanilla client (20 Hz, a 10 TPS server, a 3 s server stall, an 800 ms network stall) and flags 1.1x and 2x clients again and again, and a saved-up pause. - horizon-server: `[anticheat]` is off unless its section turns it on, round-trips through `render`, and bad keys are refused. - `tools/anticheat_e2e.py` (new), a real dedicated server with horizon-bots (new `--timer F`): - `timer`: a 1.5x bot is flagged (21 times in 40 s), sent back, alerted on the console and kicked; 6 legit bots walking and exploring are never flagged; - `off`: no `[anticheat]`: nothing is logged and nobody is kicked, the 1.5x bot included. **pr_ready** (`tools/pr_ready.py --quick` on ludovics-mac-mini, against origin/main at af5528ef2, 15 min 19 s) | Check | Result | | --- | --- | | Scope | ⚠️ 19 files, +939 −3; 867 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ changes with a Cargo.toml | | Public tree | ✅ | | Python tests | ✅ 481 passed (1 min 3 s) | | rustfmt | ✅ (4 s) | | clippy | ✅ (1 min 33 s) | | tests: workspace | ✅ 2817 passed (6 min 55 s) | | doc tests | ✅ 0 passed (4 s) | | content root tests | ✅ 6 passed (1 min 26 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ✅ (2 s) | | launcher clippy | ✅ (1 min 47 s) | | launcher tests | ✅ 295 passed (2 min 24 s) | | Parity | ➖ 357 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, arrow, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes, auto_jump, bamboo and 345 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | Also run on the rebased head: `python3 tools/parity.py dedicated_server server_entities server_player_damage`: 3 passed; `tools/anticheat_e2e.py`: off and timer pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:14:35 +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#5726
No description provided.