Add hogs per team named constant that absolutely no one asked for
authoralfadur
Mon, 27 Aug 2018 22:28:56 +0300
changeset 13795 e335daaa77a9
parent 13708 3264a26bbf8b
child 13796 59ea2403f62d
Add hogs per team named constant that absolutely no one asked for
gameServer2/src/protocol/parser.rs
gameServer2/src/server/coretypes.rs
gameServer2/src/server/handlers/inroom.rs
gameServer2/src/server/room.rs
--- a/gameServer2/src/protocol/parser.rs	Sun Aug 26 20:50:51 2018 +0200
+++ b/gameServer2/src/protocol/parser.rs	Mon Aug 27 22:28:56 2018 +0300
@@ -18,7 +18,7 @@
     test::gen_proto_msg
 };
 use crate::server::coretypes::{
-    HedgehogInfo, TeamInfo, GameCfg, VoteType
+    HedgehogInfo, TeamInfo, GameCfg, VoteType, MAX_HEDGEHOGS_PER_TEAM
 };
 
 named!(end_of_message, tag!("\n\n"));
@@ -42,7 +42,7 @@
 named!(hog_line<&[u8], HedgehogInfo>,
     do_parse!(name: str_line >> eol >> hat: str_line >>
         (HedgehogInfo{name: name.to_string(), hat: hat.to_string()})));
-named!(_8_hogs<&[u8], [HedgehogInfo; 8]>,
+named!(_8_hogs<&[u8], [HedgehogInfo; MAX_HEDGEHOGS_PER_TEAM as usize]>,
     do_parse!(h1: hog_line >> eol >> h2: hog_line >> eol >>
               h3: hog_line >> eol >> h4: hog_line >> eol >>
               h5: hog_line >> eol >> h6: hog_line >> eol >>
--- a/gameServer2/src/server/coretypes.rs	Sun Aug 26 20:50:51 2018 +0200
+++ b/gameServer2/src/server/coretypes.rs	Mon Aug 27 22:28:56 2018 +0300
@@ -1,6 +1,8 @@
 pub type ClientId = usize;
 pub type RoomId = usize;
 
+pub const MAX_HEDGEHOGS_PER_TEAM: u8 = 8;
+
 #[derive(PartialEq, Eq, Clone, Debug)]
 pub enum ServerVar {
     MOTDNew(String),
@@ -34,7 +36,7 @@
     pub flag: String,
     pub difficulty: u8,
     pub hedgehogs_number: u8,
-    pub hedgehogs: [HedgehogInfo; 8],
+    pub hedgehogs: [HedgehogInfo; MAX_HEDGEHOGS_PER_TEAM as usize],
 }
 
 #[derive(PartialEq, Eq, Clone, Debug)]
--- a/gameServer2/src/server/handlers/inroom.rs	Sun Aug 26 20:50:51 2018 +0200
+++ b/gameServer2/src/server/handlers/inroom.rs	Mon Aug 27 22:28:56 2018 +0300
@@ -2,7 +2,10 @@
 
 use crate::{
     server::{
-        coretypes::{ClientId, RoomId, Voting, VoteType},
+        coretypes::{
+            ClientId, RoomId, Voting, VoteType,
+            MAX_HEDGEHOGS_PER_TEAM
+        },
         server::HWServer,
         room::{HWRoom, RoomFlags},
         actions::{Action, Action::*}
@@ -53,7 +56,8 @@
     match msg {
         [size, typ, body..] => VALID_MESSAGES.contains(typ)
             && match body {
-                [1...8, team, ..] if *typ == b'h' => team_indices.contains(team),
+                [1...MAX_HEDGEHOGS_PER_TEAM, team, ..] if *typ == b'h' =>
+                    team_indices.contains(team),
                 _ => *typ != b'h'
             },
         _ => false
@@ -227,7 +231,7 @@
                 let actions = if let Some((_, team)) = r.find_team_and_owner_mut(|t| t.name == team_name) {
                     if !c.is_master() {
                         vec![ProtocolError("You're not the room master!".to_string())]
-                    } else if number < 1 || number > 8
+                    } else if number < 1 || number > MAX_HEDGEHOGS_PER_TEAM
                            || number > addable_hedgehogs + team.hedgehogs_number {
                         vec![HedgehogsNumber(team.name.clone(), team.hedgehogs_number)
                             .send_self().action()]
@@ -377,7 +381,7 @@
                 },
                 VoteType::HedgehogsPerTeam(number) => {
                     match number {
-                        1...8 => None,
+                        1...MAX_HEDGEHOGS_PER_TEAM => None,
                         _ => Some("/callvote hedgehogs: Specify number from 1 to 8.".to_string())
                     }
                 },
--- a/gameServer2/src/server/room.rs	Sun Aug 26 20:50:51 2018 +0200
+++ b/gameServer2/src/server/room.rs	Mon Aug 27 22:28:56 2018 +0300
@@ -2,14 +2,18 @@
     iter, collections::HashMap
 };
 use crate::server::{
-    coretypes::{ClientId, RoomId, TeamInfo, GameCfg, GameCfg::*, Voting},
+    coretypes::{
+        ClientId, RoomId, TeamInfo, GameCfg, GameCfg::*, Voting,
+        MAX_HEDGEHOGS_PER_TEAM
+    },
     client::{HWClient}
 };
 use serde::{Serialize, Deserialize};
 use serde_yaml;
 
-const MAX_HEDGEHOGS_IN_ROOM: u8 = 64;
 const MAX_TEAMS_IN_ROOM: u8 = 8;
+const MAX_HEDGEHOGS_IN_ROOM: u8 =
+    MAX_HEDGEHOGS_PER_TEAM * MAX_HEDGEHOGS_PER_TEAM;
 
 #[derive(Clone, Serialize, Deserialize)]
 struct Ammo {