gameServer2/src/server/actions.rs
changeset 12146 8d8fb85bc09c
parent 12145 a482c7a5f6e3
child 12147 03ccb89820f3
--- a/gameServer2/src/server/actions.rs	Thu Jan 26 14:45:44 2017 +0300
+++ b/gameServer2/src/server/actions.rs	Fri Jan 27 23:03:31 2017 +0300
@@ -9,6 +9,7 @@
 
 pub enum Action {
     SendMe(String),
+    SendAllButMe(String),
     RemoveClient,
     ByeClient(String),
     ReactProtocolMessage(HWProtocolMessage),
@@ -22,6 +23,13 @@
     match action {
         SendMe(msg) =>
             server.send(token, &msg),
+        SendAllButMe(msg) => {
+            for c in server.clients.iter_mut() {
+                if c.id != token {
+                    c.send_string(&msg)
+                }
+            }
+        },
         ByeClient(msg) => {
             server.react(token, poll, vec![
                 SendMe(Bye(&msg).to_raw_protocol()),
@@ -35,15 +43,27 @@
         ReactProtocolMessage(msg) =>
             handlers::handle(server, token, poll, msg),
         CheckRegistered =>
-            if server.clients[token].protocolNumber > 0 && server.clients[token].nick != "" {
+            if server.clients[token].protocol_number > 0 && server.clients[token].nick != "" {
+                server.react(token, poll, vec![
+                    JoinLobby,
+                    ]);
+            },
+        JoinLobby => {
+            let joined_msg;
+            {
+                let mut lobby_nicks: Vec<&str> = Vec::new();
+                for c in server.clients.iter() {
+                    if c.room_id.is_some() {
+                        lobby_nicks.push(&c.nick);
+                    }
+                }
+                joined_msg = LobbyJoined(&lobby_nicks).to_raw_protocol();
+            }
+            let everyone_msg = LobbyJoined(&[&server.clients[token].nick]).to_raw_protocol();
+            server.clients[token].room_id = Some(server.lobby_id);
             server.react(token, poll, vec![
-                JoinLobby,
-                ]);
-        },
-        JoinLobby => {
-            let msg_string = LobbyJoined(&[&server.clients[token].nick]).to_raw_protocol();
-            server.react(token, poll, vec![
-                SendMe(msg_string),
+                SendAllButMe(everyone_msg),
+                SendMe(joined_msg),
                 ]);
         },
         //_ => unimplemented!(),