handle state changes

master
rasul 5 years ago
parent 85d1eeff70
commit 53e67fcd1f

@ -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,13 +39,22 @@ impl Game {
client.send_without_prompt(&message);
}
if state == Some(State::Quit) {
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);
}
}
}
Ok(true)

Loading…
Cancel
Save