|
|
|
@ -103,7 +103,7 @@ impl Game {
|
|
|
|
|
false,
|
|
|
|
|
Some(State::Login(Login::Username)),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
check::PlayerCheck::Err(err) => {
|
|
|
|
@ -117,55 +117,53 @@ impl Game {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Login::CreatePassword2((username, pass)) => {
|
|
|
|
|
match pass.check(message) {
|
|
|
|
|
Ok(true) => {
|
|
|
|
|
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(),
|
|
|
|
|
};
|
|
|
|
|
Login::CreatePassword2((username, pass)) => match pass.check(message) {
|
|
|
|
|
Ok(true) => {
|
|
|
|
|
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()
|
|
|
|
|
&& self.db.save_password(player.id, pass).is_ok()
|
|
|
|
|
{
|
|
|
|
|
send_queue.push(
|
|
|
|
|
token,
|
|
|
|
|
format!("Welcome, {}\n", username),
|
|
|
|
|
false,
|
|
|
|
|
Some(State::Action),
|
|
|
|
|
);
|
|
|
|
|
send_queue.push(token, "", true, None);
|
|
|
|
|
if self.db.single_save_player(token, &player).is_ok()
|
|
|
|
|
&& self.db.save_password(player.id, pass).is_ok()
|
|
|
|
|
{
|
|
|
|
|
send_queue.push(
|
|
|
|
|
token,
|
|
|
|
|
format!("Welcome, {}\n", username),
|
|
|
|
|
false,
|
|
|
|
|
Some(State::Action),
|
|
|
|
|
);
|
|
|
|
|
send_queue.push(token, "", true, None);
|
|
|
|
|
|
|
|
|
|
send_queue.append(&mut Command::dispatch_look(
|
|
|
|
|
&Command::default(),
|
|
|
|
|
String::new(),
|
|
|
|
|
token,
|
|
|
|
|
&mut self.db,
|
|
|
|
|
));
|
|
|
|
|
} else {
|
|
|
|
|
send_queue.push(token, "Error", true, None);
|
|
|
|
|
}
|
|
|
|
|
send_queue.append(&mut Command::dispatch_look(
|
|
|
|
|
&Command::default(),
|
|
|
|
|
String::new(),
|
|
|
|
|
token,
|
|
|
|
|
&mut self.db,
|
|
|
|
|
));
|
|
|
|
|
} 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);
|
|
|
|
|
} 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) => {
|
|
|
|
@ -179,35 +177,24 @@ impl Game {
|
|
|
|
|
} else {
|
|
|
|
|
match self.db.find_player_by_name(username) {
|
|
|
|
|
Ok(Some(player)) => match self.db.get_password(player.id) {
|
|
|
|
|
Ok(Some(password)) => {
|
|
|
|
|
match password.check(message) {
|
|
|
|
|
Ok(true) => {
|
|
|
|
|
if self.db.save_connected_player(token, &player).is_ok() {
|
|
|
|
|
send_queue.push(
|
|
|
|
|
token,
|
|
|
|
|
format!("Welcome back, {}\n\n", username),
|
|
|
|
|
false,
|
|
|
|
|
Some(State::Action),
|
|
|
|
|
);
|
|
|
|
|
Ok(Some(password)) => match password.check(message) {
|
|
|
|
|
Ok(true) => {
|
|
|
|
|
if self.db.save_connected_player(token, &player).is_ok() {
|
|
|
|
|
send_queue.push(
|
|
|
|
|
token,
|
|
|
|
|
format!("Welcome back, {}\n\n", username),
|
|
|
|
|
false,
|
|
|
|
|
Some(State::Action),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
send_queue.append(&mut Command::dispatch_look(
|
|
|
|
|
&Command::default(),
|
|
|
|
|
String::new(),
|
|
|
|
|
token,
|
|
|
|
|
&mut self.db,
|
|
|
|
|
));
|
|
|
|
|
} else {
|
|
|
|
|
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.append(&mut Command::dispatch_look(
|
|
|
|
|
&Command::default(),
|
|
|
|
|
String::new(),
|
|
|
|
|
token,
|
|
|
|
|
&mut self.db,
|
|
|
|
|
));
|
|
|
|
|
} else {
|
|
|
|
|
send_queue.push(token, "Unable to login\n", false, None);
|
|
|
|
|
send_queue.push(
|
|
|
|
|
token,
|
|
|
|
|
"\n\nUsername: ",
|
|
|
|
@ -215,12 +202,21 @@ 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(false) => {
|
|
|
|
|
send_queue.push(token, "Incorrect password\n", 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);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
Ok(None) => {
|
|
|
|
|
log_error!("Player has no password: {}", player.id);
|
|
|
|
|
send_queue.push(token, "Error\n", false, None);
|
|
|
|
|