diff options
author | stale <redkugelblitzin@gmail.com> | 2022-05-13 23:11:51 -0300 |
---|---|---|
committer | stale <redkugelblitzin@gmail.com> | 2022-05-13 23:11:51 -0300 |
commit | 2bebcd6551b3a0b2c725f0b5fa5801dcf2523dba (patch) | |
tree | 698c95c8122bbc17720fd14edaadde88817cde30 /src/conn.rs | |
parent | dc8aee27c6670683f3daa5471c23a249ce10fcd5 (diff) |
fix logging off
Diffstat (limited to 'src/conn.rs')
-rw-r--r-- | src/conn.rs | 13 |
1 files changed, 8 insertions, 5 deletions
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<RwLock<Room>>) 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<WebSocket>, addr: SocketAddr, room: Arc<RwLock<Room>>) { |