use contains where possible
authoralfadur
Wed, 22 May 2019 23:05:55 +0300
changeset 15026 a479916799ea
parent 15025 dc4a12a84c92
child 15027 88e3d1ff67bb
use contains where possible
rust/hedgewars-server/src/server/handlers/inroom.rs
rust/hedgewars-server/src/utils.rs
--- a/rust/hedgewars-server/src/server/handlers/inroom.rs	Wed May 22 22:42:20 2019 +0300
+++ b/rust/hedgewars-server/src/server/handlers/inroom.rs	Wed May 22 23:05:55 2019 +0300
@@ -17,8 +17,7 @@
 };
 use base64::{decode, encode};
 use log::*;
-use std::iter::once;
-use std::mem::swap;
+use std::{cmp::min, iter::once, mem::swap};
 
 #[derive(Clone)]
 struct ByMsg<'a> {
@@ -166,7 +165,7 @@
         MaxTeams(count) => {
             if !client.is_master() {
                 response.add(Warning("You're not the room master!".to_string()).send_self());
-            } else if count < 2 || count > MAX_TEAMS_IN_ROOM {
+            } else if !(2..=MAX_TEAMS_IN_ROOM).contains(&count) {
                 response
                     .add(Warning("/maxteams: specify number from 2 to 8".to_string()).send_self());
             } else {
@@ -291,12 +290,13 @@
         SetHedgehogsNumber(team_name, number) => {
             let addable_hedgehogs = room.addable_hedgehogs();
             if let Some((_, team)) = room.find_team_and_owner_mut(|t| t.name == team_name) {
+                let max_hedgehogs = min(
+                    MAX_HEDGEHOGS_PER_TEAM,
+                    addable_hedgehogs + team.hedgehogs_number,
+                );
                 if !client.is_master() {
                     response.add(Error("You're not the room master!".to_string()).send_self());
-                } else if number < 1
-                    || number > MAX_HEDGEHOGS_PER_TEAM
-                    || number > addable_hedgehogs + team.hedgehogs_number
-                {
+                } else if !(1..=max_hedgehogs).contains(&number) {
                     response
                         .add(HedgehogsNumber(team.name.clone(), team.hedgehogs_number).send_self());
                 } else {
--- a/rust/hedgewars-server/src/utils.rs	Wed May 22 22:42:20 2019 +0300
+++ b/rust/hedgewars-server/src/utils.rs	Wed May 22 23:05:55 2019 +0300
@@ -14,7 +14,7 @@
         || name.trim() != name
         || name
             .chars()
-            .any(|c| "$()*+?[]^{|}\x7F".contains(c) || '\x00' <= c && c <= '\x1F')
+            .any(|c| "$()*+?[]^{|}\x7F".contains(c) || ('\x00'..='\x1F').contains(&c))
 }
 
 pub fn to_engine_msg<T>(msg: T) -> String