From 985ecf3922dde3f421eafbce28538e610f6fed66 Mon Sep 17 00:00:00 2001 From: Ryan Date: Sat, 2 Jul 2022 16:23:58 -0700 Subject: [PATCH] Don't send untranslated error messages to clients --- examples/conway.rs | 2 +- src/client.rs | 24 ++++++++++++++++-------- src/player_list.rs | 2 +- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/examples/conway.rs b/examples/conway.rs index b850b86..51f9891 100644 --- a/examples/conway.rs +++ b/examples/conway.rs @@ -163,7 +163,7 @@ impl Config for Game { } Event::Movement { position, .. } => { if position.y <= 0.0 { - client.teleport(spawn_pos, client.pitch(), client.yaw()); + client.teleport(spawn_pos, client.yaw(), client.pitch()); } } _ => {} diff --git a/src/client.rs b/src/client.rs index 232b4c5..d0e592e 100644 --- a/src/client.rs +++ b/src/client.rs @@ -328,7 +328,7 @@ impl Client { pub fn disconnect_no_reason(&mut self) { if self.send.is_some() { - log::info!("disconnecting client '{}' (no reason)", self.username); + log::info!("disconnecting client '{}'", self.username); self.send = None; } } @@ -456,12 +456,16 @@ impl Client { C2sPlayPacket::KeepAlive(p) => { let last_keepalive_id = self.last_keepalive_id; if self.got_keepalive { - self.disconnect("Unexpected keepalive"); + log::warn!("unexpected keepalive from player {}", self.username()); + self.disconnect_no_reason(); } else if p.id != last_keepalive_id { - self.disconnect(format!( - "Keepalive ids don't match (expected {}, got {})", - last_keepalive_id, p.id - )); + log::warn!( + "keepalive ids for player {} don't match (expected {}, got {})", + self.username(), + last_keepalive_id, + p.id + ); + self.disconnect_no_reason(); } else { self.got_keepalive = true; } @@ -610,7 +614,7 @@ impl Client { }); } - meta.player_list().packets(|pkt| self.send_packet(pkt)); + meta.player_list().diff_packets(|pkt| self.send_packet(pkt)); } // Update the players spawn position (compass position) @@ -641,7 +645,11 @@ impl Client { self.last_keepalive_id = id; self.got_keepalive = false; } else { - self.disconnect("Timed out (no keepalive response)"); + log::warn!( + "player {} timed out (no keepalive response)", + self.username() + ); + self.disconnect_no_reason(); } } diff --git a/src/player_list.rs b/src/player_list.rs index 6a1f934..b25b968 100644 --- a/src/player_list.rs +++ b/src/player_list.rs @@ -157,7 +157,7 @@ impl PlayerList { } } - pub(crate) fn packets(&self, mut packet: impl FnMut(S2cPlayPacket)) { + pub(crate) fn diff_packets(&self, mut packet: impl FnMut(S2cPlayPacket)) { if !self.removed.is_empty() { packet(PlayerInfo::RemovePlayer(self.removed.iter().cloned().collect()).into()); }