Rust 2018 conversion
authoralfadur
Thu, 16 Aug 2018 19:33:03 +0300
changeset 13666 09f4a30e50cc
parent 13665 5664650befcd
child 13667 bfc2727daead
Rust 2018 conversion
gameServer2/Cargo.toml
gameServer2/src/main.rs
gameServer2/src/protocol/messages.rs
gameServer2/src/protocol/parser.rs
gameServer2/src/protocol/test.rs
gameServer2/src/server/actions.rs
gameServer2/src/server/handlers/common.rs
gameServer2/src/server/handlers/inroom.rs
gameServer2/src/server/handlers/lobby.rs
gameServer2/src/server/handlers/loggingin.rs
gameServer2/src/server/handlers/mod.rs
gameServer2/src/server/network.rs
gameServer2/src/server/room.rs
gameServer2/src/server/server.rs
--- a/gameServer2/Cargo.toml	Tue Aug 14 15:25:05 2018 +0200
+++ b/gameServer2/Cargo.toml	Thu Aug 16 19:33:03 2018 +0300
@@ -1,4 +1,7 @@
+cargo-features = ["edition"]
+
 [package]
+edition = "2018"
 name = "hedgewars-server"
 version = "0.0.1"
 authors = [ "Andrey Korotaev <a.korotaev@hedgewars.org>" ]
@@ -7,7 +10,7 @@
 rand = "0.5"
 mio = "0.6"
 slab = "0.4"
-netbuf = "0.4.0"
+netbuf = "0.4"
 nom = "4.0"
 env_logger = "0.4"
 log = "0.4"
--- a/gameServer2/src/main.rs	Tue Aug 14 15:25:05 2018 +0200
+++ b/gameServer2/src/main.rs	Thu Aug 16 19:33:03 2018 +0300
@@ -1,5 +1,6 @@
 #![allow(unused_imports)]
 #![deny(bare_trait_objects)]
+#![feature(rust_2018_preview)]
 
 extern crate rand;
 extern crate mio;
@@ -27,7 +28,7 @@
 mod server;
 mod protocol;
 
-use server::network::NetworkLayer;
+use crate::server::network::NetworkLayer;
 use std::time::Duration;
 
 fn main() {
--- a/gameServer2/src/protocol/messages.rs	Tue Aug 14 15:25:05 2018 +0200
+++ b/gameServer2/src/protocol/messages.rs	Thu Aug 16 19:33:03 2018 +0300
@@ -1,4 +1,4 @@
-use server::coretypes::{
+use crate::server::coretypes::{
     ServerVar, GameCfg, TeamInfo,
     HedgehogInfo, VoteType
 };
@@ -111,7 +111,7 @@
 
 impl GameCfg {
     pub fn to_protocol(&self) -> (String, Vec<String>) {
-        use server::coretypes::GameCfg::*;
+        use crate::server::coretypes::GameCfg::*;
         match self {
             FeatureSize(s) => ("FEATURE_SIZE".to_string(), vec![s.to_string()]),
             MapType(t) => ("MAP".to_string(), vec![t.to_string()]),
@@ -260,7 +260,7 @@
             Pong => msg!["PONG"],
             Connected(protocol_version) => msg![
                 "CONNECTED",
-                "Hedgewars server https://www.hedgewars.org/",
+                "Hedgewars server http://www.hedgewars.org/",
                 protocol_version],
             Bye(msg) => msg!["BYE", msg],
             Nick(nick) => msg!["NICK", nick],
--- a/gameServer2/src/protocol/parser.rs	Tue Aug 14 15:25:05 2018 +0200
+++ b/gameServer2/src/protocol/parser.rs	Thu Aug 16 19:33:03 2018 +0300
@@ -17,7 +17,7 @@
     messages::{HWProtocolMessage, HWProtocolMessage::*},
     test::gen_proto_msg
 };
-use server::coretypes::{
+use crate::server::coretypes::{
     HedgehogInfo, TeamInfo, GameCfg, VoteType
 };
 
@@ -70,7 +70,7 @@
     | do_parse!(tag!("GET_SERVER_VAR") >> (GetServerVar))
     | do_parse!(tag!("TOGGLE_READY")   >> (ToggleReady))
     | do_parse!(tag!("START_GAME")     >> (StartGame))
-    | do_parse!(tag!("ROUNDFINISHED")  >> m: opt_param >> (RoundFinished))
+    | do_parse!(tag!("ROUNDFINISHED")  >> _m: opt_param >> (RoundFinished))
     | do_parse!(tag!("TOGGLE_RESTRICT_JOINS")  >> (ToggleRestrictJoin))
     | do_parse!(tag!("TOGGLE_RESTRICT_TEAMS")  >> (ToggleRestrictTeams))
     | do_parse!(tag!("TOGGLE_REGISTERED_ONLY") >> (ToggleRegisteredOnly))
--- a/gameServer2/src/protocol/test.rs	Tue Aug 14 15:25:05 2018 +0200
+++ b/gameServer2/src/protocol/test.rs	Thu Aug 16 19:33:03 2018 +0300
@@ -4,7 +4,7 @@
     strategy::{Strategy, BoxedStrategy, Just, Map},
 };
 
-use server::coretypes::{GameCfg, TeamInfo, HedgehogInfo};
+use crate::server::coretypes::{GameCfg, TeamInfo, HedgehogInfo};
 
 use super::messages::{
     HWProtocolMessage, HWProtocolMessage::*
@@ -53,7 +53,7 @@
 impl Arbitrary for Ascii {
     type Parameters = <String as Arbitrary>::Parameters;
 
-    fn arbitrary_with(args: Self::Parameters) -> Self::Strategy {
+    fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
         "[a-zA-Z0-9]+".prop_map(Ascii).boxed()
     }
 
@@ -63,8 +63,8 @@
 impl Arbitrary for GameCfg {
     type Parameters = ();
 
-    fn arbitrary_with(args: <Self as Arbitrary>::Parameters) -> <Self as Arbitrary>::Strategy {
-        use server::coretypes::GameCfg::*;
+    fn arbitrary_with(_args: <Self as Arbitrary>::Parameters) -> <Self as Arbitrary>::Strategy {
+        use crate::server::coretypes::GameCfg::*;
         (0..10).no_shrink().prop_flat_map(|i| {
             proto_msg_match!(i, def = FeatureSize(0),
             0 => FeatureSize(u32),
@@ -87,7 +87,7 @@
 impl Arbitrary for TeamInfo {
     type Parameters = ();
 
-    fn arbitrary_with(args: <Self as Arbitrary>::Parameters) -> <Self as Arbitrary>::Strategy {
+    fn arbitrary_with(_args: <Self as Arbitrary>::Parameters) -> <Self as Arbitrary>::Strategy {
         ("[a-z]+", 0u8..127u8, "[a-z]+", "[a-z]+", "[a-z]+", "[a-z]+",  0u8..127u8)
             .prop_map(|(name, color, grave, fort, voice_pack, flag, difficulty)| {
                 fn hog(n: u8) -> HedgehogInfo {
--- a/gameServer2/src/server/actions.rs	Tue Aug 14 15:25:05 2018 +0200
+++ b/gameServer2/src/server/actions.rs	Thu Aug 16 19:33:03 2018 +0300
@@ -11,13 +11,15 @@
     room::HWRoom,
     handlers
 };
-use protocol::messages::{
-    HWProtocolMessage,
-    HWServerMessage,
-    HWServerMessage::*,
-    server_chat
+use crate::{
+    protocol::messages::{
+        HWProtocolMessage,
+        HWServerMessage,
+        HWServerMessage::*,
+        server_chat
+    },
+    utils::to_engine_msg
 };
-use utils::to_engine_msg;
 use rand::{thread_rng, Rng, distributions::Uniform};
 
 pub enum Destination {
@@ -118,15 +120,10 @@
     match action {
         Send(msg) => server.send(client_id, &msg.destination, msg.message),
         ByeClient(msg) => {
-            let room_id;
-            let nick;
-            {
-                let c = &server.clients[client_id];
-                room_id = c.room_id;
-                nick = c.nick.clone();
-            }
+            let c = &server.clients[client_id];
+            let nick = c.nick.clone();
 
-            if let Some(id) = room_id{
+            if let Some(id) = c.room_id{
                 if id != server.lobby_id {
                     server.react(client_id, vec![
                         MoveToLobby(format!("quit: {}", msg.clone()))]);
@@ -155,16 +152,14 @@
         JoinLobby => {
             server.clients[client_id].room_id = Some(server.lobby_id);
 
-            let joined_msg;
-            {
-                let mut lobby_nicks = Vec::new();
-                for (_, c) in server.clients.iter() {
-                    if c.room_id.is_some() {
-                        lobby_nicks.push(c.nick.clone());
-                    }
+            let mut lobby_nicks = Vec::new();
+            for (_, c) in server.clients.iter() {
+                if c.room_id.is_some() {
+                    lobby_nicks.push(c.nick.clone());
                 }
-                joined_msg = LobbyJoined(lobby_nicks);
             }
+            let joined_msg = LobbyJoined(lobby_nicks);
+
             let everyone_msg = LobbyJoined(vec![server.clients[client_id].nick.clone()]);
             let flags_msg = ClientFlags(
                 "+i".to_string(),
@@ -188,105 +183,102 @@
         },
         AddRoom(name, password) => {
             let room_id = server.add_room();;
-            let actions = {
-                let r = &mut server.rooms[room_id];
-                let c = &mut server.clients[client_id];
-                r.master_id = Some(c.id);
-                r.name = name;
-                r.password = password;
-                r.protocol_number = c.protocol_number;
 
-                vec![
-                    RoomAdd(r.info(Some(&c))).send_all()
-                        .with_protocol(r.protocol_number).action(),
-                    MoveToRoom(room_id)]
-            };
+            let r = &mut server.rooms[room_id];
+            let c = &mut server.clients[client_id];
+            r.master_id = Some(c.id);
+            r.name = name;
+            r.password = password;
+            r.protocol_number = c.protocol_number;
+
+            let actions = vec![
+                RoomAdd(r.info(Some(&c))).send_all()
+                    .with_protocol(r.protocol_number).action(),
+                MoveToRoom(room_id)];
+
             server.react(client_id, actions);
         },
         RemoveRoom(room_id) => {
-            let actions = {
-                let r = &mut server.rooms[room_id];
-                vec![RoomRemove(r.name.clone()).send_all()
-                        .with_protocol(r.protocol_number).action()]
-            };
+            let r = &mut server.rooms[room_id];
+            let actions = vec![RoomRemove(r.name.clone()).send_all()
+                .with_protocol(r.protocol_number).action()];
             server.rooms.remove(room_id);
             server.react(client_id, actions);
         }
         MoveToRoom(room_id) => {
-            let actions = {
-                let r = &mut server.rooms[room_id];
-                let c = &mut server.clients[client_id];
-                r.players_number += 1;
-                c.room_id = Some(room_id);
+            let r = &mut server.rooms[room_id];
+            let c = &mut server.clients[client_id];
+            r.players_number += 1;
+            c.room_id = Some(room_id);
+
+            let is_master = r.master_id == Some(c.id);
+            c.set_is_master(is_master);
+            c.set_is_ready(is_master);
+            c.set_is_joined_mid_game(false);
+
+            if is_master {
+                r.ready_players_number += 1;
+            }
+
+            let mut v = vec![
+                RoomJoined(vec![c.nick.clone()]).send_all().in_room(room_id).action(),
+                ClientFlags("+i".to_string(), vec![c.nick.clone()]).send_all().action(),
+                SendRoomUpdate(None)];
+
+            if !r.greeting.is_empty() {
+                v.push(ChatMsg {nick: "[greeting]".to_string(), msg: r.greeting.clone()}
+                    .send_self().action());
+            }
 
-                let is_master = r.master_id == Some(c.id);
-                c.set_is_master(is_master);
-                c.set_is_ready(is_master);
-                c.set_is_joined_mid_game(false);
+            if !c.is_master() {
+                let team_names: Vec<_>;
+                if let Some(ref mut info) = r.game_info {
+                    c.set_is_in_game(true);
+                    c.set_is_joined_mid_game(true);
 
-                if is_master {
-                    r.ready_players_number += 1;
+                    {
+                        let teams = info.client_teams(c.id);
+                        c.teams_in_game = teams.clone().count() as u8;
+                        c.clan = teams.clone().next().map(|t| t.color);
+                        team_names = teams.map(|t| t.name.clone()).collect();
+                    }
+
+                    if !team_names.is_empty() {
+                        info.left_teams.retain(|name|
+                            !team_names.contains(&name));
+                        info.teams_in_game += team_names.len() as u8;
+                        r.teams = info.teams_at_start.iter()
+                            .filter(|(_, t)| !team_names.contains(&t.name))
+                            .cloned().collect();
+                    }
+                } else {
+                    team_names = Vec::new();
                 }
 
-                let mut v = vec![
-                    RoomJoined(vec![c.nick.clone()]).send_all().in_room(room_id).action(),
-                    ClientFlags("+i".to_string(), vec![c.nick.clone()]).send_all().action(),
-                    SendRoomUpdate(None)];
-                if !r.greeting.is_empty() {
-                    v.push(ChatMsg {nick: "[greeting]".to_string(), msg: r.greeting.clone()}
-                        .send_self().action());
-                }
-                if !c.is_master() {
-                    let team_names: Vec<_>;
-                    if let Some(ref mut info) = r.game_info {
-                        c.set_is_in_game(true);
-                        c.set_is_joined_mid_game(true);
-
-                        {
-                            let teams = info.client_teams(c.id);
-                            c.teams_in_game = teams.clone().count() as u8;
-                            c.clan = teams.clone().next().map(|t| t.color);
-                            team_names = teams.map(|t| t.name.clone()).collect();
-                        }
+                v.push(SendRoomData{ to: client_id, teams: true, config: true, flags: true});
 
-                        if !team_names.is_empty() {
-                            info.left_teams.retain(|name|
-                                !team_names.contains(&name));
-                            info.teams_in_game += team_names.len() as u8;
-                            r.teams = info.teams_at_start.iter()
-                                .filter(|(_, t)| !team_names.contains(&t.name))
-                                .cloned().collect();
-                        }
-                    } else {
-                        team_names = Vec::new();
-                    }
-
-                    v.push(SendRoomData{ to: client_id, teams: true, config: true, flags: true});
+                if let Some(ref info) = r.game_info {
+                    v.push(RunGame.send_self().action());
+                    v.push(ClientFlags("+g".to_string(), vec![c.nick.clone()])
+                        .send_all().in_room(r.id).action());
+                    v.push(ForwardEngineMessage(
+                        vec![to_engine_msg("e$spectate 1".bytes())])
+                        .send_self().action());
+                    v.push(ForwardEngineMessage(info.msg_log.clone())
+                        .send_self().action());
 
-                    if let Some(ref info) = r.game_info {
-                        v.push(RunGame.send_self().action());
-                        v.push(ClientFlags("+g".to_string(), vec![c.nick.clone()])
-                            .send_all().in_room(r.id).action());
+                    for name in &team_names {
                         v.push(ForwardEngineMessage(
-                            vec![to_engine_msg("e$spectate 1".bytes())])
-                            .send_self().action());
-                        v.push(ForwardEngineMessage(info.msg_log.clone())
-                            .send_self().action());
-
-                        for name in &team_names {
-                            v.push(ForwardEngineMessage(
-                                vec![to_engine_msg(once(b'G').chain(name.bytes()))])
-                                .send_all().in_room(r.id).action());
-                        }
-                        if info.is_paused {
-                            v.push(ForwardEngineMessage(vec![to_engine_msg(once(b'I'))])
-                                .send_all().in_room(r.id).action())
-                        }
+                            vec![to_engine_msg(once(b'G').chain(name.bytes()))])
+                            .send_all().in_room(r.id).action());
+                    }
+                    if info.is_paused {
+                        v.push(ForwardEngineMessage(vec![to_engine_msg(once(b'I'))])
+                            .send_all().in_room(r.id).action())
                     }
                 }
-                v
-            };
-            server.react(client_id, actions);
+            }
+            server.react(client_id, v);
         }
         SendRoomData {to, teams, config, flags} => {
             let mut actions = Vec::new();
@@ -483,7 +475,9 @@
                         .send_all().in_room(r.id).action());
                 }
             }
-            if let Some(id) = new_id { server.clients[id].set_is_master(true) }
+            if let Some(id) = new_id {
+                server.clients[id].set_is_master(true)
+            }
             server.react(client_id, actions);
         }
         RemoveTeam(name) => {
@@ -502,22 +496,18 @@
             server.react(client_id, actions);
         },
         RemoveClientTeams => {
-            let actions = if let (c, Some(r)) = server.client_and_room(client_id) {
-                r.client_teams(c.id).map(|t| RemoveTeam(t.name.clone())).collect()
-            } else {
-                Vec::new()
-            };
-            server.react(client_id, actions);
+            if let (c, Some(r)) = server.client_and_room(client_id) {
+                let actions = r.client_teams(c.id).map(|t| RemoveTeam(t.name.clone())).collect();
+                server.react(client_id, actions);
+            }
         }
         SendRoomUpdate(old_name) => {
-            let actions = if let (c, Some(r)) = server.client_and_room(client_id) {
+            if let (c, Some(r)) = server.client_and_room(client_id) {
                 let name = old_name.unwrap_or_else(|| r.name.clone());
-                vec![RoomUpdated(name, r.info(Some(&c)))
-                    .send_all().with_protocol(r.protocol_number).action()]
-            } else {
-                Vec::new()
-            };
-            server.react(client_id, actions);
+                let actions = vec![RoomUpdated(name, r.info(Some(&c)))
+                    .send_all().with_protocol(r.protocol_number).action()];
+                server.react(client_id, actions);
+            }
         },
         StartRoomGame(room_id) => {
             let actions = {
@@ -598,8 +588,7 @@
             let nicks: Vec<_> = server.clients.iter_mut()
                 .filter(|(_, c)| c.room_id == Some(room_id))
                 .map(|(_, c)| {
-                    let is_master = c.is_master();
-                    c.set_is_ready(is_master);
+                    c.set_is_ready(c.is_master());
                     c.set_is_joined_mid_game(false);
                     c
                 }).filter_map(|c| if !c.is_master() {
--- a/gameServer2/src/server/handlers/common.rs	Tue Aug 14 15:25:05 2018 +0200
+++ b/gameServer2/src/server/handlers/common.rs	Thu Aug 16 19:33:03 2018 +0300
@@ -1,8 +1,10 @@
-use protocol::messages::{
-    HWProtocolMessage::{self, Rnd}, HWServerMessage::{self, ChatMsg},
+use crate::{
+    server::{actions::Action, server::HWServer},
+    protocol::messages::{
+        HWProtocolMessage::{self, Rnd}, HWServerMessage::{self, ChatMsg},
+    }
 };
 use rand::{self, Rng, thread_rng};
-use server::{actions::Action, server::HWServer};
 
 pub fn rnd_reply(options: &[String]) -> HWServerMessage {
     let mut rng = thread_rng();
--- a/gameServer2/src/server/handlers/inroom.rs	Tue Aug 14 15:25:05 2018 +0200
+++ b/gameServer2/src/server/handlers/inroom.rs	Thu Aug 16 19:33:03 2018 +0300
@@ -1,17 +1,19 @@
 use mio;
 
-use protocol::messages::{
-    HWProtocolMessage,
-    HWServerMessage::*,
-    server_chat
+use crate::{
+    server::{
+        coretypes::{ClientId, RoomId, Voting, VoteType},
+        server::HWServer,
+        room::{HWRoom, RoomFlags},
+        actions::{Action, Action::*}
+    },
+    protocol::messages::{
+        HWProtocolMessage,
+        HWServerMessage::*,
+        server_chat
+    },
+    utils::is_name_illegal
 };
-use server::{
-    coretypes::{ClientId, RoomId, Voting, VoteType},
-    server::HWServer,
-    room::{HWRoom, RoomFlags},
-    actions::{Action, Action::*}
-};
-use utils::is_name_illegal;
 use std::{
     mem::swap, fs::{File, OpenOptions},
     io::{Read, Write, Result, Error, ErrorKind}
@@ -58,7 +60,7 @@
     }
 }
 
-fn is_msg_valid(msg: &[u8], team_indices: &[u8]) -> bool {
+fn is_msg_valid(msg: &[u8], _team_indices: &[u8]) -> bool {
     if let Some(typ) = msg.get(1) {
         VALID_MESSAGES.contains(typ)
     } else {
@@ -85,7 +87,7 @@
 }
 
 fn room_message_flag(msg: &HWProtocolMessage) -> RoomFlags {
-    use protocol::messages::HWProtocolMessage::*;
+    use crate::protocol::messages::HWProtocolMessage::*;
     match msg {
         ToggleRestrictJoin => RoomFlags::RESTRICTED_JOIN,
         ToggleRestrictTeams => RoomFlags::RESTRICTED_TEAM_ADD,
@@ -107,7 +109,7 @@
 }
 
 pub fn handle(server: &mut HWServer, client_id: ClientId, room_id: RoomId, message: HWProtocolMessage) {
-    use protocol::messages::HWProtocolMessage::*;
+    use crate::protocol::messages::HWProtocolMessage::*;
     match message {
         Part(None) => server.react(client_id, vec![
             MoveToLobby("part".to_string())]),
@@ -154,7 +156,7 @@
             server.react(client_id, actions);
         },
         ToggleReady => {
-            let actions = if let (c, Some(r)) = server.client_and_room(client_id) {
+            if let (c, Some(r)) = server.client_and_room(client_id) {
                 let flags = if c.is_ready() {
                     r.ready_players_number -= 1;
                     "-r"
@@ -162,19 +164,15 @@
                     r.ready_players_number += 1;
                     "+r"
                 };
-                let is_ready = !c.is_ready();
-                c.set_is_ready(is_ready);
+                c.set_is_ready(!c.is_ready());
                 let mut v =
                     vec![ClientFlags(flags.to_string(), vec![c.nick.clone()])
                         .send_all().in_room(r.id).action()];
                 if r.is_fixed() && r.ready_players_number == r.players_number {
                     v.push(StartRoomGame(r.id))
                 }
-                v
-            } else {
-                Vec::new()
-            };
-            server.react(client_id, actions);
+                server.react(client_id, v);
+            }
         }
         AddTeam(info) => {
             let mut actions = Vec::new();
@@ -224,9 +222,9 @@
             server.react(client_id, actions);
         },
         SetHedgehogsNumber(team_name, number) => {
-            let actions = if let (c, Some(r)) = server.client_and_room(client_id) {
+            if let (c, Some(r)) = server.client_and_room(client_id) {
                 let addable_hedgehogs = r.addable_hedgehogs();
-                if let Some((_, mut team)) = r.find_team_and_owner_mut(|t| t.name == team_name) {
+                let actions = if let Some((_, team)) = r.find_team_and_owner_mut(|t| t.name == team_name) {
                     if !c.is_master() {
                         vec![ProtocolError("You're not the room master!".to_string())]
                     } else if number < 1 || number > 8
@@ -240,16 +238,14 @@
                     }
                 } else {
                     vec![(Warn("No such team.".to_string()))]
-                }
-            } else {
-                Vec::new()
-            };
-            server.react(client_id, actions);
+                };
+                server.react(client_id, actions);
+            }
         },
         SetTeamColor(team_name, color) => {
-            let mut owner_id = None;
-            let actions = if let (c, Some(r)) = server.client_and_room(client_id) {
-                if let Some((owner, mut team)) = r.find_team_and_owner_mut(|t| t.name == team_name) {
+            if let (c, Some(r)) = server.client_and_room(client_id) {
+                let mut owner_id = None;
+                let actions = if let Some((owner, team)) = r.find_team_and_owner_mut(|t| t.name == team_name) {
                     if !c.is_master() {
                         vec![ProtocolError("You're not the room master!".to_string())]
                     } else if false  {
@@ -262,20 +258,18 @@
                     }
                 } else {
                     vec![(Warn("No such team.".to_string()))]
-                }
-            } else {
-                Vec::new()
-            };
+                };
 
-            if let Some(id) = owner_id {
-                server.clients[id].clan = Some(color);
-            }
+                if let Some(id) = owner_id {
+                    server.clients[id].clan = Some(color);
+                }
 
-            server.react(client_id, actions);
+                server.react(client_id, actions);
+            };
         },
         Cfg(cfg) => {
-            let actions = if let (c, Some(r)) = server.client_and_room(client_id) {
-                if r.is_fixed() {
+            if let (c, Some(r)) = server.client_and_room(client_id) {
+                let actions = if r.is_fixed() {
                     vec![Warn("Access denied.".to_string())]
                 } else if !c.is_master() {
                     vec![ProtocolError("You're not the room master!".to_string())]
@@ -284,11 +278,9 @@
                         .send_all().in_room(r.id).but_self().action()];
                     r.set_config(cfg);
                     v
-                }
-            } else {
-                Vec::new()
-            };
-            server.react(client_id, actions);
+                };
+                server.react(client_id, actions);
+            }
         }
         Save(name, location) => {
             let actions = vec![server_chat(format!("Room config saved as {}", name))
@@ -297,8 +289,8 @@
             server.react(client_id, actions);
         }
         SaveRoom(filename) => {
-            let actions = if server.clients[client_id].is_admin() {
-                match server.rooms[room_id].get_saves() {
+            if server.clients[client_id].is_admin() {
+                let actions = match server.rooms[room_id].get_saves() {
                     Ok(text) => match write_file(&filename, &text) {
                         Ok(_) => vec![server_chat("Room configs saved successfully.".to_string())
                             .send_self().action()],
@@ -311,15 +303,13 @@
                         warn!("Error while serializing the room configs: {}", e);
                         vec![Warn("Unable to serialize the room configs.".to_string())]
                     }
-                }
-            } else {
-                Vec::new()
-            };
-            server.react(client_id, actions);
+                };
+                server.react(client_id, actions);
+            }
         }
         LoadRoom(filename) => {
-            let actions = if server.clients[client_id].is_admin() {
-                match read_file(&filename) {
+            if server.clients[client_id].is_admin() {
+                let actions = match read_file(&filename) {
                     Ok(text) => match server.rooms[room_id].set_saves(&text) {
                         Ok(_) => vec![server_chat("Room configs loaded successfully.".to_string())
                             .send_self().action()],
@@ -332,11 +322,9 @@
                         warn!("Error while reading the config file \"{}\": {}", filename, e);
                         vec![Warn("Unable to load the room configs.".to_string())]
                     }
-                }
-            } else {
-                Vec::new()
-            };
-            server.react(client_id, actions);
+                };
+                server.react(client_id, actions);
+            }
         }
         Delete(name) => {
             let actions = if !server.rooms[room_id].delete_config(&name) {
--- a/gameServer2/src/server/handlers/lobby.rs	Tue Aug 14 15:25:05 2018 +0200
+++ b/gameServer2/src/server/handlers/lobby.rs	Thu Aug 16 19:33:03 2018 +0300
@@ -1,19 +1,21 @@
 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;
 use super::common::rnd_reply;
 
 pub fn handle(server: &mut HWServer, client_id: ClientId, message: HWProtocolMessage) {
-    use protocol::messages::HWProtocolMessage::*;
+    use crate::protocol::messages::HWProtocolMessage::*;
     match message {
         CreateRoom(name, password) => {
             let actions =
@@ -35,32 +37,29 @@
                 .send_all().in_room(server.lobby_id).but_self().action()];
             server.react(client_id, actions);
         },
-        JoinRoom(name, password) => {
-            let actions;
-            {
-                let room = server.rooms.iter().find(|(_, r)| r.name == name);
-                let room_id = room.map(|(_, r)| r.id);
-                let nicks = server.clients.iter()
-                    .filter(|(_, c)| c.room_id == room_id)
-                    .map(|(_, c)| c.nick.clone())
-                    .collect();
-                let c = &mut server.clients[client_id];
+        JoinRoom(name, _password) => {
+            let room = server.rooms.iter().find(|(_, r)| r.name == name);
+            let room_id = room.map(|(_, r)| r.id);
+            let nicks = server.clients.iter()
+                .filter(|(_, c)| c.room_id == room_id)
+                .map(|(_, c)| c.nick.clone())
+                .collect();
+            let c = &mut server.clients[client_id];
 
-                actions = if let Some((_, r)) = room {
-                    if c.protocol_number != r.protocol_number {
-                        vec![Warn("Room version incompatible to your Hedgewars version!".to_string())]
-                    } else if r.is_join_restricted() {
-                        vec![Warn("Access denied. This room currently doesn't allow joining.".to_string())]
-                    } else if r.players_number == u8::max_value() {
-                        vec![Warn("This room is already full".to_string())]
-                    } else {
-                        vec![MoveToRoom(r.id),
-                             RoomJoined(nicks).send_self().action()]
-                    }
+            let actions = if let Some((_, r)) = room {
+                if c.protocol_number != r.protocol_number {
+                    vec![Warn("Room version incompatible to your Hedgewars version!".to_string())]
+                } else if r.is_join_restricted() {
+                    vec![Warn("Access denied. This room currently doesn't allow joining.".to_string())]
+                } else if r.players_number == u8::max_value() {
+                    vec![Warn("This room is already full".to_string())]
                 } else {
-                    vec![Warn("No such room.".to_string())]
-                };
-            }
+                    vec![MoveToRoom(r.id),
+                         RoomJoined(nicks).send_self().action()]
+                }
+            } else {
+                vec![Warn("No such room.".to_string())]
+            };
             server.react(client_id, actions);
         },
         Rnd(v) => {
--- 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"),
--- a/gameServer2/src/server/handlers/mod.rs	Tue Aug 14 15:25:05 2018 +0200
+++ b/gameServer2/src/server/handlers/mod.rs	Thu Aug 16 19:33:03 2018 +0300
@@ -6,14 +6,17 @@
     actions::{Action, Action::*},
     coretypes::ClientId
 };
-use protocol::messages::{
-    HWProtocolMessage,
-    HWServerMessage::*
+use crate::{
+    protocol::messages::{
+        HWProtocolMessage,
+        HWServerMessage::*
+    }
 };
-mod common;
+
 mod loggingin;
 mod lobby;
 mod inroom;
+mod common;
 
 pub fn handle(server: &mut HWServer, client_id: ClientId, message: HWProtocolMessage) {
     match message {
--- a/gameServer2/src/server/network.rs	Tue Aug 14 15:25:05 2018 +0200
+++ b/gameServer2/src/server/network.rs	Thu Aug 16 19:33:03 2018 +0300
@@ -14,8 +14,10 @@
 use netbuf;
 use slab::Slab;
 
-use utils;
-use protocol::{ProtocolDecoder, messages::*};
+use crate::{
+    utils,
+    protocol::{ProtocolDecoder, messages::*}
+};
 use super::{
     server::{HWServer},
     coretypes::ClientId
--- a/gameServer2/src/server/room.rs	Tue Aug 14 15:25:05 2018 +0200
+++ b/gameServer2/src/server/room.rs	Thu Aug 16 19:33:03 2018 +0300
@@ -1,7 +1,7 @@
 use std::{
     iter, collections::HashMap
 };
-use server::{
+use crate::server::{
     coretypes::{ClientId, RoomId, TeamInfo, GameCfg, GameCfg::*, Voting},
     client::{HWClient}
 };
@@ -71,7 +71,7 @@
 }
 
 fn game_config_from(c: &RoomConfig) -> Vec<GameCfg> {
-    use server::coretypes::GameCfg::*;
+    use crate::server::coretypes::GameCfg::*;
     let mut v = vec![
         Ammo(c.ammo.name.to_string(), c.ammo.settings.clone()),
         Scheme(c.scheme.name.to_string(), c.scheme.settings.clone()),
--- a/gameServer2/src/server/server.rs	Tue Aug 14 15:25:05 2018 +0200
+++ b/gameServer2/src/server/server.rs	Thu Aug 16 19:33:03 2018 +0300
@@ -1,11 +1,11 @@
 use slab;
-use utils;
+use crate::utils;
 use super::{
     client::HWClient, room::HWRoom, actions, handlers,
     coretypes::{ClientId, RoomId},
     actions::{Destination, PendingMessage}
 };
-use protocol::messages::*;
+use crate::protocol::messages::*;
 
 type Slab<T> = slab::Slab<T>;