diff options
author | Dennis Kobert <d-kobert@web.de> | 2019-05-21 00:46:33 +0200 |
---|---|---|
committer | Dennis Kobert <d-kobert@web.de> | 2019-05-21 00:46:33 +0200 |
commit | 24ea877322054db328069126fbd540bc1ce2d7eb (patch) | |
tree | 6e4fb888918fd760adea71427cfc663daf802135 /game_server | |
parent | b7e6649f321f7560fa16b88674c64a98009cbcf2 (diff) | |
parent | fa9b24f80c4fd4ca05a7b7aa3a4122d874136274 (diff) |
erge branch 'scribble' of github.com:TrueDoctor/DiscoBot into scribble
Diffstat (limited to 'game_server')
-rw-r--r-- | game_server/src/scribble_group.rs | 12 | ||||
-rw-r--r-- | game_server/src/ws_test.html | 8 |
2 files changed, 14 insertions, 6 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..3b3d4ce 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> + <div align='right'><span>Message</span><input id='msg'></input> <button onclick='send_text()'>Send</button></div> <div id='chat' style='background: rgb(20, 20, 20); padding-left: 20px; margin: 40px' /> </body> <script> @@ -39,12 +39,14 @@ function test_connection() { toggle_connected(false); }); ws.addEventListener('message', function (event) { - add_text('got ws message: ' + event.data); + add_text('got ws message: "' + event.data + '"'); }); } function send_text() { - ws.send(document.getElementById('msg').value); + let msg = document.getElementById('msg').value; + ws.send(msg); + add_text('sent message: "' + msg + '"'); } function add_text(text, color='white') { |