check that name is valid per name requirements

master
rasul 5 years ago
parent 70ebf1a210
commit b9156b0300

@ -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) {
PlayerCheck::Ok(name) => {
match self.db.find_player_by_name(&name) {
Ok(Some(_)) => { Ok(Some(_)) => {
send_queue.push(token, "\nPassword: ", false, None); send_queue.push(token, "\nPassword: ", false, None);
client.state = State::Login(Login::Password(message)); client.state = State::Login(Login::Password(name));
} }
Ok(None) => { Ok(None) => {
send_queue.push( send_queue.push(
token, token,
format!("\nCreate {}? [y/N]: ", message.clone()), format!("\nCreate {}? [y/N]: ", name),
false, false,
None, None,
); );
client.state = State::Login(Login::CreateUser(message)); client.state = State::Login(Login::CreateUser(name));
} }
Err(_) => { Err(_) => {
send_queue.push(token, "\nError\n\nUsername: ", false, None); 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);
},
};
} }
} }

Loading…
Cancel
Save