[PR #4531] [MERGED] Server: vanilla's reach checks on attacks and entity interactions #5678

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

📋 Pull Request Information

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

Base: main ← Head: fix/server-reach


📝 Commits (1)

  • d39eb5d Server: vanilla's reach on attacks and entity interactions, and blocks by attribute

📊 Changes

5 files changed (+355 additions, -9 deletions)

View changed files

📝 crates/horizon-bots/src/main.rs (+54 -4)
📝 crates/horizon-client/src/game/hand.rs (+74 -0)
📝 crates/horizon-client/src/game/lan_actions.rs (+71 -2)
📝 crates/horizon-client/src/lan/guest.rs (+9 -3)
➕ tools/server_reach_e2e.py (+147 -0)

📄 Description

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

What and why

Horizon's server path (LAN host, the integrated server thread, dedicated servers) never checked the range of ServerboundAttackPacket: a hacked client could hit any player or mob it knew the id of, from any distance ("there's literally no reach checks, so you can just set reach to 1000"; a player was seen hitting people from far away on the official server). This mirrors vanilla's checks exactly, always on (vanilla parity, not the anticheat):

  • handleAttack: Player.isWithinAttackRange(mainHandItem, targetBox, 3.0) before anything else, for players, mobs, vehicles and objects, dragon parts and crystals, projectiles. It uses the held item's attack_range component, else AttackRange.defaultFor (0 to the entity_interaction_range attribute, no margin). So a survival player reaches 3 + 3 = 6 blocks from the eyes to the target's box and a creative one 5 + 3 = 8. Out of range, the attack is dropped silently, as vanilla does: no log, no kick.
  • handleInteract: Player.isWithinEntityInteractionRange(targetBox, 3.0).
  • Digging and handleUseItemOn already checked isWithinBlockInteractionRange(pos, 1.0) but with a fixed 4.5 (5 in creative). They now read the guest's block_interaction_range attribute, so /attribute and items count. handleUseItemOn now also logs vanilla's Rejecting UseItemOnPacket from NAME: Location (x, y, z) too far away from hit block BlockPos{...}. before dropping the packet.

The ranges are the player's own attributes: ServerPlayer.updatePlayerAttributes puts creative's modifiers on them every tick (+2 entity, +0.5 block).

About "6 blocks refused": vanilla's server accepts a hit 6 blocks away. Its tolerance is the range plus 3, and at 6 blocks the victim's box is 5.7 from the eyes. The test checks vanilla's real boundary: 6 hits, 7 is refused. Tighter checks (the client's 3 blocks, with latency compensation) belong to the anticheat's reach check, off by default.

Vanilla reference

ServerGamePacketListenerImpl.handleAttack, handleInteract, handleUseItemOn; ServerPlayerGameMode.handleBlockBreakAction; Player.isWithinAttackRange, isWithinEntityInteractionRange, isWithinBlockInteractionRange; LivingEntity.getAttackRangeWith; AttackRange.defaultFor, isInRange, effectiveMinRange/effectiveMaxRange (read with tools/rea_vanilla.py).

Tests

  • tools/server_reach_e2e.py (new): a real survival dedicated server and pairs of horizon-bots, placed with /tp. Each attacker sends ServerboundAttackPacket at its victim twice a second (new --behaviour stand, --attack NAME, health in the report):

    attacker distance main this branch (= vanilla)
    survival 3 hit hit
    survival 6 hit hit
    survival 7 hit refused
    survival 50 hit refused
    creative 7 hit hit
    creative 9 hit refused
  • Unit test the_server_takes_attacks_within_vanilla_reach_only (survival 6 / creative 8 bounds, a spear's own range with its margin); the existing block-reach test still passes with the attribute.

pr_ready (tools/pr_ready.py --quick --base 8f376a471237775e521e910a834a552244e12207 on ludovics-mac-mini, against 8f376a4712 at 8f376a471, 8 min 13 s)

Check Result
Scope ✅ 5 files, +355 −9
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 481 passed (1 min 10 s)
rustfmt ✅ (5 s)
clippy ✅ (1 min 21 s)
tests: horizon-bots, horizon-client ✅ 1065 passed (5 min 2 s)
doc tests ✅ 0 passed (3 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)

Harnesses (tools/parity.py --changed-files on this branch's files, Mac mini): 34 of 35 pass: block_removal, command_exec, composter, crafter, cursor_death, dedicated_server, dispenser, forced_end, friends_integration, hardcore_respawn, locator_bar, mace, online_mode, pearl_death, pearl_wind_charge, remote_fireball, remote_fireworks, sculk, secure_chat, server_dimension_players, server_dragon, server_entities, server_knockback, server_ops_feedback, server_player_sculk, server_player_targets, server_resource_pack, server_world_gen, use_item_on, user_cache, world_spawn#1, world_spawn#2, world_spawn#3, world_spawn#4.

lunge_motion differs, and it isn't this change. A spear's Lunge is ServerboundPlayerActionPacket STAB, a path this PR doesn't touch, and the harness's vanilla transcript itself changed between two runs on the loaded machine (rising 0.0831, then 0.1648): its jump timing depends on load.

🤖 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/4531 **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:** `fix/server-reach` --- ### 📝 Commits (1) - [`d39eb5d`](https://github.com/horizon-rust/horizon/commit/d39eb5d638673755c4b720f66c3d16ec424df869) Server: vanilla's reach on attacks and entity interactions, and blocks by attribute ### 📊 Changes **5 files changed** (+355 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-bots/src/main.rs` (+54 -4) 📝 `crates/horizon-client/src/game/hand.rs` (+74 -0) 📝 `crates/horizon-client/src/game/lan_actions.rs` (+71 -2) 📝 `crates/horizon-client/src/lan/guest.rs` (+9 -3) ➕ `tools/server_reach_e2e.py` (+147 -0) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What and why Horizon's server path (LAN host, the integrated server thread, dedicated servers) never checked the range of `ServerboundAttackPacket`: a hacked client could hit any player or mob it knew the id of, from any distance ("there's literally no reach checks, so you can just set reach to 1000"; a player was seen hitting people from far away on the official server). This mirrors vanilla's checks exactly, **always on** (vanilla parity, not the anticheat): - **handleAttack**: `Player.isWithinAttackRange(mainHandItem, targetBox, 3.0)` before anything else, for players, mobs, vehicles and objects, dragon parts and crystals, projectiles. It uses the held item's `attack_range` component, else `AttackRange.defaultFor` (0 to the `entity_interaction_range` attribute, no margin). So a survival player reaches 3 + 3 = 6 blocks from the eyes to the target's box and a creative one 5 + 3 = 8. Out of range, the attack is dropped silently, as vanilla does: no log, no kick. - **handleInteract**: `Player.isWithinEntityInteractionRange(targetBox, 3.0)`. - **Digging and handleUseItemOn** already checked `isWithinBlockInteractionRange(pos, 1.0)` but with a fixed 4.5 (5 in creative). They now read the guest's `block_interaction_range` attribute, so `/attribute` and items count. handleUseItemOn now also logs vanilla's `Rejecting UseItemOnPacket from NAME: Location (x, y, z) too far away from hit block BlockPos{...}.` before dropping the packet. The ranges are the player's own attributes: `ServerPlayer.updatePlayerAttributes` puts creative's modifiers on them every tick (+2 entity, +0.5 block). **About "6 blocks refused":** vanilla's server *accepts* a hit 6 blocks away. Its tolerance is the range plus 3, and at 6 blocks the victim's box is 5.7 from the eyes. The test checks vanilla's real boundary: 6 hits, 7 is refused. Tighter checks (the client's 3 blocks, with latency compensation) belong to the anticheat's reach check, off by default. ## Vanilla reference `ServerGamePacketListenerImpl.handleAttack`, `handleInteract`, `handleUseItemOn`; `ServerPlayerGameMode.handleBlockBreakAction`; `Player.isWithinAttackRange`, `isWithinEntityInteractionRange`, `isWithinBlockInteractionRange`; `LivingEntity.getAttackRangeWith`; `AttackRange.defaultFor`, `isInRange`, `effectiveMinRange`/`effectiveMaxRange` (read with `tools/rea_vanilla.py`). ## Tests - `tools/server_reach_e2e.py` (new): a real survival dedicated server and pairs of horizon-bots, placed with `/tp`. Each attacker sends `ServerboundAttackPacket` at its victim twice a second (new `--behaviour stand`, `--attack NAME`, health in the report): | attacker | distance | main | this branch (= vanilla) | |---|---|---|---| | survival | 3 | hit | hit | | survival | 6 | hit | hit | | survival | 7 | **hit** | refused | | survival | 50 | **hit** | refused | | creative | 7 | hit | hit | | creative | 9 | **hit** | refused | - Unit test `the_server_takes_attacks_within_vanilla_reach_only` (survival 6 / creative 8 bounds, a spear's own range with its margin); the existing block-reach test still passes with the attribute. **pr_ready** (`tools/pr_ready.py --quick --base 8f376a471237775e521e910a834a552244e12207` on ludovics-mac-mini, against 8f376a471237775e521e910a834a552244e12207 at 8f376a471, 8 min 13 s) | Check | Result | | --- | --- | | Scope | ✅ 5 files, +355 −9 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 481 passed (1 min 10 s) | | rustfmt | ✅ (5 s) | | clippy | ✅ (1 min 21 s) | | tests: horizon-bots, horizon-client | ✅ 1065 passed (5 min 2 s) | | doc tests | ✅ 0 passed (3 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) | **Harnesses** (`tools/parity.py --changed-files` on this branch's files, Mac mini): **34 of 35 pass**: block_removal, command_exec, composter, crafter, cursor_death, dedicated_server, dispenser, forced_end, friends_integration, hardcore_respawn, locator_bar, mace, online_mode, pearl_death, pearl_wind_charge, remote_fireball, remote_fireworks, sculk, secure_chat, server_dimension_players, server_dragon, server_entities, server_knockback, server_ops_feedback, server_player_sculk, server_player_targets, server_resource_pack, server_world_gen, use_item_on, user_cache, world_spawn#1, world_spawn#2, world_spawn#3, world_spawn#4. `lunge_motion` differs, and it isn't this change. A spear's Lunge is `ServerboundPlayerActionPacket` STAB, a path this PR doesn't touch, and the harness's *vanilla* transcript itself changed between two runs on the loaded machine (`rising` 0.0831, then 0.1648): its jump timing depends on load. 🤖 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:16 +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#5678
No description provided.