Fix team remove synchronization
authoralfadur
Wed, 04 Jul 2018 18:49:51 +0300
changeset 13443 2501428303a2
parent 13442 c6a3784ff2c1
child 13444 914f9b970f4d
Fix team remove synchronization
gameServer2/src/server/actions.rs
gameServer2/src/server/handlers/inroom.rs
gameServer2/src/server/room.rs
--- a/gameServer2/src/server/actions.rs	Wed Jul 04 15:42:42 2018 +0300
+++ b/gameServer2/src/server/actions.rs	Wed Jul 04 18:49:51 2018 +0300
@@ -446,10 +446,13 @@
                         actions.push(FinishRoomGame(r.id));
                     }
                     let remove_msg = to_engine_msg(once(b'F').chain(team_name.bytes()));
-                    match &info.last_msg {
-                        Some(m) => info.msg_log.push(m.clone()),
-                        None => info.msg_log.push(remove_msg.clone())
+                    if let Some(m) = &info.sync_msg {
+                        info.msg_log.push(m.clone());
                     }
+                    if info.sync_msg.is_some() {
+                        info.sync_msg = None
+                    }
+                    info.msg_log.push(remove_msg.clone());
                     actions.push(ForwardEngineMessage(vec![remove_msg])
                         .send_all().in_room(r.id).but_self().action());
                 }
--- a/gameServer2/src/server/handlers/inroom.rs	Wed Jul 04 15:42:42 2018 +0300
+++ b/gameServer2/src/server/handlers/inroom.rs	Wed Jul 04 18:49:51 2018 +0300
@@ -65,6 +65,10 @@
     msg.get(1).filter(|t| **t == b'+').is_some()
 }
 
+fn is_msg_timed(msg: &[u8]) -> bool {
+    msg.get(1).filter(|t| !NON_TIMED_MESSAGES.contains(t)).is_some()
+}
+
 pub fn handle(server: &mut HWServer, client_id: ClientId, message: HWProtocolMessage) {
     use protocol::messages::HWProtocolMessage::*;
     match message {
@@ -245,9 +249,10 @@
                 if c.teams_in_game > 0 {
                     let decoding = decode(&em[..]).unwrap();
                     let messages = by_msg(&decoding);
-                    let valid = messages.clone().filter(|m| is_msg_valid(m, &c.team_indices));
-                    let non_empty = messages.filter(|m| !is_msg_empty(m));
-                    let last_msg = None;
+                    let valid = messages.filter(|m| is_msg_valid(m, &c.team_indices));
+                    let non_empty = valid.clone().filter(|m| !is_msg_empty(m));
+                    let sync_msg = valid.clone().filter(|m| is_msg_timed(m))
+                        .last().map(|m| if is_msg_empty(m) {Some(encode(m))} else {None});
 
                     let em_response = encode(&valid.flat_map(|msg| msg).cloned().collect::<Vec<_>>());
                     if !em_response.is_empty() {
@@ -259,8 +264,8 @@
                         if !em_log.is_empty() {
                             info.msg_log.push(em_log);
                         }
-                        if last_msg.is_some() {
-                            info.last_msg = last_msg;
+                        if let Some(msg) = sync_msg {
+                            info.sync_msg = msg;
                         }
                     }
                 }
--- a/gameServer2/src/server/room.rs	Wed Jul 04 15:42:42 2018 +0300
+++ b/gameServer2/src/server/room.rs	Wed Jul 04 18:49:51 2018 +0300
@@ -84,7 +84,7 @@
     pub teams_at_start: Vec<(ClientId, TeamInfo)>,
     pub left_teams: Vec<String>,
     pub msg_log: Vec<String>,
-    pub last_msg: Option<String>,
+    pub sync_msg: Option<String>,
     pub is_paused: bool,
     config: RoomConfig
 }
@@ -94,7 +94,7 @@
         GameInfo {
             left_teams: Vec::new(),
             msg_log: Vec::new(),
-            last_msg: None,
+            sync_msg: None,
             is_paused: false,
             teams_in_game: teams.len() as u8,
             teams_at_start: teams,