From 2bebcd6551b3a0b2c725f0b5fa5801dcf2523dba Mon Sep 17 00:00:00 2001 From: stale Date: Fri, 13 May 2022 23:11:51 -0300 Subject: fix logging off --- src/conn.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/conn.rs') diff --git a/src/conn.rs b/src/conn.rs index 01bc1e8..9c23592 100644 --- a/src/conn.rs +++ b/src/conn.rs @@ -72,13 +72,16 @@ pub async fn lobby(socket: WebSocket, addr: SocketAddr, room: Arc>) let room_lock = room.read().await; let mut players = room_lock.players.write().await; - let disconn_p = players.remove(&addr); - for p in players.values() { - if let Err(e) = p.conn.tx.send(Message::text("logoff {disconn_p.seqid} {disconn_p.name}")) { - println!("couldn't deliver logoff info to {}: {}", p, e); + if let Some(disconn_p) = players.remove(&addr) { + for p in players.values() { + if let Err(e) = p.conn.tx.send(Message::text(format!("logoff {}", disconn_p.uid))) { + println!("couldn't deliver logoff info to {}: {}", p, e); + } } + println!("{disconn_p} disconnected"); + } else { + println!("{addr} disconnected"); } - println!("{} disconnected", if let Some(p) = disconn_p { p.to_string() } else { addr.to_string() }); } pub async fn handle_room(mut incoming: SplitStream, addr: SocketAddr, room: Arc>) { -- cgit v1.2.3