allow adding teams while round is in progress
authoralfadur
Tue, 07 Jul 2020 01:15:15 +0300
changeset 15697 25371cae9fd7
parent 15696 50dc9d0191d1
child 15698 f681c3f2eeba
allow adding teams while round is in progress
rust/hedgewars-server/src/core/server.rs
rust/hedgewars-server/src/handlers/common.rs
rust/hedgewars-server/src/handlers/inroom.rs
rust/hedgewars-server/src/handlers/strings.rs
--- a/rust/hedgewars-server/src/core/server.rs	Tue Jul 07 00:11:20 2020 +0200
+++ b/rust/hedgewars-server/src/core/server.rs	Tue Jul 07 01:15:15 2020 +0300
@@ -59,7 +59,6 @@
     TooManyTeams,
     TooManyHedgehogs,
     TeamAlreadyExists,
-    GameInProgress,
     Restricted,
 }
 
@@ -861,8 +860,6 @@
             Err(TooManyHedgehogs)
         } else if room.find_team(|t| t.name == info.name) != None {
             Err(TeamAlreadyExists)
-        } else if room.game_info.is_some() {
-            Err(GameInProgress)
         } else if room.is_team_add_restricted() {
             Err(Restricted)
         } else {
--- a/rust/hedgewars-server/src/handlers/common.rs	Tue Jul 07 00:11:20 2020 +0200
+++ b/rust/hedgewars-server/src/handlers/common.rs	Tue Jul 07 01:15:15 2020 +0300
@@ -212,18 +212,21 @@
 
         for (_, original_team) in &info.original_teams {
             if let Some(team) = room.find_team(|team| team.name == original_team.name) {
-                if team.color != original_team.color {
-                    response.add(TeamColor(team.name.clone(), team.color).send_self());
-                }
-                if team.hedgehogs_number != original_team.hedgehogs_number {
-                    response
-                        .add(HedgehogsNumber(team.name.clone(), team.hedgehogs_number).send_self());
+                if team != original_team {
+                    response.add(TeamRemove(original_team.name.clone()).send_self());
+                    response.add(TeamAdd(team.to_protocol()).send_self());
                 }
             } else {
                 response.add(TeamRemove(original_team.name.clone()).send_self());
             }
         }
 
+        for (_, team) in &room.teams {
+            if !info.original_teams.iter().any(|(_, t)| t.name == team.name) {
+                response.add(TeamAdd(team.to_protocol()).send_self());
+            }
+        }
+
         get_room_config_impl(room.config(), Destination::ToSelf, response);
     }
 }
--- a/rust/hedgewars-server/src/handlers/inroom.rs	Tue Jul 07 00:11:20 2020 +0200
+++ b/rust/hedgewars-server/src/handlers/inroom.rs	Tue Jul 07 01:15:15 2020 +0300
@@ -233,7 +233,6 @@
                 Err(AddTeamError::TooManyTeams) => response.warn(TOO_MANY_TEAMS),
                 Err(AddTeamError::TooManyHedgehogs) => response.warn(TOO_MANY_HEDGEHOGS),
                 Err(AddTeamError::TeamAlreadyExists) => response.warn(TEAM_EXISTS),
-                Err(AddTeamError::GameInProgress) => response.warn(ROUND_IN_PROGRESS),
                 Err(AddTeamError::Restricted) => response.warn(TEAM_ADD_RESTRICTED),
             }
         }
--- a/rust/hedgewars-server/src/handlers/strings.rs	Tue Jul 07 00:11:20 2020 +0200
+++ b/rust/hedgewars-server/src/handlers/strings.rs	Tue Jul 07 01:15:15 2020 +0300
@@ -26,7 +26,6 @@
 pub const ROOM_EXISTS: &str = "A room with the same name already exists.";
 pub const ROOM_FULL: &str = "This room is already full.";
 pub const ROOM_JOIN_RESTRICTED: &str = "Access denied. This room currently doesn't allow joining.";
-pub const ROUND_IN_PROGRESS: &str = "Joining not possible: Round is in progress.";
 pub const ROOM_REGISTRATION_REQUIRED: &str =
     "Access denied. This room is for registered users only.";
 pub const SUPER_POWER: &str = "Super power activated.";