|
|
@ -24,11 +24,11 @@ impl Game {
|
|
|
|
// get the username
|
|
|
|
// get the username
|
|
|
|
Login::Username => {
|
|
|
|
Login::Username => {
|
|
|
|
if message.is_empty() {
|
|
|
|
if message.is_empty() {
|
|
|
|
send_queue.push(token, "\n\nUsername: ", false);
|
|
|
|
send_queue.push(token, "\n\nUsername: ", false, None);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
match self.db.find_player_by_name(&message) {
|
|
|
|
match self.db.find_player_by_name(&message) {
|
|
|
|
Ok(Some(_)) => {
|
|
|
|
Ok(Some(_)) => {
|
|
|
|
send_queue.push(token, "\nPassword: ", false);
|
|
|
|
send_queue.push(token, "\nPassword: ", false, None);
|
|
|
|
client.state = State::Login(Login::Password(message));
|
|
|
|
client.state = State::Login(Login::Password(message));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(None) => {
|
|
|
|
Ok(None) => {
|
|
|
@ -36,11 +36,12 @@ impl Game {
|
|
|
|
token,
|
|
|
|
token,
|
|
|
|
format!("\nCreate {}? [y/N]: ", message.clone()),
|
|
|
|
format!("\nCreate {}? [y/N]: ", message.clone()),
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
|
|
|
|
None,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
client.state = State::Login(Login::CreateUser(message));
|
|
|
|
client.state = State::Login(Login::CreateUser(message));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(_) => {
|
|
|
|
Err(_) => {
|
|
|
|
send_queue.push(token, "\nError\n\nUsername: ", false);
|
|
|
|
send_queue.push(token, "\nError\n\nUsername: ", false, None);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -49,10 +50,10 @@ impl Game {
|
|
|
|
// username not found
|
|
|
|
// username not found
|
|
|
|
Login::CreateUser(username) => {
|
|
|
|
Login::CreateUser(username) => {
|
|
|
|
if !message.clone().is_empty() && message != "n" {
|
|
|
|
if !message.clone().is_empty() && message != "n" {
|
|
|
|
send_queue.push(token, "\nNew password: ", false);
|
|
|
|
send_queue.push(token, "\nNew password: ", false, None);
|
|
|
|
client.state = State::Login(Login::CreatePassword(username.to_owned()));
|
|
|
|
client.state = State::Login(Login::CreatePassword(username.to_owned()));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
send_queue.push(token, "\n\nUsername: ", false);
|
|
|
|
send_queue.push(token, "\n\nUsername: ", false, None);
|
|
|
|
client.state = State::Login(Login::Username);
|
|
|
|
client.state = State::Login(Login::Username);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -60,10 +61,10 @@ impl Game {
|
|
|
|
// first new user password
|
|
|
|
// first new user password
|
|
|
|
Login::CreatePassword(username) => {
|
|
|
|
Login::CreatePassword(username) => {
|
|
|
|
if message.is_empty() {
|
|
|
|
if message.is_empty() {
|
|
|
|
send_queue.push(token, "\n\nUsername: ", false);
|
|
|
|
send_queue.push(token, "\n\nUsername: ", false, None);
|
|
|
|
client.state = State::Login(Login::Username);
|
|
|
|
client.state = State::Login(Login::Username);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
send_queue.push(token, "\nNew password again: ", false);
|
|
|
|
send_queue.push(token, "\nNew password again: ", false, None);
|
|
|
|
client.state =
|
|
|
|
client.state =
|
|
|
|
State::Login(Login::CreatePassword2((username.to_owned(), message)));
|
|
|
|
State::Login(Login::CreatePassword2((username.to_owned(), message)));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -72,7 +73,7 @@ impl Game {
|
|
|
|
Login::CreatePassword2((username, pass)) => {
|
|
|
|
Login::CreatePassword2((username, pass)) => {
|
|
|
|
let pass = pass.to_owned();
|
|
|
|
let pass = pass.to_owned();
|
|
|
|
if message.is_empty() || message != pass {
|
|
|
|
if message.is_empty() || message != pass {
|
|
|
|
send_queue.push(token, "\n\nUsername: ", false);
|
|
|
|
send_queue.push(token, "\n\nUsername: ", false, None);
|
|
|
|
client.state = State::Login(Login::Username);
|
|
|
|
client.state = State::Login(Login::Username);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if let Ok(id) = self.db.new_player_id() {
|
|
|
|
if let Ok(id) = self.db.new_player_id() {
|
|
|
@ -85,8 +86,8 @@ impl Game {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if self.db.single_save_player(token, &player).is_ok() {
|
|
|
|
if self.db.single_save_player(token, &player).is_ok() {
|
|
|
|
send_queue.push(token, format!("Welcome, {}\n", username), false);
|
|
|
|
send_queue.push(token, format!("Welcome, {}\n", username), false, None);
|
|
|
|
send_queue.push(token, "", true);
|
|
|
|
send_queue.push(token, "", true, None);
|
|
|
|
|
|
|
|
|
|
|
|
send_queue.append(&mut Command::dispatch_look(
|
|
|
|
send_queue.append(&mut Command::dispatch_look(
|
|
|
|
&Command::default(),
|
|
|
|
&Command::default(),
|
|
|
@ -97,17 +98,17 @@ impl Game {
|
|
|
|
|
|
|
|
|
|
|
|
client.state = State::Action;
|
|
|
|
client.state = State::Action;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
send_queue.push(token, "Error", true);
|
|
|
|
send_queue.push(token, "Error", true, None);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
send_queue.push(token, "Error", true);
|
|
|
|
send_queue.push(token, "Error", true, None);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Login::Password(username) => {
|
|
|
|
Login::Password(username) => {
|
|
|
|
if message.is_empty() {
|
|
|
|
if message.is_empty() {
|
|
|
|
send_queue.push(token, "\n\nUsername: ", false);
|
|
|
|
send_queue.push(token, "\n\nUsername: ", false, None);
|
|
|
|
client.state = State::Login(Login::Username);
|
|
|
|
client.state = State::Login(Login::Username);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
match self.db.find_player_by_name(username) {
|
|
|
|
match self.db.find_player_by_name(username) {
|
|
|
@ -118,6 +119,7 @@ impl Game {
|
|
|
|
token,
|
|
|
|
token,
|
|
|
|
format!("Welcome back, {}\n\n", username),
|
|
|
|
format!("Welcome back, {}\n\n", username),
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
|
|
|
|
None,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
client.state = State::Action;
|
|
|
|
client.state = State::Action;
|
|
|
|
|
|
|
|
|
|
|
@ -128,19 +130,19 @@ impl Game {
|
|
|
|
&mut self.db,
|
|
|
|
&mut self.db,
|
|
|
|
));
|
|
|
|
));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
send_queue.push(token, "Unable to login\n", false);
|
|
|
|
send_queue.push(token, "Unable to login\n", false, None);
|
|
|
|
send_queue.push(token, "\n\nUsername: ", false);
|
|
|
|
send_queue.push(token, "\n\nUsername: ", false, None);
|
|
|
|
client.state = State::Login(Login::Username);
|
|
|
|
client.state = State::Login(Login::Username);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
send_queue.push(token, "Incorrect password\n", false);
|
|
|
|
send_queue.push(token, "Incorrect password\n", false, None);
|
|
|
|
send_queue.push(token, "\n\nUsername: ", false);
|
|
|
|
send_queue.push(token, "\n\nUsername: ", false, None);
|
|
|
|
client.state = State::Login(Login::Username);
|
|
|
|
client.state = State::Login(Login::Username);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(None) | Err(_) => {
|
|
|
|
Ok(None) | Err(_) => {
|
|
|
|
send_queue.push(token, "Error\n", false);
|
|
|
|
send_queue.push(token, "Error\n", false, None);
|
|
|
|
send_queue.push(token, "\n\nUsername: ", false);
|
|
|
|
send_queue.push(token, "\n\nUsername: ", false, None);
|
|
|
|
client.state = State::Login(Login::Username);
|
|
|
|
client.state = State::Login(Login::Username);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|