|
|
@ -83,15 +83,27 @@ impl Game {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
match self.check_player_password(message) {
|
|
|
|
match self.check_player_password(message) {
|
|
|
|
PlayerCheck::Ok(pass) => {
|
|
|
|
PlayerCheck::Ok(pass) => {
|
|
|
|
send_queue.push(
|
|
|
|
match Password::new(pass) {
|
|
|
|
token,
|
|
|
|
Ok(password) => send_queue.push(
|
|
|
|
"\nNew password again: ",
|
|
|
|
token,
|
|
|
|
false,
|
|
|
|
"\nNew password again: ",
|
|
|
|
Some(State::Login(Login::CreatePassword2((
|
|
|
|
false,
|
|
|
|
username.to_owned(),
|
|
|
|
Some(State::Login(Login::CreatePassword2((
|
|
|
|
Password::new(pass),
|
|
|
|
username.to_owned(),
|
|
|
|
)))),
|
|
|
|
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) => {
|
|
|
|
PlayerCheck::Err(err) => {
|
|
|
|
send_queue.push(token, "\nInvalid password:\n", false, None);
|
|
|
|
send_queue.push(token, "\nInvalid password:\n", false, None);
|
|
|
@ -105,48 +117,55 @@ impl Game {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Login::CreatePassword2((username, pass)) => {
|
|
|
|
Login::CreatePassword2((username, pass)) => {
|
|
|
|
if !pass.check(message) {
|
|
|
|
match pass.check(message) {
|
|
|
|
send_queue.push(token, "\n\nPasswords don't match", false, None);
|
|
|
|
Ok(true) => {
|
|
|
|
send_queue.push(
|
|
|
|
if let Ok(id) = self.db.new_player_id() {
|
|
|
|
token,
|
|
|
|
let player = Player {
|
|
|
|
"\n\nUsername: ",
|
|
|
|
id,
|
|
|
|
false,
|
|
|
|
name: username.clone(),
|
|
|
|
Some(State::Login(Login::Username)),
|
|
|
|
created: Utc::now(),
|
|
|
|
);
|
|
|
|
location: self.config.player.starting_location.clone(),
|
|
|
|
} else {
|
|
|
|
};
|
|
|
|
if let Ok(id) = self.db.new_player_id() {
|
|
|
|
|
|
|
|
let player = Player {
|
|
|
|
|
|
|
|
id,
|
|
|
|
|
|
|
|
name: username.clone(),
|
|
|
|
|
|
|
|
created: Utc::now(),
|
|
|
|
|
|
|
|
location: self.config.player.starting_location.clone(),
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self.db.single_save_player(token, &player).is_ok()
|
|
|
|
if self.db.single_save_player(token, &player).is_ok()
|
|
|
|
&& self.db.save_password(player.id, pass).is_ok()
|
|
|
|
&& self.db.save_password(player.id, pass).is_ok()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
send_queue.push(
|
|
|
|
send_queue.push(
|
|
|
|
token,
|
|
|
|
token,
|
|
|
|
format!("Welcome, {}\n", username),
|
|
|
|
format!("Welcome, {}\n", username),
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
Some(State::Action),
|
|
|
|
Some(State::Action),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
send_queue.push(token, "", true, None);
|
|
|
|
send_queue.push(token, "", true, None);
|
|
|
|
|
|
|
|
|
|
|
|
send_queue.append(&mut Command::dispatch_look(
|
|
|
|
send_queue.append(&mut Command::dispatch_look(
|
|
|
|
&Command::default(),
|
|
|
|
&Command::default(),
|
|
|
|
String::new(),
|
|
|
|
String::new(),
|
|
|
|
token,
|
|
|
|
token,
|
|
|
|
&mut self.db,
|
|
|
|
&mut self.db,
|
|
|
|
));
|
|
|
|
));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
send_queue.push(token, "Error", true, None);
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
send_queue.push(token, "Error", true, None);
|
|
|
|
send_queue.push(token, "Error", true, None);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} 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) => {
|
|
|
|
Login::Password(username) => {
|
|
|
|
if message.is_empty() {
|
|
|
|
if message.is_empty() {
|
|
|
@ -160,23 +179,34 @@ impl Game {
|
|
|
|
match self.db.find_player_by_name(username) {
|
|
|
|
match self.db.find_player_by_name(username) {
|
|
|
|
Ok(Some(player)) => match self.db.get_password(player.id) {
|
|
|
|
Ok(Some(player)) => match self.db.get_password(player.id) {
|
|
|
|
Ok(Some(password)) => {
|
|
|
|
Ok(Some(password)) => {
|
|
|
|
if password.check(message) {
|
|
|
|
match password.check(message) {
|
|
|
|
if self.db.save_connected_player(token, &player).is_ok() {
|
|
|
|
Ok(true) => {
|
|
|
|
send_queue.push(
|
|
|
|
if self.db.save_connected_player(token, &player).is_ok() {
|
|
|
|
token,
|
|
|
|
send_queue.push(
|
|
|
|
format!("Welcome back, {}\n\n", username),
|
|
|
|
token,
|
|
|
|
false,
|
|
|
|
format!("Welcome back, {}\n\n", username),
|
|
|
|
Some(State::Action),
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
Some(State::Action),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
send_queue.append(&mut Command::dispatch_look(
|
|
|
|
send_queue.append(&mut Command::dispatch_look(
|
|
|
|
&Command::default(),
|
|
|
|
&Command::default(),
|
|
|
|
String::new(),
|
|
|
|
String::new(),
|
|
|
|
token,
|
|
|
|
token,
|
|
|
|
&mut self.db,
|
|
|
|
&mut self.db,
|
|
|
|
));
|
|
|
|
));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
send_queue.push(token, "Unable to login\n", false, None);
|
|
|
|
send_queue.push(token, "Unable to login\n", false, None);
|
|
|
|
|
|
|
|
send_queue.push(
|
|
|
|
|
|
|
|
token,
|
|
|
|
|
|
|
|
"\n\nUsername: ",
|
|
|
|
|
|
|
|
false,
|
|
|
|
|
|
|
|
Some(State::Login(Login::Username)),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(false) => {
|
|
|
|
|
|
|
|
send_queue.push(token, "Incorrect password\n", false, None);
|
|
|
|
send_queue.push(
|
|
|
|
send_queue.push(
|
|
|
|
token,
|
|
|
|
token,
|
|
|
|
"\n\nUsername: ",
|
|
|
|
"\n\nUsername: ",
|
|
|
@ -184,14 +214,10 @@ impl Game {
|
|
|
|
Some(State::Login(Login::Username)),
|
|
|
|
Some(State::Login(Login::Username)),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Err(e) => {
|
|
|
|
send_queue.push(token, "Incorrect password\n", false, None);
|
|
|
|
log_error!("Error creating password :: {}", e);
|
|
|
|
send_queue.push(
|
|
|
|
send_queue.push(token, "\nError\n\n", false, None);
|
|
|
|
token,
|
|
|
|
}
|
|
|
|
"\n\nUsername: ",
|
|
|
|
|
|
|
|
false,
|
|
|
|
|
|
|
|
Some(State::Login(Login::Username)),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(None) => {
|
|
|
|
Ok(None) => {
|
|
|
|