add back em response on joining a game in progress
authoralfadur <mail@none>
Tue, 31 Dec 2019 04:42:20 +0300
changeset 15557 3f6a7a867040
parent 15556 bb93e9642b5b
child 15558 a798e6441a36
add back em response on joining a game in progress
rust/hedgewars-server/src/handlers/common.rs
--- a/rust/hedgewars-server/src/handlers/common.rs	Mon Dec 30 17:25:44 2019 +0300
+++ b/rust/hedgewars-server/src/handlers/common.rs	Tue Dec 31 04:42:20 2019 +0300
@@ -134,13 +134,10 @@
             .in_room(room.id)
             .but_self(),
     );
-    response.add(ClientFlags(add_flags(&[Flags::InRoom]), vec![nick]).send_all());
+    response.add(ClientFlags(add_flags(&[Flags::InRoom]), vec![nick.clone()]).send_all());
     let nicks = room_clients.clone().map(|c| c.nick.clone()).collect();
     response.add(RoomJoined(nicks).send_self());
 
-    get_room_teams(room, client.id, response);
-    get_room_config(room, client.id, response);
-
     let mut flag_selectors = [
         (
             Flags::RoomMaster,
@@ -168,6 +165,9 @@
         }
     }
 
+    get_room_teams(room, client.id, response);
+    get_room_config(room, client.id, response);
+
     if !room.greeting.is_empty() {
         response.add(
             ChatMsg {
@@ -177,6 +177,36 @@
             .send_self(),
         );
     }
+
+    if let Some(info) = &room.game_info {
+        response.add(
+            ClientFlags(add_flags(&[Flags::Ready, Flags::InGame]), vec![nick])
+                .send_all()
+                .in_room(room.id),
+        );
+        response.add(RunGame.send_self());
+
+        response.add(
+            ForwardEngineMessage(
+                once(to_engine_msg("e$spectate 1".bytes()))
+                    .chain(info.msg_log.iter().cloned())
+                    .collect(),
+            )
+            .send_self(),
+        );
+
+        for team in info.client_teams(client.id) {
+            response.add(
+                ForwardEngineMessage(vec![to_engine_msg(once(b'G').chain(team.name.bytes()))])
+                    .send_all()
+                    .in_room(room.id),
+            );
+        }
+
+        if info.is_paused {
+            response.add(ForwardEngineMessage(vec![to_engine_msg(once(b'I'))]).send_self());
+        }
+    }
 }
 
 pub fn get_room_join_error(error: JoinRoomError, response: &mut Response) {