handle state changes

master
rasul 5 years ago
parent 85d1eeff70
commit 53e67fcd1f

@ -25,7 +25,7 @@ impl Game {
// send everything in the send queue // send everything in the send queue
while let Some((token, message, prompt, state)) = send_queue.pop() { while let Some((token, message, prompt, state)) = send_queue.pop() {
// get the client // 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 client
} else { } else {
// no client, so put the token back and move on // no client, so put the token back and move on
@ -39,12 +39,21 @@ impl Game {
client.send_without_prompt(&message); client.send_without_prompt(&message);
} }
if state == Some(State::Quit) { match state {
let _ = client.close(); Some(State::Quit) => {
log::info!("Disconnect from {}", client); let _ = client.close();
self.clients.remove(&token); log::info!("Disconnect from {}", client);
let _ = self.db.remove_connected_player(token); self.clients.remove(&token);
self.tokens.push_back(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);
}
} }
} }

Loading…
Cancel
Save