diff options
-rw-r--r-- | game_server/src/scribble_group.rs | 12 | ||||
-rw-r--r-- | game_server/src/ws_test.html | 2 |
2 files changed, 10 insertions, 4 deletions
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 @@ <div id='cons'>connected</div><br> <button onclick='test_connection()'>Launch</button><br> <span>Server address: </span><input id='addr'></input> - <span>Message</span><input id='msg'></input><button onclick='send_text()'>Send</button> + <span>Message</span><input id='msg'></input> <button onclick='send_text()'>Send</button> <div id='chat' style='background: rgb(20, 20, 20); padding-left: 20px; margin: 40px' /> </body> <script> |