Fix handlers module
authorunc0rr
Mon, 06 Feb 2017 18:15:29 +0300
changeset 12154 44b06731278b
parent 12153 8591375271b8
child 12155 bbefbd1a3b0a
Fix handlers module
gameServer2/src/server/handlers.rs
gameServer2/src/server/handlers/mod.rs
--- a/gameServer2/src/server/handlers.rs	Mon Feb 06 17:54:27 2017 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,34 +0,0 @@
-use mio;
-use std::io::Write;
-use std::io;
-
-use super::server::HWServer;
-use super::actions::Action;
-use super::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::Ping =>
-            server.react(token, poll, vec![SendMe(Pong.to_raw_protocol())]),
-        HWProtocolMessage::Quit(Some(msg)) =>
-            server.react(token, poll, vec![ByeClient("User quit: ".to_string() + &msg)]),
-        HWProtocolMessage::Quit(None) =>
-            server.react(token, poll, vec![ByeClient("User quit".to_string())]),
-        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]);
-        },
-        HWProtocolMessage::List => warn!("Deprecated LIST message received"),
-        HWProtocolMessage::Malformed => warn!("Malformed/unknown message"),
-        HWProtocolMessage::Empty => warn!("Empty message"),
-        _ => unimplemented!(),
-    }
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gameServer2/src/server/handlers/mod.rs	Mon Feb 06 18:15:29 2017 +0300
@@ -0,0 +1,35 @@
+use mio;
+use std::io::Write;
+use std::io;
+
+use super::server::HWServer;
+use super::actions::Action;
+use super::actions::Action::*;
+use protocol::messages::HWProtocolMessage;
+use protocol::messages::HWServerMessage::*;
+
+mod loggingin;
+mod lobby;
+mod inroom;
+
+pub fn handle(server: &mut HWServer, token: mio::Token, poll: &mio::Poll, message: HWProtocolMessage) {
+    match message {
+        HWProtocolMessage::Ping =>
+            server.react(token, poll, vec![SendMe(Pong.to_raw_protocol())]),
+        HWProtocolMessage::Quit(Some(msg)) =>
+            server.react(token, poll, vec![ByeClient("User quit: ".to_string() + &msg)]),
+        HWProtocolMessage::Quit(None) =>
+            server.react(token, poll, vec![ByeClient("User quit".to_string())]),
+        HWProtocolMessage::Malformed => warn!("Malformed/unknown message"),
+        HWProtocolMessage::Empty => warn!("Empty message"),
+        _ => {
+            if !server.clients[token].room_id.is_some() {
+                loggingin::handle(server, token, poll, message);
+            } else if server.clients[token].room_id == Some(server.lobby_id) {
+                lobby::handle(server, token, poll, message);
+            } else {
+                inroom::handle(server, token, poll, message);
+            }
+        },
+    }
+}