gameServer2/src/server/handlers/loggingin.rs
changeset 12152 03ccb89820f3
child 12857 bd35cb2302b3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gameServer2/src/server/handlers/loggingin.rs	Sat Feb 04 19:52:38 2017 +0300
@@ -0,0 +1,23 @@
+use mio;
+
+use server::server::HWServer;
+use server::actions::Action;
+use server::actions::Action::*;
+use protocol::messages::HWProtocolMessage;
+use protocol::messages::HWServerMessage::*;
+
+pub fn handle(server: &mut HWServer, token: mio::Token, poll: &mio::Poll, message: HWProtocolMessage) {
+    match message {
+        HWProtocolMessage::Nick(nick) =>
+            if server.clients[token].room_id == None {
+                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].protocol_number = proto;
+            server.react(token, poll, vec![CheckRegistered]);
+        },
+        _ => warn!("Incorrect command in logging-in state"),
+    }
+}