|
|
|
@ -83,15 +83,27 @@ impl Game {
|
|
|
|
|
} else {
|
|
|
|
|
match self.check_player_password(message) {
|
|
|
|
|
PlayerCheck::Ok(pass) => {
|
|
|
|
|
send_queue.push(
|
|
|
|
|
match Password::new(pass) {
|
|
|
|
|
Ok(password) => send_queue.push(
|
|
|
|
|
token,
|
|
|
|
|
"\nNew password again: ",
|
|
|
|
|
false,
|
|
|
|
|
Some(State::Login(Login::CreatePassword2((
|
|
|
|
|
username.to_owned(),
|
|
|
|
|
Password::new(pass),
|
|
|
|
|
password,
|
|
|
|
|
)))),
|
|
|
|
|
),
|
|
|
|
|
Err(e) => {
|
|
|
|
|
log_error!("Hash error checking password :: {}", e);
|
|
|
|
|
send_queue.push(token, "\nError\n", false, None);
|
|
|
|
|
send_queue.push(
|
|
|
|
|
token,
|
|
|
|
|
"\n\nUsername: ",
|
|
|
|
|
false,
|
|
|
|
|
Some(State::Login(Login::Username)),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
PlayerCheck::Err(err) => {
|
|
|
|
|
send_queue.push(token, "\nInvalid password:\n", false, None);
|
|
|
|
@ -105,15 +117,8 @@ impl Game {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Login::CreatePassword2((username, pass)) => {
|
|
|
|
|
if !pass.check(message) {
|
|
|
|
|
send_queue.push(token, "\n\nPasswords don't match", false, None);
|
|
|
|
|
send_queue.push(
|
|
|
|
|
token,
|
|
|
|
|
"\n\nUsername: ",
|
|
|
|
|
false,
|
|
|
|
|
Some(State::Login(Login::Username)),
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
match pass.check(message) {
|
|
|
|
|
Ok(true) => {
|
|
|
|
|
if let Ok(id) = self.db.new_player_id() {
|
|
|
|
|
let player = Player {
|
|
|
|
|
id,
|
|
|
|
@ -145,8 +150,22 @@ impl Game {
|
|
|
|
|
} else {
|
|
|
|
|
send_queue.push(token, "Error", true, None);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
Ok(false) => {
|
|
|
|
|
send_queue.push(token, "\n\nPasswords don't match", false, None);
|
|
|
|
|
send_queue.push(
|
|
|
|
|
token,
|
|
|
|
|
"\n\nUsername: ",
|
|
|
|
|
false,
|
|
|
|
|
Some(State::Login(Login::Username)),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
Err(e) => {
|
|
|
|
|
log_error!("Error creating password :: {}", e);
|
|
|
|
|
send_queue.push(token, "\nError\n\n", false, None);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
Login::Password(username) => {
|
|
|
|
|
if message.is_empty() {
|
|
|
|
@ -160,7 +179,8 @@ impl Game {
|
|
|
|
|
match self.db.find_player_by_name(username) {
|
|
|
|
|
Ok(Some(player)) => match self.db.get_password(player.id) {
|
|
|
|
|
Ok(Some(password)) => {
|
|
|
|
|
if password.check(message) {
|
|
|
|
|
match password.check(message) {
|
|
|
|
|
Ok(true) => {
|
|
|
|
|
if self.db.save_connected_player(token, &player).is_ok() {
|
|
|
|
|
send_queue.push(
|
|
|
|
|
token,
|
|
|
|
@ -184,7 +204,8 @@ impl Game {
|
|
|
|
|
Some(State::Login(Login::Username)),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
Ok(false) => {
|
|
|
|
|
send_queue.push(token, "Incorrect password\n", false, None);
|
|
|
|
|
send_queue.push(
|
|
|
|
|
token,
|
|
|
|
@ -193,6 +214,11 @@ impl Game {
|
|
|
|
|
Some(State::Login(Login::Username)),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
Err(e) => {
|
|
|
|
|
log_error!("Error creating password :: {}", e);
|
|
|
|
|
send_queue.push(token, "\nError\n\n", false, None);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Ok(None) => {
|
|
|
|
|
log_error!("Player has no password: {}", player.id);
|
|
|
|
|