rust/hedgewars-server/src/handlers.rs
changeset 15103 823052e66611
parent 15102 80ff12edf5e6
child 15113 7d6e519a88c5
--- a/rust/hedgewars-server/src/handlers.rs	Sun Jun 02 23:58:12 2019 +0300
+++ b/rust/hedgewars-server/src/handlers.rs	Mon Jun 03 01:15:57 2019 +0300
@@ -57,6 +57,9 @@
 }
 
 pub enum IoTask {
+    CheckRegistered {
+        nick: String,
+    },
     GetAccount {
         nick: String,
         protocol: u16,
@@ -80,6 +83,7 @@
 
 #[derive(Debug)]
 pub enum IoResult {
+    AccountRegistered(bool),
     Account(Option<AccountInfo>),
     Replay(Option<Replay>),
     SaveRoom(RoomId, bool),
@@ -328,22 +332,30 @@
     io_result: IoResult,
 ) {
     match io_result {
-        IoResult::Account(Some(info)) => {
-            if !info.is_registered && server.is_registered_only() {
+        IoResult::AccountRegistered(is_registered) => {
+            if !is_registered && server.is_registered_only() {
                 response.add(
                     Bye("This server only allows registered users to join.".to_string())
                         .send_self(),
                 );
                 response.remove_client(client_id);
-            } else {
-                response.add(ServerAuth(format!("{:x}", info.server_hash)).send_self());
-                if let Some(client) = server.anteroom.remove_client(client_id) {
-                    server.add_client(client_id, client);
-                    let client = &mut server.clients[client_id];
-                    client.set_is_registered(info.is_registered);
-                    client.set_is_admin(info.is_admin);
-                    client.set_is_contributor(info.is_admin)
-                }
+            } else if is_registered {
+                let salt = server.anteroom.clients[client_id].server_salt.clone();
+                response.add(AskPassword(salt).send_self());
+            } else if let Some(client) = server.anteroom.remove_client(client_id) {
+                server.add_client(client_id, client);
+                common::join_lobby(server, response);
+            }
+        }
+        IoResult::Account(Some(info)) => {
+            response.add(ServerAuth(format!("{:x}", info.server_hash)).send_self());
+            if let Some(client) = server.anteroom.remove_client(client_id) {
+                server.add_client(client_id, client);
+                let client = &mut server.clients[client_id];
+                client.set_is_registered(info.is_registered);
+                client.set_is_admin(info.is_admin);
+                client.set_is_contributor(info.is_contributor);
+                common::join_lobby(server, response);
             }
         }
         IoResult::Account(None) => {