Add official server feature to cargo
authoralfadur
Wed, 05 Sep 2018 19:22:29 +0300
changeset 13771 4664da990556
parent 13769 c5edfcfac68b
child 13773 c8fd12db6215
Add official server feature to cargo
gameServer2/Cargo.toml
gameServer2/src/protocol/messages.rs
gameServer2/src/protocol/parser.rs
gameServer2/src/protocol/test.rs
gameServer2/src/server/client.rs
gameServer2/src/server/handlers/checker.rs
gameServer2/src/server/handlers/loggingin.rs
gameServer2/src/server/handlers/mod.rs
gameServer2/src/server/server.rs
--- a/gameServer2/Cargo.toml	Wed Sep 05 18:09:06 2018 +0300
+++ b/gameServer2/Cargo.toml	Wed Sep 05 19:22:29 2018 +0300
@@ -6,6 +6,9 @@
 version = "0.0.1"
 authors = [ "Andrey Korotaev <a.korotaev@hedgewars.org>" ]
 
+[features]
+official-server = []
+
 [dependencies]
 rand = "0.5"
 mio = "0.6"
--- a/gameServer2/src/protocol/messages.rs	Wed Sep 05 18:09:06 2018 +0300
+++ b/gameServer2/src/protocol/messages.rs	Wed Sep 05 19:22:29 2018 +0300
@@ -20,7 +20,7 @@
     Nick(String),
     Proto(u16),
     Password(String, String),
-    Checker(u32, String, String),
+    Checker(u16, String, String),
     // lobby
     List,
     Chat(String),
--- a/gameServer2/src/protocol/parser.rs	Wed Sep 05 18:09:06 2018 +0300
+++ b/gameServer2/src/protocol/parser.rs	Wed Sep 05 19:22:29 2018 +0300
@@ -132,7 +132,7 @@
                     s: a_line     >>
                     (Password(p, s)))
     | do_parse!(tag!("CHECKER")   >> eol >>
-                    i: u32_line   >> eol >>
+                    i: u16_line   >> eol >>
                     n: a_line     >> eol >>
                     p: a_line     >>
                     (Checker(i, n, p)))
--- a/gameServer2/src/protocol/test.rs	Wed Sep 05 18:09:06 2018 +0300
+++ b/gameServer2/src/protocol/test.rs	Wed Sep 05 19:22:29 2018 +0300
@@ -120,7 +120,7 @@
         9 => Nick(Ascii),
         10 => Proto(u16),
         11 => Password(Ascii, Ascii),
-        12 => Checker(u32, Ascii, Ascii),
+        12 => Checker(u16, Ascii, Ascii),
         13 => List(),
         14 => Chat(Ascii),
         15 => CreateRoom(Ascii, Option<Ascii>),
--- a/gameServer2/src/server/client.rs	Wed Sep 05 18:09:06 2018 +0300
+++ b/gameServer2/src/server/client.rs	Wed Sep 05 19:22:29 2018 +0300
@@ -7,6 +7,7 @@
         const IS_READY = 0b0000_0100;
         const IS_IN_GAME = 0b0000_1000;
         const IS_JOINED_MID_GAME = 0b0001_0000;
+        const IS_CHECKER = 0b0010_0000;
 
         const NONE = 0b0000_0000;
         const DEFAULT = Self::NONE.bits;
@@ -17,6 +18,8 @@
     pub id: ClientId,
     pub room_id: Option<usize>,
     pub nick: String,
+    pub web_password: String,
+    pub server_salt: String,
     pub protocol_number: u16,
     pub flags: ClientFlags,
     pub teams_in_game: u8,
@@ -25,11 +28,13 @@
 }
 
 impl HWClient {
-    pub fn new(id: ClientId) -> HWClient {
+    pub fn new(id: ClientId, salt: String) -> HWClient {
         HWClient {
             id,
             room_id: None,
             nick: String::new(),
+            web_password: String::new(),
+            server_salt: salt,
             protocol_number: 0,
             flags: ClientFlags::DEFAULT,
             teams_in_game: 0,
@@ -51,10 +56,12 @@
     pub fn is_ready(&self)-> bool { self.contains(ClientFlags::IS_READY) }
     pub fn is_in_game(&self)-> bool { self.contains(ClientFlags::IS_IN_GAME) }
     pub fn is_joined_mid_game(&self)-> bool { self.contains(ClientFlags::IS_JOINED_MID_GAME) }
+    pub fn is_checker(&self)-> bool { self.contains(ClientFlags::IS_CHECKER) }
 
     pub fn set_is_admin(&mut self, value: bool) { self.set(ClientFlags::IS_ADMIN, value) }
     pub fn set_is_master(&mut self, value: bool) { self.set(ClientFlags::IS_MASTER, value) }
     pub fn set_is_ready(&mut self, value: bool) { self.set(ClientFlags::IS_READY, value) }
     pub fn set_is_in_game(&mut self, value: bool) { self.set(ClientFlags::IS_IN_GAME, value) }
     pub fn set_is_joined_mid_game(&mut self, value: bool) { self.set(ClientFlags::IS_JOINED_MID_GAME, value) }
+    pub fn set_is_checker(&mut self, value: bool) { self.set(ClientFlags::IS_CHECKER, value) }
 }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gameServer2/src/server/handlers/checker.rs	Wed Sep 05 19:22:29 2018 +0300
@@ -0,0 +1,17 @@
+use mio;
+
+use crate::{
+    server::{
+        server::HWServer,
+        coretypes::ClientId,
+    },
+    protocol::messages::{
+        HWProtocolMessage
+    },
+};
+
+pub fn handle(server: & mut HWServer, client_id: ClientId, message: HWProtocolMessage) {
+    match message {
+        _ => warn!("Unknown command"),
+    }
+}
--- a/gameServer2/src/server/handlers/loggingin.rs	Wed Sep 05 18:09:06 2018 +0300
+++ b/gameServer2/src/server/handlers/loggingin.rs	Wed Sep 05 19:22:29 2018 +0300
@@ -33,7 +33,7 @@
             };
 
             server.react(client_id, actions);
-        },
+        }
         HWProtocolMessage::Proto(proto) => {
             let client = &mut server.clients[client_id];
             let actions = if client.protocol_number != 0 {
@@ -48,7 +48,14 @@
                      CheckRegistered]
             };
             server.react(client_id, actions);
-        },
+        }
+        #[cfg(feature = "official-server")]
+        HWProtocolMessage::Checker(protocol, nick, password) => {
+            let c = &mut server.clients[client_id];
+            c.nick = nick;
+            c.web_password = password;
+            c.set_is_checker(true);
+        }
         _ => warn!("Incorrect command in logging-in state"),
     }
 }
--- a/gameServer2/src/server/handlers/mod.rs	Wed Sep 05 18:09:06 2018 +0300
+++ b/gameServer2/src/server/handlers/mod.rs	Wed Sep 05 19:22:29 2018 +0300
@@ -17,6 +17,7 @@
 mod lobby;
 mod inroom;
 mod common;
+mod checker;
 
 pub fn handle(server: &mut HWServer, client_id: ClientId, message: HWProtocolMessage) {
     match message {
--- a/gameServer2/src/server/server.rs	Wed Sep 05 18:09:06 2018 +0300
+++ b/gameServer2/src/server/server.rs	Wed Sep 05 19:22:29 2018 +0300
@@ -6,6 +6,8 @@
     actions::{Destination, PendingMessage}
 };
 use crate::protocol::messages::*;
+use rand::{RngCore, thread_rng};
+use base64::{encode};
 
 type Slab<T> = slab::Slab<T>;
 
@@ -37,7 +39,10 @@
         {
             let entry = self.clients.vacant_entry();
             key = entry.key();
-            let client = HWClient::new(entry.key());
+            let mut salt = [0u8; 18];
+            thread_rng().fill_bytes(&mut salt);
+
+            let client = HWClient::new(entry.key(), encode(&salt));
             entry.insert(client);
         }
         self.send(key, &Destination::ToSelf, HWServerMessage::Connected(utils::PROTOCOL_VERSION));