subcommand to change player password

master
rasul 5 years ago
parent cc10e5001f
commit faadf904e0

@ -1,4 +1,5 @@
mod name;
mod password;
mod player;
pub use name::*;

@ -0,0 +1,24 @@
use mio::Token;
use crate::command::CommandSetPlayer;
use crate::database::Db;
use crate::queue::SendQueue;
use crate::{try_option_send_error, try_send_error};
impl CommandSetPlayer {
/// Set the player's password
pub fn dispatch_password(&self, args: String, token: Token, db: &mut Db) -> SendQueue {
let mut player = try_option_send_error!(token, db.get_connected_player(token));
if args.is_empty() {
return SendQueue(vec![(token, "Password can't be empty".into(), true, None)].into());
}
player.password = args;
let _ = try_send_error!(token, db.save_player(&player));
let _ = try_send_error!(token, db.save_connected_player(token, &player));
SendQueue::ok(token)
}
}

@ -13,6 +13,9 @@ pub enum CommandSetPlayer {
/// Set the player's name
Name,
/// Set the password
Password,
Default,
}
@ -26,6 +29,7 @@ impl Parse for CommandSetPlayer {
fn help(&self) -> &str {
match self {
Self::Name => "set player name NEW_NAME :: Set player name to NEW_NAME.",
Self::Password => "set player password NEW_PASS :: Set password to NEW_PASS",
Self::Default => "",
}
}
@ -33,6 +37,7 @@ impl Parse for CommandSetPlayer {
fn dispatch_map(&self) -> fn(&Self, String, Token, &mut Db) -> SendQueue {
match self {
Self::Name => Self::dispatch_name,
Self::Password => Self::dispatch_password,
Self::Default => Self::dispatch_default,
}
}

Loading…
Cancel
Save