Lobby joining action
authorunc0rr
Thu, 26 Jan 2017 14:45:44 +0300
changeset 12150 a482c7a5f6e3
parent 12149 589a2d7d3dc5
child 12151 8d8fb85bc09c
Lobby joining action
gameServer2/src/protocol/messages.rs
gameServer2/src/server/actions.rs
gameServer2/src/server/handlers.rs
--- a/gameServer2/src/protocol/messages.rs	Wed Jan 25 23:48:23 2017 +0300
+++ b/gameServer2/src/protocol/messages.rs	Thu Jan 26 14:45:44 2017 +0300
@@ -75,6 +75,7 @@
     Bye(&'a str),
     Nick(&'a str),
     LobbyLeft(&'a str),
+    LobbyJoined(&'a [&'a str]),
 
     Connected(u32),
     Unreachable,
@@ -111,6 +112,12 @@
             => construct_message(&["NICK", &nick]),
             &HWServerMessage::LobbyLeft(msg)
                 => construct_message(&["LOBBY_LEFT", &msg]),
+            &HWServerMessage::LobbyJoined(msg)
+                => {
+                let mut v = vec!["LOBBY:JOINED"];
+                v.extend_from_slice(msg);
+                construct_message(&v)
+            },
             _ => construct_message(&["ERROR", "UNIMPLEMENTED"]),
         }
     }
--- a/gameServer2/src/server/actions.rs	Wed Jan 25 23:48:23 2017 +0300
+++ b/gameServer2/src/server/actions.rs	Thu Jan 26 14:45:44 2017 +0300
@@ -12,6 +12,8 @@
     RemoveClient,
     ByeClient(String),
     ReactProtocolMessage(HWProtocolMessage),
+    CheckRegistered,
+    JoinLobby,
 }
 
 use self::Action::*;
@@ -32,6 +34,18 @@
         },
         ReactProtocolMessage(msg) =>
             handlers::handle(server, token, poll, msg),
+        CheckRegistered =>
+            if server.clients[token].protocolNumber > 0 && server.clients[token].nick != "" {
+            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),
+                ]);
+        },
         //_ => unimplemented!(),
     }
 }
--- a/gameServer2/src/server/handlers.rs	Wed Jan 25 23:48:23 2017 +0300
+++ b/gameServer2/src/server/handlers.rs	Thu Jan 26 14:45:44 2017 +0300
@@ -20,9 +20,13 @@
             if server.clients[token].nick.len() == 0 {
                 server.react(token, poll, vec![SendMe(Nick(&nick).to_raw_protocol())]);
                 server.clients[token].nick = nick;
+                server.react(token, poll, vec![CheckRegistered]);
             },
-        HWProtocolMessage::Proto(proto) =>
-                server.clients[token].protocolNumber = proto,
+        HWProtocolMessage::Proto(proto) => {
+                server.clients[token].protocolNumber = proto;
+                server.react(token, poll, vec![CheckRegistered]);
+        },
+        HWProtocolMessage::List => warn!("Deprecated LIST message received"),
         HWProtocolMessage::Malformed => warn!("Malformed/unknown message"),
         HWProtocolMessage::Empty => warn!("Empty message"),
         _ => unimplemented!(),