From 53e67fcd1fc1ca15da30562ca76a70f92117cd5f Mon Sep 17 00:00:00 2001 From: rasul Date: Wed, 8 Apr 2020 12:55:47 -0500 Subject: [PATCH] handle state changes --- src/game/iter_once.rs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/game/iter_once.rs b/src/game/iter_once.rs index 85ade39..d372396 100644 --- a/src/game/iter_once.rs +++ b/src/game/iter_once.rs @@ -25,7 +25,7 @@ impl Game { // send everything in the send queue while let Some((token, message, prompt, state)) = send_queue.pop() { // get the client - let client = if let Some(client) = self.clients.get_mut(&token) { + let mut client = if let Some(client) = self.clients.remove(&token) { client } else { // no client, so put the token back and move on @@ -39,12 +39,21 @@ impl Game { client.send_without_prompt(&message); } - if state == Some(State::Quit) { - let _ = client.close(); - log::info!("Disconnect from {}", client); - self.clients.remove(&token); - let _ = self.db.remove_connected_player(token); - self.tokens.push_back(token); + match state { + Some(State::Quit) => { + let _ = client.close(); + log::info!("Disconnect from {}", client); + self.clients.remove(&token); + let _ = self.db.remove_connected_player(token); + self.tokens.push_back(token); + } + Some(state) => { + client.state = state; + self.clients.insert(token, client); + } + _ => { + let _ = self.clients.insert(token, client); + } } }