aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-03-27 21:28:08 +0000
committermat <git@matdoes.dev>2025-03-27 21:28:13 +0000
commit02de98240f3642019b1c8104b00bc4a9d6d17e71 (patch)
tree1fd7074164a9cb1eb6d1012e4662cef61f10891d /azalea-client/src
parent37cde3ad3245675c54e70a4ded362f2a60f0d8a4 (diff)
downloadazalea-drasl-02de98240f3642019b1c8104b00bc4a9d6d17e71.tar.xz
fix not replying to ping packets in config state
Diffstat (limited to 'azalea-client/src')
-rw-r--r--azalea-client/src/plugins/packet/config/events.rs41
-rw-r--r--azalea-client/src/plugins/packet/mod.rs1
2 files changed, 26 insertions, 16 deletions
diff --git a/azalea-client/src/plugins/packet/config/events.rs b/azalea-client/src/plugins/packet/config/events.rs
index d0a7f3be..24a1157b 100644
--- a/azalea-client/src/plugins/packet/config/events.rs
+++ b/azalea-client/src/plugins/packet/config/events.rs
@@ -22,7 +22,7 @@ pub struct ReceiveConfigPacketEvent {
/// An event for sending a packet to the server while we're in the
/// `configuration` state.
-#[derive(Event)]
+#[derive(Event, Clone)]
pub struct SendConfigPacketEvent {
pub sent_by: Entity,
pub packet: ServerboundConfigPacket,
@@ -34,26 +34,35 @@ impl SendConfigPacketEvent {
}
}
-pub fn handle_outgoing_packets(
- mut send_packet_events: EventReader<SendConfigPacketEvent>,
+pub fn handle_outgoing_packets_observer(
+ trigger: Trigger<SendConfigPacketEvent>,
mut query: Query<(&mut RawConnection, Option<&InConfigState>)>,
) {
- for event in send_packet_events.read() {
- if let Ok((raw_conn, in_configuration_state)) = query.get_mut(event.sent_by) {
- if in_configuration_state.is_none() {
- error!(
- "Tried to send a configuration packet {:?} while not in configuration state",
- event.packet
- );
- continue;
- }
- debug!("Sending packet: {:?}", event.packet);
- if let Err(e) = raw_conn.write_packet(event.packet.clone()) {
- error!("Failed to send packet: {e}");
- }
+ let event = trigger.event();
+ if let Ok((raw_conn, in_configuration_state)) = query.get_mut(event.sent_by) {
+ if in_configuration_state.is_none() {
+ error!(
+ "Tried to send a configuration packet {:?} while not in configuration state",
+ event.packet
+ );
+ return;
+ }
+ debug!("Sending packet: {:?}", event.packet);
+ if let Err(e) = raw_conn.write_packet(event.packet.clone()) {
+ error!("Failed to send packet: {e}");
}
}
}
+/// A system that converts [`SendConfigPacketEvent`] events into triggers so
+/// they get received by [`handle_outgoing_packets_observer`].
+pub fn handle_outgoing_packets(
+ mut commands: Commands,
+ mut events: EventReader<SendConfigPacketEvent>,
+) {
+ for event in events.read() {
+ commands.trigger(event.clone());
+ }
+}
pub fn emit_receive_config_packet_events(
query: Query<(Entity, &RawConnection), With<InConfigState>>,
diff --git a/azalea-client/src/plugins/packet/mod.rs b/azalea-client/src/plugins/packet/mod.rs
index 826cd5cf..05f64e19 100644
--- a/azalea-client/src/plugins/packet/mod.rs
+++ b/azalea-client/src/plugins/packet/mod.rs
@@ -55,6 +55,7 @@ impl Plugin for PacketPlugin {
),
)
.add_observer(game::handle_outgoing_packets_observer)
+ .add_observer(config::handle_outgoing_packets_observer)
.add_systems(
Update,
(