pass quit state back when player quits, and check for that to close the connection

master
rasul 5 years ago
parent acc6f26df5
commit 0547792265

@ -3,9 +3,10 @@ use mio::Token;
use crate::command::Command; use crate::command::Command;
use crate::database::Db; use crate::database::Db;
use crate::queue::SendQueue; use crate::queue::SendQueue;
use crate::state::State;
impl Command { impl Command {
pub fn dispatch_quit(&self, _: String, token: Token, _: &mut Db) -> SendQueue { pub fn dispatch_quit(&self, _: String, token: Token, _: &mut Db) -> SendQueue {
SendQueue(vec![(token, "Goodbye\n\n".into(), false, None)].into()) SendQueue(vec![(token, "Goodbye\n\n".into(), false, Some(State::Quit))].into())
} }
} }

@ -1,6 +1,7 @@
use crate::game::Game; use crate::game::Game;
use crate::queue::SendQueue; use crate::queue::SendQueue;
use crate::result::RudeResult; use crate::result::RudeResult;
use crate::state::State;
use crate::try_log; use crate::try_log;
impl Game { impl Game {
@ -36,12 +37,13 @@ impl Game {
client.send_with_prompt(message); client.send_with_prompt(message);
} else { } else {
client.send_without_prompt(&message); client.send_without_prompt(&message);
if message == "Goodbye\n\n".to_string() { }
let _ = client.close();
log::info!("Disconnect from {}", client); if state == Some(State::Quit) {
self.clients.remove(&token); let _ = client.close();
self.tokens.push_back(token); log::info!("Disconnect from {}", client);
} self.clients.remove(&token);
self.tokens.push_back(token);
} }
} }

@ -26,7 +26,7 @@ impl Game {
let mut queue = self.login(token, message, login_state); let mut queue = self.login(token, message, login_state);
send_queue.append(&mut queue); send_queue.append(&mut queue);
} }
State::Action => { State::Action | State::Quit => {
let mut queue = self.action(token, message); let mut queue = self.action(token, message);
send_queue.append(&mut queue); send_queue.append(&mut queue);
} }

Loading…
Cancel
Save