|
|
@ -3,7 +3,7 @@ use log::warn;
|
|
|
|
use mio::Token;
|
|
|
|
use mio::Token;
|
|
|
|
|
|
|
|
|
|
|
|
use crate::command::Command;
|
|
|
|
use crate::command::Command;
|
|
|
|
use crate::game::Game;
|
|
|
|
use crate::game::{Game, PlayerCheck};
|
|
|
|
use crate::player::Player;
|
|
|
|
use crate::player::Player;
|
|
|
|
use crate::queue::SendQueue;
|
|
|
|
use crate::queue::SendQueue;
|
|
|
|
use crate::state::*;
|
|
|
|
use crate::state::*;
|
|
|
@ -26,24 +26,35 @@ impl Game {
|
|
|
|
if message.is_empty() {
|
|
|
|
if message.is_empty() {
|
|
|
|
send_queue.push(token, "\n\nUsername: ", false, None);
|
|
|
|
send_queue.push(token, "\n\nUsername: ", false, None);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
match self.db.find_player_by_name(&message) {
|
|
|
|
match self.check_player_name(message) {
|
|
|
|
Ok(Some(_)) => {
|
|
|
|
PlayerCheck::Ok(name) => {
|
|
|
|
send_queue.push(token, "\nPassword: ", false, None);
|
|
|
|
match self.db.find_player_by_name(&name) {
|
|
|
|
client.state = State::Login(Login::Password(message));
|
|
|
|
Ok(Some(_)) => {
|
|
|
|
}
|
|
|
|
send_queue.push(token, "\nPassword: ", false, None);
|
|
|
|
Ok(None) => {
|
|
|
|
client.state = State::Login(Login::Password(name));
|
|
|
|
send_queue.push(
|
|
|
|
}
|
|
|
|
token,
|
|
|
|
Ok(None) => {
|
|
|
|
format!("\nCreate {}? [y/N]: ", message.clone()),
|
|
|
|
send_queue.push(
|
|
|
|
false,
|
|
|
|
token,
|
|
|
|
None,
|
|
|
|
format!("\nCreate {}? [y/N]: ", name),
|
|
|
|
);
|
|
|
|
false,
|
|
|
|
client.state = State::Login(Login::CreateUser(message));
|
|
|
|
None,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
Err(_) => {
|
|
|
|
client.state = State::Login(Login::CreateUser(name));
|
|
|
|
send_queue.push(token, "\nError\n\nUsername: ", false, None);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(_) => {
|
|
|
|
}
|
|
|
|
send_queue.push(token, "\nError\n\nUsername: ", false, None);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
PlayerCheck::Err(err) => {
|
|
|
|
|
|
|
|
send_queue.push(token, "\nInvalid username:\n", false, None);
|
|
|
|
|
|
|
|
for line in err {
|
|
|
|
|
|
|
|
send_queue.push(token, format!("{}\n", line), false, None);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
send_queue.push(token, "\n\nUsername: ", false, None);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|