From 0253d9bc47f9debca046edd6b14be1f550900485 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 25 Oct 2026 01:23:59 +0200 Subject: [PATCH] Multiplayer: no play packets after the client acknowledges a reconfiguration A proxy switching servers (Velocity, BungeeCord) sends the client back to configuration. The network thread acknowledged it, but the game thread kept ticking the old level and its client_tick_end went out right after the acknowledgement, where the server reads it as configuration packet 13. Velocity drops the client: "A packet did not decode successfully", shown as "An internal error occurred in your connection". Vanilla's handleConfigurationStart clears the level before it acknowledges, so nothing of play follows. Session::send now drops play packets while the connection is in configuration, checked under the writer lock that the acknowledgement is sent with. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/net.rs | 67 +++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/crates/horizon-client/src/net.rs b/crates/horizon-client/src/net.rs index 31f9b9094..9cce9e1c6 100644 --- a/crates/horizon-client/src/net.rs +++ b/crates/horizon-client/src/net.rs @@ -147,7 +147,12 @@ impl Session { pub fn poll(&self) -> Vec { self.events.try_iter().collect() } - /// Send a play packet; silently dropped once the connection is gone. + /// Send a play packet; silently dropped once the connection is gone, + /// and while the server has the connection back in configuration (a + /// proxy switching servers). Vanilla's `handleConfigurationStart` clears + /// the level before it acknowledges, so no play packet follows the + /// acknowledgement; one that did would reach the server as a + /// configuration packet, and Velocity drops such a client. pub fn send(&self, packet: play::Serverbound) { if self.debug && !matches!( @@ -159,7 +164,11 @@ impl Session { { eprintln!("[net] -> {packet:?}"); } - if let Some(w) = self.writer.lock().unwrap().as_mut() + let mut writer = self.writer.lock().unwrap(); + if self.configuring.load(Ordering::Relaxed) { + return; + } + if let Some(w) = writer.as_mut() && w.send(&packet.encode()).is_err() { w.shutdown(); @@ -686,6 +695,60 @@ mod tests { assert!(thread.join().unwrap().is_err()); } + #[test] + fn play_packets_wait_out_a_reconfiguration() { + let (client, server) = horizon_protocol::connection::Pipe::pair(); + let (mut reader, writer) = Connection::local(client).split(); + let (send, events) = channel(); + let session = Session { + events, + writer: Arc::new(Mutex::new(Some(writer))), + configuring: Arc::new(AtomicBool::new(false)), + thread: None, + address: "local".into(), + name: "Player".into(), + counters: Arc::new(Mutex::new(None)), + debug: false, + }; + let (thread_writer, thread_configuring) = + (session.writer.clone(), session.configuring.clone()); + let thread = std::thread::spawn(move || { + receive_play( + &mut reader, + &thread_writer, + &thread_configuring, + &Language::new(), + &send, + ) + }); + let mut server = Connection::local(server); + let tick_end = play::Serverbound::ClientTickEnd(Empty); + server + .send(&play::Clientbound::StartConfiguration(Empty).encode()) + .unwrap(); + let (id, body) = server.recv().unwrap(); + assert_eq!( + play::Serverbound::decode(id, &body).unwrap(), + play::Serverbound::ConfigurationAcknowledged(Empty) + ); + // The game thread still ticks the old level: nothing of it goes out. + session.send(tick_end.clone()); + server + .send(&cfg::Clientbound::FinishConfiguration(Empty).encode()) + .unwrap(); + let (id, body) = server.recv().unwrap(); + assert_eq!( + cfg::Serverbound::decode(id, &body).unwrap(), + cfg::Serverbound::FinishConfiguration(Empty) + ); + // Back in play, the game's packets flow again. + session.send(tick_end.clone()); + let (id, body) = server.recv().unwrap(); + assert_eq!(play::Serverbound::decode(id, &body).unwrap(), tick_end); + drop(session); + assert!(thread.join().unwrap().is_err()); + } + #[test] fn server_brand_payload_is_decoded_and_invalid_or_unrelated_payloads_are_ignored() { let (send, events) = channel();