gameServer2/src/server/handlers/loggingin.rs
changeset 13666 09f4a30e50cc
parent 13478 d79795acaa73
child 13798 4664da990556
--- a/gameServer2/src/server/handlers/loggingin.rs	Tue Aug 14 15:25:05 2018 +0200
+++ b/gameServer2/src/server/handlers/loggingin.rs	Thu Aug 16 19:33:03 2018 +0300
@@ -1,55 +1,52 @@
 use mio;
 
-use server::{
-    server::HWServer,
-    coretypes::ClientId,
-    actions::{Action, Action::*}
+use crate::{
+    server::{
+        server::HWServer,
+        coretypes::ClientId,
+        actions::{Action, Action::*}
+    },
+    protocol::messages::{
+        HWProtocolMessage, HWServerMessage::*
+    },
+    utils::is_name_illegal
 };
-use protocol::messages::{
-    HWProtocolMessage, HWServerMessage::*
-};
-use utils::is_name_illegal;
 
 pub fn handle(server: & mut HWServer, client_id: ClientId, message: HWProtocolMessage) {
     match message {
         HWProtocolMessage::Nick(nick) => {
-            let actions;
-            {
-                let client = &mut server.clients[client_id];
-                debug!("{} {}", nick, is_name_illegal(&nick));
-                actions = if client.room_id != None {
-                    unreachable!()
-                }
-                else if !client.nick.is_empty() {
-                    vec![ProtocolError("Nickname already provided.".to_string())]
-                }
-                else if     is_name_illegal(&nick) {
-                    vec![ByeClient("Illegal nickname! Nicknames must be between 1-40 characters long, must not have a trailing or leading space and must not have any of these characters: $()*+?[]^{|}".to_string())]
-                }
-                else {
-                    client.nick = nick.clone();
-                    vec![Nick(nick).send_self().action(),
-                         CheckRegistered]
-                };
+            let client = &mut server.clients[client_id];
+            debug!("{} {}", nick, is_name_illegal(&nick));
+            let actions = if client.room_id != None {
+                unreachable!()
+            }
+            else if !client.nick.is_empty() {
+                vec![ProtocolError("Nickname already provided.".to_string())]
             }
+            else if     is_name_illegal(&nick) {
+                vec![ByeClient("Illegal nickname! Nicknames must be between 1-40 characters long, must not have a trailing or leading space and must not have any of these characters: $()*+?[]^{|}".to_string())]
+            }
+            else {
+                client.nick = nick.clone();
+                vec![Nick(nick).send_self().action(),
+                     CheckRegistered]
+            };
+
             server.react(client_id, actions);
         },
         HWProtocolMessage::Proto(proto) => {
-            let actions;
-            {
-                let client = &mut server.clients[client_id];
-                actions = if client.protocol_number != 0 {
-                    vec![ProtocolError("Protocol already known.".to_string())]
-                }
-                else if proto == 0 {
-                    vec![ProtocolError("Bad number.".to_string())]
-                }
-                else {
-                    client.protocol_number = proto;
-                    vec![Proto(proto).send_self().action(),
-                         CheckRegistered]
-                };
+            let client = &mut server.clients[client_id];
+            let actions = if client.protocol_number != 0 {
+                vec![ProtocolError("Protocol already known.".to_string())]
             }
+            else if proto == 0 {
+                vec![ProtocolError("Bad number.".to_string())]
+            }
+            else {
+                client.protocol_number = proto;
+                vec![Proto(proto).send_self().action(),
+                     CheckRegistered]
+            };
             server.react(client_id, actions);
         },
         _ => warn!("Incorrect command in logging-in state"),