From 6e8e99e3291353cc1c0156a9c46b807b93c958f1 Mon Sep 17 00:00:00 2001 From: rasul Date: Tue, 28 Apr 2020 15:59:14 -0500 Subject: [PATCH] ensure requirements are met when changing password --- src/command/set/player/password.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/command/set/player/password.rs b/src/command/set/player/password.rs index babc570..b13828d 100644 --- a/src/command/set/player/password.rs +++ b/src/command/set/player/password.rs @@ -1,5 +1,6 @@ use mio::Token; +use crate::check; use crate::command::CommandSetPlayer; use crate::database::Db; use crate::password::Password; @@ -11,13 +12,17 @@ impl CommandSetPlayer { pub fn dispatch_password(&self, args: String, token: Token, db: &mut Db) -> SendQueue { let player = try_option_send_error!(token, db.get_connected_player(token)); - if args.is_empty() { - return (token, "Password can't be empty").into(); + match check::player_password(args) { + check::PlayerCheck::Ok(checked_pass) => { + let password = try_send_error!(token, Password::new(checked_pass)); + let _ = try_send_error!(token, db.save_password(player.id, &password)); + SendQueue::ok(token) + } + check::PlayerCheck::Err(err_vec) => { + let mut s: String = err_vec.join("\n"); + s.push_str("\n"); + (token, s).into() + } } - - let password = try_send_error!(token, Password::new(args)); - let _ = try_send_error!(token, db.save_password(player.id, &password)); - - SendQueue::ok(token) } }