diff options
| author | mat <github@matdoes.dev> | 2023-02-12 22:56:20 -0600 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2023-02-12 22:56:20 -0600 |
| commit | 1b3d6f9581689e9caa0e2dd14dcf48c20fb06ed7 (patch) | |
| tree | 0fbc933e220ffd9d3a848c12c38d1889fcec39a6 /azalea-client/src/packet_handling.rs | |
| parent | 913f17299b85fb58c5c463a3dc4db8eb7e2d9f76 (diff) | |
| download | azalea-drasl-1b3d6f9581689e9caa0e2dd14dcf48c20fb06ed7.tar.xz | |
DisconnectEvent
Diffstat (limited to 'azalea-client/src/packet_handling.rs')
| -rw-r--r-- | azalea-client/src/packet_handling.rs | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/azalea-client/src/packet_handling.rs b/azalea-client/src/packet_handling.rs index 1dcf3c06..516c6784 100644 --- a/azalea-client/src/packet_handling.rs +++ b/azalea-client/src/packet_handling.rs @@ -38,6 +38,7 @@ use tokio::sync::mpsc; use crate::{ chat::{ChatPacket, ChatReceivedEvent}, + disconnect::DisconnectEvent, local_player::{GameProfileComponent, LocalPlayer}, ClientInformation, PlayerInfo, }; @@ -286,10 +287,14 @@ fn handle_packets(ecs: &mut Ecs) { } ClientboundGamePacket::Disconnect(p) => { debug!("Got disconnect packet {:?}", p); - let mut system_state: SystemState<Query<&LocalPlayer>> = SystemState::new(ecs); - let query = system_state.get(ecs); - let local_player = query.get(player_entity).unwrap(); - local_player.disconnect(); + let mut system_state: SystemState<EventWriter<DisconnectEvent>> = + SystemState::new(ecs); + let mut disconnect_events = system_state.get_mut(ecs); + disconnect_events.send(DisconnectEvent { + entity: player_entity, + }); + // bye + return; } ClientboundGamePacket::UpdateRecipes(_p) => { debug!("Got update recipes packet"); @@ -950,10 +955,14 @@ impl PacketReceiver { if !matches!(*error, ReadPacketError::ConnectionClosed) { error!("Error reading packet from Client: {error:?}"); } - return; + break; } } } + // TODO: it should send a DisconnectEvent here somehow + // maybe use a tokio::sync::oneshot that tells it to close and have the + // receiver in localplayer and have a system that watches that or + // something? } /// Consume the [`ServerboundGamePacket`] queue and actually write the @@ -970,6 +979,7 @@ impl PacketReceiver { break; }; } + println!("Write task finished"); // receiver is automatically closed when it's dropped } } |
