From 42c79043cf44bd462cbde79f9e87503520daebd7 Mon Sep 17 00:00:00 2001 From: mat Date: Fri, 7 Mar 2025 19:11:24 +0000 Subject: [PATCH] don't send game packets when outside of the game state --- azalea-client/src/plugins/packet/game/events.rs | 12 ++++++++++-- azalea-client/src/plugins/packet/game/mod.rs | 4 +++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/azalea-client/src/plugins/packet/game/events.rs b/azalea-client/src/plugins/packet/game/events.rs index e5c87971..5ba9972d 100644 --- a/azalea-client/src/plugins/packet/game/events.rs +++ b/azalea-client/src/plugins/packet/game/events.rs @@ -63,10 +63,18 @@ impl SendPacketEvent { pub fn handle_outgoing_packets( mut send_packet_events: EventReader, - mut query: Query<&mut RawConnection>, + mut query: Query<(&mut RawConnection, Option<&InGameState>)>, ) { for event in send_packet_events.read() { - if let Ok(raw_connection) = query.get_mut(event.sent_by) { + if let Ok((raw_connection, in_game_state)) = query.get_mut(event.sent_by) { + if in_game_state.is_none() { + error!( + "Tried to send a game packet {:?} while not in game state", + event.packet + ); + continue; + } + // debug!("Sending packet: {:?}", event.packet); if let Err(e) = raw_connection.write_packet(event.packet.clone()) { error!("Failed to send packet: {e}"); diff --git a/azalea-client/src/plugins/packet/game/mod.rs b/azalea-client/src/plugins/packet/game/mod.rs index a13f1490..a715a77e 100644 --- a/azalea-client/src/plugins/packet/game/mod.rs +++ b/azalea-client/src/plugins/packet/game/mod.rs @@ -1503,10 +1503,12 @@ impl GamePacketHandler<'_> { } pub fn start_configuration(&mut self, _p: &ClientboundStartConfiguration) { + debug!("Got start configuration packet"); + as_system::<(Commands, EventWriter<_>)>(self.ecs, |(mut commands, mut events)| { events.send(SendPacketEvent::new( self.player, - ServerboundConfigurationAcknowledged {}, + ServerboundConfigurationAcknowledged, )); commands