[PR #3586] [MERGED] Input: release held keys when leaving a server #5076

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

📋 Pull Request Information

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

Base: main ← Head: fix-3246


📝 Commits (1)

  • 698e7fd Input: release held keys when leaving a server

📊 Changes

2 files changed (+34 additions, -0 deletions)

View changed files

📝 crates/horizon-client/src/game/remote.rs (+6 -0)
📝 tools/lan_e2e.py (+28 -0)

📄 Description

🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando themselves.

What and why

Fixes #3246

A player holding W and Space when the LAN host closed the world had both keys stuck down after joining again: the player walked and jumped on their own until the keys were pressed and released again.

The cause: Game::keys, the set of held movement keys, was not emptied when the player left a server. Once the title or disconnect screen is open, key releases go to that screen's handler, not to keys. So the W and Space the player let go of on the "Connection Lost" screen were still in keys when the next world started. (Focus loss and screens such as chat, books, options and the server pack prompt already clear it. leave_server was the gap.)

Vanilla releases every key mapping whenever a screen opens: Gui.setScreen calls MouseHandler.releaseMouse and KeyMapping.releaseAll. That covers the disconnect screen and the title screen. leave_server (game/remote.rs) now does the same before it shows either one. It clears keys and the attack and use buttons (left, right). Toggled sneak and sprint already follow vanilla through track_toggle_screens, so they are unchanged.

Vanilla reference

From javap -c on the 26.3 client.jar:

  • Gui.setScreen: for a non-null screen, MouseHandler.releaseMouse() then KeyMapping.releaseAll()
  • KeyMapping.releaseAll → KeyMapping.release (clickCount = 0, setDown(false))
  • ToggleKeyMapping.release / KeyMapping.restoreToggleStatesOnScreenClosed (Horizon's track_toggle_screens, unchanged)

No parity harness covers input across a disconnect. tools/lan_e2e.py gets a check, keys_released, with two real games over LAN. The guest holds W and Space, leaves the server and joins again. Its held keys must be empty after it leaves and after it rejoins, and it must not move in the 20 ticks after it rejoins.

Before the fix (this branch with the remote.rs change reverted):

$ python tools/lan_e2e.py --check keys_released
[lan] keys_released: FAIL AssertionError("keys stayed down after leaving: {'held': ['KeyW', 'Space'], 'left': ['KeyW', 'Space'], 'rejoined': ['KeyW', 'Space'], 'walked': 0.409}")

After:

$ python tools/lan_e2e.py --check keys_released --check leave
[lan] keys_released: PASS {'held': ['KeyW', 'Space'], 'left': [], 'rejoined': [], 'walked': 0.0}
[lan] leave: PASS {'leave_game': [2, 3]}

(On Windows, lan_e2e was run through a small wrapper: junctions instead of symlinks, no vscreen, and horizon-ctl launch's output sent to a file, because a captured launch never reaches EOF there. The check itself is unchanged.)

Self-check

Run on Windows 11. tools/pr_ready.py was not run; these are the steps it runs:

cargo fmt --all -- --check                                                    ok
cargo clippy -p horizon-client --features mods --all-targets -- -D warnings   ok
cargo test -p horizon-client --features mods --bins remote::                  3 passed
python tools/lan_e2e.py --check keys_released --check leave                   2 passed (keys_released fails before the fix)

In game

In game, reproduced as in the report with two games over LAN (the host on its server thread). The guest holds W and Space (horizon-ctl key w down, key space down), and the host saves and quits. The guest gets "Connection Lost / Server closed". Then the host opens the world to LAN again and the guest rejoins.

  • Before: status.keys on the disconnect screen is ["KeyW", "Space"], and still is after rejoining. The guest walks and jumps by itself: z 544.5 → 550.4, y 69.0 → 70.25 in 20 ticks.
  • After: status.keys is [] on the disconnect screen and after rejoining, and the guest stands still (the same position 40 ticks apart).

🤖 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/3586 **Author:** [@d3grando](https://github.com/d3grando) **Created:** 10/29/2026 **Status:** ✅ Merged **Merged:** 10/29/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix-3246` --- ### 📝 Commits (1) - [`698e7fd`](https://github.com/horizon-rust/horizon/commit/698e7fd662ba0a6502f0965ea660994f4f11092f) Input: release held keys when leaving a server ### 📊 Changes **2 files changed** (+34 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/remote.rs` (+6 -0) 📝 `tools/lan_e2e.py` (+28 -0) </details> ### 📄 Description > 🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando themselves. ## What and why Fixes #3246 A player holding W and Space when the LAN host closed the world had both keys stuck down after joining again: the player walked and jumped on their own until the keys were pressed and released again. The cause: `Game::keys`, the set of held movement keys, was not emptied when the player left a server. Once the title or disconnect screen is open, key releases go to that screen's handler, not to `keys`. So the W and Space the player let go of on the "Connection Lost" screen were still in `keys` when the next world started. (Focus loss and screens such as chat, books, options and the server pack prompt already clear it. `leave_server` was the gap.) Vanilla releases every key mapping whenever a screen opens: `Gui.setScreen` calls `MouseHandler.releaseMouse` and `KeyMapping.releaseAll`. That covers the disconnect screen and the title screen. `leave_server` (`game/remote.rs`) now does the same before it shows either one. It clears `keys` and the attack and use buttons (`left`, `right`). Toggled sneak and sprint already follow vanilla through `track_toggle_screens`, so they are unchanged. ## Vanilla reference From `javap -c` on the 26.3 `client.jar`: - `Gui.setScreen`: for a non-null screen, `MouseHandler.releaseMouse()` then `KeyMapping.releaseAll()` - `KeyMapping.releaseAll` → `KeyMapping.release` (`clickCount = 0`, `setDown(false)`) - `ToggleKeyMapping.release` / `KeyMapping.restoreToggleStatesOnScreenClosed` (Horizon's `track_toggle_screens`, unchanged) No parity harness covers input across a disconnect. `tools/lan_e2e.py` gets a check, `keys_released`, with two real games over LAN. The guest holds W and Space, leaves the server and joins again. Its held keys must be empty after it leaves and after it rejoins, and it must not move in the 20 ticks after it rejoins. Before the fix (this branch with the `remote.rs` change reverted): ``` $ python tools/lan_e2e.py --check keys_released [lan] keys_released: FAIL AssertionError("keys stayed down after leaving: {'held': ['KeyW', 'Space'], 'left': ['KeyW', 'Space'], 'rejoined': ['KeyW', 'Space'], 'walked': 0.409}") ``` After: ``` $ python tools/lan_e2e.py --check keys_released --check leave [lan] keys_released: PASS {'held': ['KeyW', 'Space'], 'left': [], 'rejoined': [], 'walked': 0.0} [lan] leave: PASS {'leave_game': [2, 3]} ``` (On Windows, lan_e2e was run through a small wrapper: junctions instead of symlinks, no vscreen, and `horizon-ctl launch`'s output sent to a file, because a captured launch never reaches EOF there. The check itself is unchanged.) ## Self-check Run on Windows 11. `tools/pr_ready.py` was not run; these are the steps it runs: ``` cargo fmt --all -- --check ok cargo clippy -p horizon-client --features mods --all-targets -- -D warnings ok cargo test -p horizon-client --features mods --bins remote:: 3 passed python tools/lan_e2e.py --check keys_released --check leave 2 passed (keys_released fails before the fix) ``` ## In game In game, reproduced as in the report with two games over LAN (the host on its server thread). The guest holds W and Space (`horizon-ctl key w down`, `key space down`), and the host saves and quits. The guest gets "Connection Lost / Server closed". Then the host opens the world to LAN again and the guest rejoins. - **Before:** `status.keys` on the disconnect screen is `["KeyW", "Space"]`, and still is after rejoining. The guest walks and jumps by itself: z 544.5 → 550.4, y 69.0 → 70.25 in 20 ticks. - **After:** `status.keys` is `[]` on the disconnect screen and after rejoining, and the guest stands still (the same position 40 ticks apart). 🤖 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:10: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#5076
No description provided.