diff --git a/src/player.rs b/src/player.rs index cdb6766..812bb3e 100644 --- a/src/player.rs +++ b/src/player.rs @@ -13,7 +13,7 @@ use crate::{ packet::{ rw::{read_packet, write_packet}, ConnectionKind, Packet, PacketData, - PacketData_variants::{Connect, HolePunch, Init, UdpInit}, + PacketData_variants::{Connect, Disconnect, HolePunch, Init, UdpInit}, CLIENT_NAME_SIZE, }, protocol::String, @@ -113,7 +113,7 @@ impl PlayerActor { match message { WriteMessage::Data(Packet { user_id, udp, data }) => { // trace!("writing packet {udp:?}, {data:?}"); - let res = if udp { + let res = if udp && addr.is_some() { async { let Some(addr) = addr else { trace!("no address set yet"); @@ -180,7 +180,7 @@ impl PlayerActor { connection_kind: connect.kind, name: connect.client_name, write_sender: sender, - udp_port + udp_port, }, ) .instrument(span) @@ -214,7 +214,14 @@ impl Actor for PlayerActor { Ok(()) } - async fn stopped(self) -> Self::Stop {} + async fn stopped(self) -> Self::Stop { + broadcast_packet(Packet { + user_id: self.id, + udp: false, + data: PacketData::Disconnect(Disconnect), + }) + .await; + } } struct StopError; impl Handler for PlayerActor {