From 368b018f567a804cf02e3fea4246a5c082f8c616 Mon Sep 17 00:00:00 2001 From: natrixaeria Date: Mon, 20 May 2019 20:04:35 +0200 Subject: Remove users from server, if not reachable --- game_server/src/scribble_group.rs | 12 +++++++++--- game_server/src/ws_test.html | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'game_server') diff --git a/game_server/src/scribble_group.rs b/game_server/src/scribble_group.rs index e68c6df..01090de 100644 --- a/game_server/src/scribble_group.rs +++ b/game_server/src/scribble_group.rs @@ -35,15 +35,21 @@ impl Group for ScribbleGroup { let self_uid = id; std::thread::spawn(move || { loop { - let message = rec.recv_message().unwrap(); - info!("got message: '{:?}'", message); + let message = match rec.recv_message() { + Ok(x) => x, + _ => break + }; + //trace!("got message: '{:?}'", message); let mut senders = senders_mutex.lock().unwrap(); for (uid, sender) in senders.iter_mut() { if self_uid != *uid { - sender.send_message(&message); + sender.send_message(&message) + .unwrap_or_else(|_| debug!("tried to send message to {}, but failed", *uid)); } } } + senders_mutex.lock().unwrap().remove(&self_uid); + info!("client {} has left", self_uid); }); } } diff --git a/game_server/src/ws_test.html b/game_server/src/ws_test.html index ee60b65..44b6eb0 100644 --- a/game_server/src/ws_test.html +++ b/game_server/src/ws_test.html @@ -12,7 +12,7 @@
connected


Server address: - Message + Message