[PR #4919] [MERGED] Anticheat prediction (a): record each client tick and the server ticks it had seen #5942

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

📋 Pull Request Information

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

Base: main ← Head: feat/anticheat-prediction-record


📝 Commits (1)

  • d26c8fb Anticheat prediction (a): record each client tick and the server ticks it saw

📊 Changes

7 files changed (+312 additions, -1 deletions)

View changed files

📝 crates/horizon-anticheat/src/lib.rs (+9 -0)
➕ crates/horizon-anticheat/src/prediction.rs (+161 -0)
📝 crates/horizon-client/src/game/lan.rs (+1 -0)
📝 crates/horizon-client/src/lan/anticheat.rs (+57 -0)
📝 crates/horizon-client/src/lan/hub.rs (+6 -1)
📝 crates/horizon-client/tests/lan_bot.rs (+77 -0)
📝 docs/anticheat.md (+1 -0)

📄 Description

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

The first of the movement prediction's PRs (plan agreed with @rdbtCVS on #4735): (a) record each client tick. (b) plays a tick again with vanilla's movement code, (c) is the check, (d) the e2e bots. It replaces #4735's bound-based speed and the planned step.

What it does

A new check, prediction in [anticheat]. Like every check it only runs when the anticheat is on, and it is off in the default server.toml (no [anticheat] block). For now it only records and flags nothing:

  • Client ticks (horizon_anticheat::prediction::Record). A vanilla client ends every tick with ServerboundClientTickEndPacket, and the packets in between are one client tick. Each tick records the keys held (ServerboundPlayerInputPacket), sprinting, the rotation, the move's position and flags, and the last server tick the client had handled. The record keeps the last 40 ticks.
  • Ping/pong brackets. Every server tick ends with a ClientboundPingPacket whose id is that tick, sent after everything else the tick sent, just before the flush. A vanilla client answers it as soon as it handles it, before its next tick runs. So each client tick knows which server ticks' changes (a push, a teleport, an effect) were in effect during it, and which weren't. The record ignores a pong for a ping that was never sent, a duplicate, or one out of order. A Pong doesn't count as an action for the idle timeout.

Record::clear (teleports, respawns) and the replay come with (b).

Cost (60 walking bots, Mac mini, 30 s warmup + 120 s)

Build MSPT P95 P99 RSS MB CPU %
main (00643bca1) 4.35 4.92 5.43 624.6 190.8
this PR, anticheat off (the default) 4.41 5.02 6.33 626.9 168.2
this PR, --anticheat (prediction recording) 4.33 4.88 5.33 623.7 165.2

All three are within run-to-run noise on the busy Mac mini. The recording costs one ping a tick per player and a 40-tick ring buffer.

When the anticheat is off, the cost is one Option test per move packet and per pong.

Tests

  • prediction.rs unit tests: a tick is the packets between two tick ends; pongs mark which server ticks each tick had seen (never sent, duplicate, out of order are rejected); only the last 40 ticks are kept.
  • lan_bot the_prediction_records_each_client_tick_and_the_server_ticks_it_had_seen: a real hub with the anticheat on gets a pong, an input, a move and two tick ends. The test checks both recorded ticks, and that a pong for a ping never sent changes nothing.

pr_ready

Check Result
Scope ✅ 7 files, +312 −1
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 486 passed (53 s)
rustfmt ✅ (4 s)
clippy ✅ (50 s)
tests: horizon-anticheat, horizon-client ✅ 1288 passed (3 min 10 s)
doc tests ✅ 0 passed (1 s)
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 ➖ 33 affected, to run in CI (--quick): block_removal, command_exec, composter, crafter, cursor_death, dedicated_server, dispenser, forced_end, friends_integration, hardcore_respawn, lan_integration, locator_bar and 21 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

Clean-room: written from vanilla 26.3 (ServerGamePacketListenerImpl, ClientboundPingPacket, the client's handlePing) and public descriptions only. No other project's code.

🤖 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/4919 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/anticheat-prediction-record` --- ### 📝 Commits (1) - [`d26c8fb`](https://github.com/horizon-rust/horizon/commit/d26c8fba0a868517830eb3caff9a7310522b918b) Anticheat prediction (a): record each client tick and the server ticks it saw ### 📊 Changes **7 files changed** (+312 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-anticheat/src/lib.rs` (+9 -0) ➕ `crates/horizon-anticheat/src/prediction.rs` (+161 -0) 📝 `crates/horizon-client/src/game/lan.rs` (+1 -0) 📝 `crates/horizon-client/src/lan/anticheat.rs` (+57 -0) 📝 `crates/horizon-client/src/lan/hub.rs` (+6 -1) 📝 `crates/horizon-client/tests/lan_bot.rs` (+77 -0) 📝 `docs/anticheat.md` (+1 -0) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. The first of the movement prediction's PRs (plan agreed with @rdbtCVS on #4735): **(a) record each client tick**. (b) plays a tick again with vanilla's movement code, (c) is the check, (d) the e2e bots. It replaces #4735's bound-based `speed` and the planned `step`. ## What it does A new check, `prediction` in `[anticheat]`. Like every check it only runs when the anticheat is on, and it is **off in the default server.toml** (no `[anticheat]` block). For now it only records and flags nothing: - **Client ticks** (`horizon_anticheat::prediction::Record`). A vanilla client ends every tick with ServerboundClientTickEndPacket, and the packets in between are one client tick. Each tick records the keys held (ServerboundPlayerInputPacket), sprinting, the rotation, the move's position and flags, and the last server tick the client had handled. The record keeps the last 40 ticks. - **Ping/pong brackets.** Every server tick ends with a ClientboundPingPacket whose id is that tick, sent after everything else the tick sent, just before the flush. A vanilla client answers it as soon as it handles it, before its next tick runs. So each client tick knows which server ticks' changes (a push, a teleport, an effect) were in effect during it, and which weren't. The record ignores a pong for a ping that was never sent, a duplicate, or one out of order. A Pong doesn't count as an action for the idle timeout. `Record::clear` (teleports, respawns) and the replay come with (b). ## Cost (60 walking bots, Mac mini, 30 s warmup + 120 s) | Build | MSPT | P95 | P99 | RSS MB | CPU % | |---|---|---|---|---|---| | main (00643bca1) | 4.35 | 4.92 | 5.43 | 624.6 | 190.8 | | this PR, anticheat off (the default) | 4.41 | 5.02 | 6.33 | 626.9 | 168.2 | | this PR, `--anticheat` (prediction recording) | 4.33 | 4.88 | 5.33 | 623.7 | 165.2 | All three are within run-to-run noise on the busy Mac mini. The recording costs one ping a tick per player and a 40-tick ring buffer. When the anticheat is off, the cost is one `Option` test per move packet and per pong. ## Tests - `prediction.rs` unit tests: a tick is the packets between two tick ends; pongs mark which server ticks each tick had seen (never sent, duplicate, out of order are rejected); only the last 40 ticks are kept. - lan_bot `the_prediction_records_each_client_tick_and_the_server_ticks_it_had_seen`: a real hub with the anticheat on gets a pong, an input, a move and two tick ends. The test checks both recorded ticks, and that a pong for a ping never sent changes nothing. ## pr_ready | Check | Result | | --- | --- | | Scope | ✅ 7 files, +312 −1 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 486 passed (53 s) | | rustfmt | ✅ (4 s) | | clippy | ✅ (50 s) | | tests: horizon-anticheat, horizon-client | ✅ 1288 passed (3 min 10 s) | | doc tests | ✅ 0 passed (1 s) | | 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 | ➖ 33 affected, to run in CI (--quick): block_removal, command_exec, composter, crafter, cursor_death, dedicated_server, dispenser, forced_end, friends_integration, hardcore_respawn, lan_integration, locator_bar and 21 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | Clean-room: written from vanilla 26.3 (ServerGamePacketListenerImpl, ClientboundPingPacket, the client's handlePing) and public descriptions only. No other project's code. 🤖 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:16:05 +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#5942
No description provided.