enable local admins for non-official servers
authoralfadur
Wed, 19 Jun 2019 02:40:00 +0300
changeset 15197 f6115638aa92
parent 15196 f1c2289d40bd
child 15198 a22013a817e4
enable local admins for non-official servers
rust/hedgewars-server/src/core/server.rs
rust/hedgewars-server/src/handlers.rs
rust/hedgewars-server/src/server/network.rs
--- a/rust/hedgewars-server/src/core/server.rs	Wed Jun 19 01:47:56 2019 +0300
+++ b/rust/hedgewars-server/src/core/server.rs	Wed Jun 19 02:40:00 2019 +0300
@@ -18,6 +18,7 @@
     pub protocol_number: Option<NonZeroU16>,
     pub server_salt: String,
     pub is_checker: bool,
+    pub is_local_admin: bool,
 }
 
 pub struct HwAnteroom {
@@ -30,12 +31,13 @@
         HwAnteroom { clients }
     }
 
-    pub fn add_client(&mut self, client_id: ClientId, salt: String) {
+    pub fn add_client(&mut self, client_id: ClientId, salt: String, is_local_admin: bool) {
         let client = HwAnteClient {
             nick: None,
             protocol_number: None,
             server_salt: salt,
             is_checker: false,
+            is_local_admin,
         };
         self.clients.insert(client_id, client);
     }
@@ -93,6 +95,9 @@
         if let (Some(protocol), Some(nick)) = (data.protocol_number, data.nick) {
             let mut client = HwClient::new(client_id, protocol.get(), nick);
             client.set_is_checker(data.is_checker);
+            #[cfg(not(feature = "official-server"))]
+            client.set_is_admin(data.is_local_admin);
+
             self.clients.insert(client_id, client);
         }
     }
--- a/rust/hedgewars-server/src/handlers.rs	Wed Jun 19 01:47:56 2019 +0300
+++ b/rust/hedgewars-server/src/handlers.rs	Wed Jun 19 02:40:00 2019 +0300
@@ -343,11 +343,18 @@
     }
 }
 
-pub fn handle_client_accept(server: &mut HwServer, client_id: ClientId, response: &mut Response) {
+pub fn handle_client_accept(
+    server: &mut HwServer,
+    client_id: ClientId,
+    response: &mut Response,
+    is_local: bool,
+) {
     let mut salt = [0u8; 18];
     thread_rng().fill_bytes(&mut salt);
 
-    server.anteroom.add_client(client_id, encode(&salt));
+    server
+        .anteroom
+        .add_client(client_id, encode(&salt), is_local);
 
     response.add(HwServerMessage::Connected(utils::SERVER_VERSION).send_self());
 }
--- a/rust/hedgewars-server/src/server/network.rs	Wed Jun 19 01:47:56 2019 +0300
+++ b/rust/hedgewars-server/src/server/network.rs	Wed Jun 19 02:40:00 2019 +0300
@@ -523,7 +523,12 @@
             response.add(Redirect(self.ssl.listener.local_addr().unwrap().port()).send_self())
         }
 
-        handlers::handle_client_accept(&mut self.server, client_id, &mut response);
+        handlers::handle_client_accept(
+            &mut self.server,
+            client_id,
+            &mut response,
+            self.clients[client_id].peer_addr.ip().is_loopback(),
+        );
         self.handle_response(response, poll);
     }