diff options
-rw-r--r-- | page.html | 2 | ||||
-rw-r--r-- | src/conn.rs | 13 |
2 files changed, 9 insertions, 6 deletions
@@ -121,7 +121,7 @@ info_elem.onclick = e => { s.send("reset") }; } break; case "logoff": { - let oid = fields[1]; + let oid = Number(fields[1]); cursors.get(oid).elem.remove(); cursors.get(oid).selwin.remove(); cursors.delete(oid); 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>>) { |