[PR #5003] [MERGED] Anticheat prediction (b2): replay what the server sent, on the tick the client took it #5998

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

📋 Pull Request Information

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

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


📝 Commits (1)

  • 84f633b Anticheat prediction (b2): replay what the server sent, on the tick the client took it

📊 Changes

7 files changed (+239 additions, -60 deletions)

View changed files

📝 crates/horizon-anticheat/src/prediction.rs (+64 -0)
📝 crates/horizon-client/src/game/prediction.rs (+13 -20)
📝 crates/horizon-client/src/lan/anticheat.rs (+15 -1)
📝 crates/horizon-client/src/lan/guest.rs (+30 -0)
📝 crates/horizon-client/src/lan/prediction.rs (+110 -38)
📝 crates/horizon-protocol/src/buf.rs (+6 -0)
📝 docs/anticheat.md (+1 -1)

📄 Description

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

Movement prediction (b2), after (b1) #4989. This adds the history @rdbtCVS asked for on #4735: whatever the server sent the player that changes how its client moves is replayed on the client tick that first had it. It still flags nothing: the check, (c), is the next PR. Like every check it only runs with [anticheat] on, which no default server.toml has.

What changes

  • Guest::send notes the packets that change the player's own movement:
    • SetEntityMotion for itself (as the client decodes it, through LpVec3::quantize);
    • an explosion's knockback (Explode);
    • UpdateAttributes, UpdateMobEffect and RemoveMobEffect for itself.
  • The tick's ping files these changes in the Record (prediction::Change), each under the server tick that sent it.
  • Replay::catch_up applies each change before the first client tick whose pong had seen that server tick:
    • a velocity replaces the client's;
    • knockback adds to it;
    • attributes and effects are copied from the server's copy of the player.
  • A client that ignores a push (anti-knockback) is now off on the tick it should have taken it.
  • Attributes and status used to be copied from the server on every tick. Now they are copied only when the server sends a change, which costs less: 4.8 µs per player per tick, down from 5.6 (timed directly in the server, 60 walking bots).

Measured

  • Real Horizon client on a dedicated server with [anticheat] on: walking, sprint-jumping, turning, strafing, sneaking, with Speed III and Jump Boost II given, then cleared, by /effect (attributes and effects reach the client between ticks). All 638 ticks replayed with offset 0.0. I used a throwaway script with a temporary log line, not committed; (d) brings the committed e2e.
  • Unit tests (lan::prediction, real 26.3 data): a knockback mid-walk replays to ≤ 1e-6 on every tick. When the client ignores it, that tick is off by more than 0.3. The record keeps each change's server tick (changes_keep_the_server_tick_that_sent_them).
  • I couldn't get a real-client knockback on the server: /damage … by <armor stand> and TNT pushed nothing there. The bots of (d) will attack. Also, /attribute Walker … answers "Walker is not a valid entity for this command", a Horizon command bug outside this PR.

pr_ready

Check Result
Scope ✅ 7 files, +239 −60
Cargo.lock ✅ unchanged
Public tree ✅ (1 s)
Python tests ✅ 495 passed (1 min 5 s)
rustfmt ✅ (4 s)
clippy ✅ (42 s)
tests: horizon-anticheat, horizon-client, horizon-protocol ❌ 934 passed, 1 failed (2 min 41 s)
doc tests ✅ 0 passed (2 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 ➖ 117 affected, to run in CI (--quick)
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

The failing test is motion::tests::a_swimming_passenger_sits_up_even_when_standing_does_not_fit. It comes from #4662 and fails on main whenever .local data is present; this PR doesn't touch it. After rebasing on main (with #4989), clippy and the lan::prediction tests pass again.

Harnesses for the server's players: server_knockback, dedicated_server and server_entities pass.

Clean-room: written from vanilla 26.3 (ClientPacketListener.handleSetEntityMotion, handleExplosion, handleUpdateAttributes, handleUpdateMobEffect, ServerGamePacketListenerImpl.handlePong) 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/5003 **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-history` --- ### 📝 Commits (1) - [`84f633b`](https://github.com/horizon-rust/horizon/commit/84f633b56b4f642bbcd46608b8002917a34a5097) Anticheat prediction (b2): replay what the server sent, on the tick the client took it ### 📊 Changes **7 files changed** (+239 additions, -60 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-anticheat/src/prediction.rs` (+64 -0) 📝 `crates/horizon-client/src/game/prediction.rs` (+13 -20) 📝 `crates/horizon-client/src/lan/anticheat.rs` (+15 -1) 📝 `crates/horizon-client/src/lan/guest.rs` (+30 -0) 📝 `crates/horizon-client/src/lan/prediction.rs` (+110 -38) 📝 `crates/horizon-protocol/src/buf.rs` (+6 -0) 📝 `docs/anticheat.md` (+1 -1) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Movement prediction (b2), after (b1) #4989. This adds the history @rdbtCVS asked for on #4735: whatever the server sent the player that changes how its client moves is replayed on the client tick that first had it. It still **flags nothing**: the check, (c), is the next PR. Like every check it only runs with `[anticheat]` on, which no default server.toml has. ## What changes - `Guest::send` notes the packets that change the player's own movement: - `SetEntityMotion` for itself (as the client decodes it, through `LpVec3::quantize`); - an explosion's knockback (`Explode`); - `UpdateAttributes`, `UpdateMobEffect` and `RemoveMobEffect` for itself. - The tick's ping files these changes in the `Record` (`prediction::Change`), each under the server tick that sent it. - `Replay::catch_up` applies each change before the first client tick whose pong had seen that server tick: - a velocity replaces the client's; - knockback adds to it; - attributes and effects are copied from the server's copy of the player. - A client that ignores a push (anti-knockback) is now off on the tick it should have taken it. - Attributes and status used to be copied from the server on every tick. Now they are copied only when the server sends a change, which costs less: **4.8 µs per player per tick, down from 5.6** (timed directly in the server, 60 walking bots). ## Measured - **Real Horizon client** on a dedicated server with `[anticheat]` on: walking, sprint-jumping, turning, strafing, sneaking, with Speed III and Jump Boost II given, then cleared, by `/effect` (attributes and effects reach the client between ticks). All **638 ticks replayed with offset 0.0**. I used a throwaway script with a temporary log line, not committed; (d) brings the committed e2e. - **Unit tests** (`lan::prediction`, real 26.3 data): a knockback mid-walk replays to ≤ 1e-6 on every tick. When the client ignores it, that tick is off by more than 0.3. The record keeps each change's server tick (`changes_keep_the_server_tick_that_sent_them`). - I couldn't get a real-client knockback on the server: `/damage … by <armor stand>` and TNT pushed nothing there. The bots of (d) will attack. Also, `/attribute Walker …` answers "Walker is not a valid entity for this command", a Horizon command bug outside this PR. ## pr_ready | Check | Result | | --- | --- | | Scope | ✅ 7 files, +239 −60 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ (1 s) | | Python tests | ✅ 495 passed (1 min 5 s) | | rustfmt | ✅ (4 s) | | clippy | ✅ (42 s) | | tests: horizon-anticheat, horizon-client, horizon-protocol | ❌ 934 passed, 1 failed (2 min 41 s) | | doc tests | ✅ 0 passed (2 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 | ➖ 117 affected, to run in CI (--quick) | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | The failing test is `motion::tests::a_swimming_passenger_sits_up_even_when_standing_does_not_fit`. It comes from #4662 and fails on main whenever `.local` data is present; this PR doesn't touch it. After rebasing on main (with #4989), clippy and the `lan::prediction` tests pass again. Harnesses for the server's players: `server_knockback`, `dedicated_server` and `server_entities` pass. Clean-room: written from vanilla 26.3 (`ClientPacketListener.handleSetEntityMotion`, `handleExplosion`, `handleUpdateAttributes`, `handleUpdateMobEffect`, `ServerGamePacketListenerImpl.handlePong`) 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:31 +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#5998
No description provided.