From 169be6374c43ede203f7b0eb97eeebc4b5f68fcc Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Wed, 21 Oct 2026 12:09:18 +0200 Subject: [PATCH] hurtlog keeps a LAN guest's hurts across a respawn A guest's body is rebuilt when it respawns, and its hurt and attack logs went with the old one: the control socket's hurtlog lost the hurts that killed it whenever the death and the respawn fell between two reads. The logs now pass to the new body, and a dead guest's are read too. Co-Authored-By: Claude Opus 5.5 (cherry picked from commit df9fa5f0185766f7a7338df5046200d1a2e67d22) --- crates/horizon-client/src/game/control.rs | 19 ++++++++++++------- crates/horizon-client/src/game/lan_actions.rs | 10 +++++++++- crates/horizon-client/src/lan/guest.rs | 8 ++++++++ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/crates/horizon-client/src/game/control.rs b/crates/horizon-client/src/game/control.rs index c6c0e2225..bb1728ad3 100644 --- a/crates/horizon-client/src/game/control.rs +++ b/crates/horizon-client/src/game/control.rs @@ -715,9 +715,12 @@ impl Game<'_> { /// The hurts and melee attacks each player logged since the last call /// (`PlayerMotion::hurt_log`, `attack_log`), taken out. fn control_hurt_log(&mut self) -> Value { - fn drain(name: &str, p: &mut horizon_client::motion::PlayerMotion) -> Value { - let hurts: Vec = p - .hurt_log + fn drain( + name: &str, + hurt_log: &mut Vec, + attack_log: &mut Vec, + ) -> Value { + let hurts: Vec = hurt_log .drain(..) .map(|r| { json!({ @@ -728,8 +731,7 @@ impl Game<'_> { }) }) .collect(); - let attacks: Vec = p - .attack_log + let attacks: Vec = attack_log .drain(..) .map(|r| { json!({ @@ -742,13 +744,16 @@ impl Game<'_> { } let mut players = Vec::new(); if let Some(p) = self.player.as_mut() { - players.push(drain("host", p)); + players.push(drain("host", &mut p.hurt_log, &mut p.attack_log)); } if let Some(host) = self.lan.as_mut() { for g in &mut host.hub.guests { let name = g.name.clone(); if let Some(m) = g.motion.as_mut() { - players.push(drain(&name, m)); + players.push(drain(&name, &mut m.hurt_log, &mut m.attack_log)); + } else if let Some((mut hurts, mut attacks)) = g.logs_kept.take() { + // Dead, not yet respawned: what its last body logged. + players.push(drain(&name, &mut hurts, &mut attacks)); } } } diff --git a/crates/horizon-client/src/game/lan_actions.rs b/crates/horizon-client/src/game/lan_actions.rs index af127f42a..34fb88be5 100644 --- a/crates/horizon-client/src/game/lan_actions.rs +++ b/crates/horizon-client/src/game/lan_actions.rs @@ -200,6 +200,11 @@ impl Game<'_> { host.hub.guests[i].position[2], ); host.hub.guests[i].motion = PlayerMotion::new(self.motion, p).ok().map(Box::new); + let kept = host.hub.guests[i].logs_kept.take(); + if let (Some(m), Some((hurts, attacks))) = (host.hub.guests[i].motion.as_mut(), kept) { + m.hurt_log = hurts; + m.attack_log = attacks; + } } let mut play = host.play.remove(&conn).unwrap_or_default(); let g = &mut host.hub.guests[i]; @@ -1336,7 +1341,10 @@ impl Game<'_> { g.food = 20; g.saturation = 5.0; g.sent_health = None; - g.motion = None; + if let Some(m) = g.motion.take() { + let m = *m; + g.logs_kept = Some((m.hurt_log, m.attack_log)); + } let mut xp = Experience { level: g.xp_level, progress: g.xp_progress, diff --git a/crates/horizon-client/src/lan/guest.rs b/crates/horizon-client/src/lan/guest.rs index 91bf2709f..f46e37abc 100644 --- a/crates/horizon-client/src/lan/guest.rs +++ b/crates/horizon-client/src/lan/guest.rs @@ -122,6 +122,13 @@ pub struct Guest { pub tracker: Tracker, // Player state the gameplay code reads and writes. pub motion: Option>, + /// The hurt and attack logs of the body it had before it respawned, + /// until the new body takes them over (the control socket's `hurtlog` + /// reads across a death). + pub logs_kept: Option<( + Vec, + Vec, + )>, /// The 36 inventory slots (hotbar first), armor (head..feet) and off hand. pub inventory: Vec>, pub armor: [Option; 4], @@ -251,6 +258,7 @@ impl Guest { batch_quota: 0.0, tracker: Tracker::default(), motion: None, + logs_kept: None, inventory: vec![None; 36], armor: [None, None, None, None], offhand: None,