From cea795b99dd7e3d1d55ab5a6c78af2225b06e128 Mon Sep 17 00:00:00 2001 From: rasul Date: Tue, 23 Jun 2020 16:13:16 -0500 Subject: [PATCH] rustfmt --- src/check.rs | 20 ++++- src/command/dispatch/help.rs | 7 +- src/game/state/login.rs | 148 +++++++++++++++++------------------ src/hash.rs | 5 +- src/password.rs | 5 +- 5 files changed, 94 insertions(+), 91 deletions(-) diff --git a/src/check.rs b/src/check.rs index e0337a6..20aade9 100644 --- a/src/check.rs +++ b/src/check.rs @@ -64,9 +64,15 @@ pub fn player_name>(name: S) -> PlayerCheck { let mut err_vec = Vec::::new(); if name.len() < NAME_MIN.with(|n| *n.borrow()) { - err_vec.push(format!("{} character minimum", NAME_MIN.with(|n| *n.borrow()))); + err_vec.push(format!( + "{} character minimum", + NAME_MIN.with(|n| *n.borrow()) + )); } else if name.len() > NAME_MAX.with(|n| *n.borrow()) { - err_vec.push(format!("{} character maximum", NAME_MAX.with(|n| *n.borrow()))); + err_vec.push(format!( + "{} character maximum", + NAME_MAX.with(|n| *n.borrow()) + )); } for c in name.chars() { @@ -92,9 +98,15 @@ pub fn player_password>(password: S) -> PlayerCheck { let mut err_vec = Vec::::new(); if password.len() < PASS_MIN.with(|p| *p.borrow()) { - err_vec.push(format!("{} character minimum", PASS_MIN.with(|p| *p.borrow()))); + err_vec.push(format!( + "{} character minimum", + PASS_MIN.with(|p| *p.borrow()) + )); } else if password.len() > PASS_MAX.with(|p| *p.borrow()) { - err_vec.push(format!("{} character maximum", PASS_MAX.with(|p| *p.borrow()))); + err_vec.push(format!( + "{} character maximum", + PASS_MAX.with(|p| *p.borrow()) + )); } for c in password.chars() { diff --git a/src/command/dispatch/help.rs b/src/command/dispatch/help.rs index bca0146..d5296c7 100644 --- a/src/command/dispatch/help.rs +++ b/src/command/dispatch/help.rs @@ -5,12 +5,7 @@ use crate::database::Db; use crate::queue::SendQueue; impl Command { - pub fn dispatch_help( - command: &Command, - args: String, - token: Token, - _db: &mut Db, - ) -> SendQueue { + pub fn dispatch_help(command: &Command, args: String, token: Token, _db: &mut Db) -> SendQueue { if args.is_empty() { return (token, command.commands()).into(); } diff --git a/src/game/state/login.rs b/src/game/state/login.rs index ea07507..333cda0 100644 --- a/src/game/state/login.rs +++ b/src/game/state/login.rs @@ -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); diff --git a/src/hash.rs b/src/hash.rs index d884960..96527aa 100644 --- a/src/hash.rs +++ b/src/hash.rs @@ -63,6 +63,9 @@ mod tests { let salt = "cucumbers"; let hashed = hash(password, salt).unwrap(); - assert_eq!(hashed, "$argon2i$v=19$m=4096,t=3,p=1$Y3VjdW1iZXJz$r5IYZSVjTOQoW9bGSv3GseB6pcOSEK8btQ8ftJX5wmE"); + assert_eq!( + hashed, + "$argon2i$v=19$m=4096,t=3,p=1$Y3VjdW1iZXJz$r5IYZSVjTOQoW9bGSv3GseB6pcOSEK8btQ8ftJX5wmE" + ); } } diff --git a/src/password.rs b/src/password.rs index 89e77c7..f9a3b62 100644 --- a/src/password.rs +++ b/src/password.rs @@ -33,10 +33,7 @@ impl Password { /// Check the password against the provided password. pub fn check>(&self, s: S) -> RudeResult { let s = s.into(); - let hash = try_log!( - hash(s, &self.salt), - "Unable to check hash", - ); + let hash = try_log!(hash(s, &self.salt), "Unable to check hash",); Ok(self.hash == hash) }