fix official server build & bump dependencies
authoralfadur
Thu, 07 Feb 2019 18:04:53 +0300
changeset 14700 216d39de1a44
parent 14699 25c564f77b7d
child 14701 8a45c90f4580
fix official server build & bump dependencies
rust/hedgewars-server/Cargo.toml
rust/hedgewars-server/src/server/core.rs
rust/hedgewars-server/src/server/handlers/loggingin.rs
--- a/rust/hedgewars-server/Cargo.toml	Thu Feb 07 17:17:42 2019 +0300
+++ b/rust/hedgewars-server/Cargo.toml	Thu Feb 07 18:04:53 2019 +0300
@@ -10,11 +10,11 @@
 default = []
 
 [dependencies]
-rand = "0.5"
+rand = "0.6"
 mio = "0.6"
 slab = "0.4"
 netbuf = "0.4"
-nom = "4.1"
+nom = "4.2"
 env_logger = "0.6"
 log = "0.4"
 base64 = "0.10"
@@ -23,7 +23,7 @@
 serde_yaml = "0.8"
 serde_derive = "1.0"
 openssl = { version = "0.10", optional = true }
-mysql = { version = "14.2", optional = true }
+mysql = { version = "15.0", optional = true }
 
 [dev-dependencies]
 proptest = "0.8"
--- a/rust/hedgewars-server/src/server/core.rs	Thu Feb 07 17:17:42 2019 +0300
+++ b/rust/hedgewars-server/src/server/core.rs	Thu Feb 07 18:04:53 2019 +0300
@@ -19,8 +19,8 @@
 pub struct HWAnteClient {
     pub nick: Option<String>,
     pub protocol_number: Option<NonZeroU16>,
+    pub web_password: Option<String>,
     pub server_salt: String,
-    pub web_password: String,
 }
 
 pub struct HWAnteroom {
@@ -38,17 +38,15 @@
             nick: None,
             protocol_number: None,
             server_salt: salt,
-            web_password: "".to_string(),
+            web_password: None,
         };
         self.clients.insert(client_id, client);
     }
 
     pub fn remove_client(&mut self, client_id: ClientId) -> Option<HWAnteClient> {
         let mut client = self.clients.remove(client_id);
-        if let Some(ref mut client) = client {
-            client
-                .web_password
-                .replace_range(.., "🦔🦔🦔🦔🦔🦔🦔🦔");
+        if let Some(HWAnteClient { web_password: Some(ref mut password), ..}) = client {
+            password.replace_range(.., "🦔🦔🦔🦔🦔🦔🦔🦔");
         }
         client
     }
--- a/rust/hedgewars-server/src/server/handlers/loggingin.rs	Thu Feb 07 17:17:42 2019 +0300
+++ b/rust/hedgewars-server/src/server/handlers/loggingin.rs	Thu Feb 07 18:04:53 2019 +0300
@@ -29,10 +29,10 @@
 }
 
 #[cfg(feature = "official-server")]
-fn get_hash(client: &HWAnteClient, salt1: &str, salt2: &str) -> Sha1Digest {
+fn get_hash(protocol_number: u16, web_password: &str, salt1: &str, salt2: &str) -> Sha1Digest {
     let s = format!(
         "{}{}{}{}{}",
-        salt1, salt2, client.web_password, client.protocol_number, "!hedgewars"
+        salt1, salt2, web_password, protocol_number, "!hedgewars"
     );
     Sha1Digest(sha1(s.as_bytes()))
 }
@@ -97,22 +97,27 @@
         HWProtocolMessage::Password(hash, salt) => {
             let client = &anteroom.clients[client_id];
 
-            let client_hash = get_hash(client, &salt, &client.server_salt);
-            let server_hash = get_hash(client, &client.server_salt, &salt);
-            if client_hash == server_hash {
-                response.add(ServerAuth(format!("{:x}", server_hash)).send_self());
-                LoginResult::Complete
+            if let (Some(protocol), Some(password)) = (client.protocol_number, client.web_password.as_ref()) {
+                let client_hash = get_hash(protocol.get(), &password, &salt, &client.server_salt);
+                let server_hash = get_hash(protocol.get(), &password, &client.server_salt, &salt);
+                if client_hash == server_hash {
+                    response.add(ServerAuth(format!("{:x}", server_hash)).send_self());
+                    LoginResult::Complete
+                } else {
+                    response.add(Bye("No protocol provided.".to_string()).send_self());
+                    LoginResult::Unchanged
+                }
             } else {
-                response.add(Bye("Authentication failed".to_string()).send_self());
+                response.add(Bye("Authentication failed.".to_string()).send_self());
                 LoginResult::Exit
             }
         }
         #[cfg(feature = "official-server")]
         HWProtocolMessage::Checker(protocol, nick, password) => {
             let client = &mut anteroom.clients[client_id];
-            client.protocol_number = Some(protocol);
+            client.protocol_number = NonZeroU16::new(protocol);
             client.nick = Some(nick);
-            client.web_password = password;
+            client.web_password = Some(password);
             //client.set_is_checker(true);
             LoginResult::Complete
         }