From cc84150f6c75194655a79100fd7baef932dcc8b8 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Wed, 21 Oct 2026 23:09:18 +0200 Subject: [PATCH] A player leaving a level loses its waypoints there ServerWaypointManager.removePlayer disconnects every waypoint the player was receiving: a player who goes to another level gets an untrack for each player it tracked in the one it left. Horizon's per-level managers tick with the players in their own level only, so the untrack had no connection to go to and the player kept the old level's markers. Each level's manager now also gets the connections of the players in the other levels, for these untracks. The player-targets and dimension-players harnesses compare the waypoints as each step leaves them (the last packet for each waypoint): arriving in a level, vanilla sends the same waypoint up to three times within the step, and the packet by packet order is test_locator_bar_parity's. Both pass: 123 and 40 lines identical. Part of #843 Co-Authored-By: Claude Opus 5.5 --- .../horizon-client/src/game/lan_waypoints.rs | 7 ++- crates/horizon-client/src/lan/waypoints.rs | 51 ++++++++++++++++++- tools/test_server_dimension_players_parity.py | 17 +++++-- tools/test_server_player_targets_parity.py | 15 +++++- 4 files changed, 83 insertions(+), 7 deletions(-) diff --git a/crates/horizon-client/src/game/lan_waypoints.rs b/crates/horizon-client/src/game/lan_waypoints.rs index 44ca69939..ba1512a00 100644 --- a/crates/horizon-client/src/game/lan_waypoints.rs +++ b/crates/horizon-client/src/game/lan_waypoints.rs @@ -110,8 +110,13 @@ impl Game<'_> { .filter(|(l, _)| *l == level) .map(|(_, p)| p.clone()) .collect(); + let away: Vec<(u128, u32)> = players + .iter() + .filter(|(l, _)| *l != level) + .filter_map(|(_, p)| Some((p.uuid, p.conn?))) + .collect(); let manager = host.waypoints.entry(level.clone()).or_default(); - out.extend(manager.tick(&here, &respawned, locator_bar)); + out.extend(manager.tick_level(&here, &away, &respawned, locator_bar)); // Nobody left in the level: nothing to remember there. if here.is_empty() { host.waypoints.remove(&level); diff --git a/crates/horizon-client/src/lan/waypoints.rs b/crates/horizon-client/src/lan/waypoints.rs index 852cfc4fb..3e92d820d 100644 --- a/crates/horizon-client/src/lan/waypoints.rs +++ b/crates/horizon-client/src/lan/waypoints.rs @@ -153,6 +153,9 @@ pub struct Waypoints { /// One tick's players, and the packets for their connections. struct Tick<'a> { players: HashMap, + /// The connections of the players in other levels: one who just left this level is + /// still told of the waypoints it loses (`removePlayer` disconnects them). + away: &'a [(u128, u32)], view: HashMap, /// Players a respawn replaced this tick: a new ServerPlayer, on its first tick. fresh: &'a [u128], @@ -169,7 +172,17 @@ impl<'a> Tick<'a> { icon: &Icon, target: WaypointTarget, ) { - let Some(conn) = self.players.get(&receiver).and_then(|p| p.conn) else { + let Some(conn) = self + .players + .get(&receiver) + .and_then(|p| p.conn) + .or_else(|| { + self.away + .iter() + .find(|(uuid, _)| *uuid == receiver) + .map(|&(_, conn)| conn) + }) + else { return; }; self.out @@ -449,9 +462,22 @@ impl Waypoints { players: &[Player], respawned: &[u128], locator_bar: bool, + ) -> Vec<(u32, C)> { + self.tick_level(players, &[], respawned, locator_bar) + } + + /// [`Self::tick`] for one level of several: `away` are the connections of the players + /// in the other levels, for the untracks owed to one who has just left this one. + pub fn tick_level( + &mut self, + players: &[Player], + away: &[(u128, u32)], + respawned: &[u128], + locator_bar: bool, ) -> Vec<(u32, C)> { let mut t = Tick { players: players.iter().map(|p| (p.uuid, p)).collect(), + away, view: HashMap::default(), fresh: respawned, enabled: locator_bar, @@ -632,6 +658,29 @@ mod tests { assert_eq!(to(&out, 20), [(1, WaypointTarget::Empty)]); } + #[test] + fn a_player_leaving_the_level_loses_its_waypoints() { + let (a, b) = ( + player(1, 10, [0.5, 64.0, 0.5]), + player(2, 20, [4.5, 64.0, 0.5]), + ); + let mut w = Waypoints::default(); + w.tick(&[a.clone(), b.clone()], &[], true); + let mut moved = b.clone(); + moved.position = [5.5, 64.0, 0.5]; + w.tick(&[a.clone(), moved], &[], true); + // B goes to another level: A loses B, and B (reached through `away`) loses A. + let out = w.tick_level(std::slice::from_ref(&a), &[(2, 20)], &[], true); + assert_eq!( + to(&out, 10), + vec![(waypoint_operation::UNTRACK, WaypointTarget::Empty)] + ); + assert_eq!( + to(&out, 20), + vec![(waypoint_operation::UNTRACK, WaypointTarget::Empty)] + ); + } + #[test] fn team_colours() { assert_eq!(team_rgb("red"), Some(0xFF5555)); diff --git a/tools/test_server_dimension_players_parity.py b/tools/test_server_dimension_players_parity.py index 4ff594e96..8453d14af 100644 --- a/tools/test_server_dimension_players_parity.py +++ b/tools/test_server_dimension_players_parity.py @@ -96,15 +96,26 @@ def run_side(label, server_command, client_command, build, world): SHOWN = ('add', 'remove', 'respawn', 'track', 'untrack', 'update') +def settled(lines): + """One player's lines of one step, in order, with the waypoint packets reduced to the last for each waypoint: + what the locator bar shows once the step is over. Arriving in a level, vanilla sends the same waypoint more + than once on the way there; the packet by packet order is test_locator_bar_parity's.""" + def waypoint(line): + parts = line.split(' ') + return parts[3] if len(parts) > 3 and parts[2] in ('track', 'untrack', 'update') else None + last = {waypoint(l): i for i, l in enumerate(lines) if waypoint(l)} + return [l for i, l in enumerate(lines) if not waypoint(l) or last[waypoint(l)] == i] + + def shown(lines): - """Each player's adds, removes, respawns and waypoints, step by step; sorted within a step (the packets of one - step may leave in another order within the tick).""" + """Each player's adds, removes, respawns and waypoints (as the step leaves them), step by step; sorted within a + step (the packets of one step may leave in another order within the tick).""" steps = {} for line in lines: parts = line.split(' ', 2) if len(parts) == 3 and parts[2].split(' ')[0] in SHOWN: steps.setdefault((parts[0], parts[1]), []).append(line) - return [l for key in steps for l in sorted(steps[key])] + return [l for key in steps for l in sorted(settled(steps[key]))] def main(): diff --git a/tools/test_server_player_targets_parity.py b/tools/test_server_player_targets_parity.py index 4e925500f..71416223b 100644 --- a/tools/test_server_player_targets_parity.py +++ b/tools/test_server_player_targets_parity.py @@ -12,7 +12,7 @@ of vanilla's protocol code) and records, step by step, the system chat each rece about it: game mode events, teleports, inventory slots, effects, its death (with the death message), the other players it is sent or loses and the levels it respawns into. Each player's lines in each step are compared exactly, in sorted order (the packets of one step may leave in another order within the tick), with the locator bar's -waypoints (one manager per level: a player in another level is untracked). What a death does besides its messages +waypoints as each step leaves them (one manager per level: a player in another level is untracked). What a death does besides its messages is left to its own harness. """ import hashlib @@ -83,6 +83,17 @@ DEATH_STEP = 'step=console-kill' STEP_SECONDS = 2.5 +def settled(lines): + """One player's lines of one step, in order, with the waypoint packets reduced to the last for each waypoint: + what the locator bar shows once the step is over. Arriving in a level, vanilla sends the same waypoint more + than once on the way there; the packet by packet order is test_locator_bar_parity's.""" + def waypoint(line): + parts = line.split(' ') + return parts[3] if len(parts) > 3 and parts[2] in ('track', 'untrack', 'update') else None + last = {waypoint(l): i for i, l in enumerate(lines) if waypoint(l)} + return [l for i, l in enumerate(lines) if not waypoint(l) or last[waypoint(l)] == i] + + def run_side(label, server_command, client_command, build, world): directory = build / label port = server_dir(directory, world) @@ -140,7 +151,7 @@ def run_side(label, server_command, client_command, build, world): steps.setdefault((who, step), []).append(line) order = {f'step={s}': i for i, (s, _, _) in enumerate(SCRIPT)} keys = sorted(steps, key=lambda k: (k[0], order.get(k[1], -1))) - return [l for k in keys for l in sorted(steps[k])], errors + return [l for k in keys for l in sorted(settled(steps[k]))], errors def main():