rust/hedgewars-server/src/core/server.rs
changeset 15534 bb93e9642b5b
parent 15533 0606f89698e7
child 15536 a798e6441a36
--- a/rust/hedgewars-server/src/core/server.rs	Sat Dec 28 19:41:05 2019 +0300
+++ b/rust/hedgewars-server/src/core/server.rs	Mon Dec 30 17:25:44 2019 +0300
@@ -25,6 +25,7 @@
     WrongPassword,
     Full,
     Restricted,
+    RegistrationRequired,
 }
 
 #[derive(Debug)]
@@ -206,7 +207,7 @@
     }
 
     #[inline]
-    pub fn iter_clients(&self) -> impl Iterator<Item = &HwClient> {
+    pub fn iter_clients(&self) -> impl Iterator<Item = &HwClient> + Clone {
         self.clients.iter().map(|(_, c)| c)
     }
 
@@ -323,10 +324,15 @@
 
         if client.protocol_number != room.protocol_number {
             Err(WrongProtocol)
-        } else if room.password.is_some() && room_password != room.password.as_deref() {
+        } else if room.password.is_some()
+            && room_password != room.password.as_deref()
+            && !client.has_super_power()
+        {
             Err(WrongPassword)
         } else if room.is_join_restricted() {
             Err(Restricted)
+        } else if room.is_registration_required() {
+            Err(RegistrationRequired)
         } else if room.players_number == u8::max_value() {
             Err(Full)
         } else {
@@ -335,7 +341,8 @@
             Ok((
                 &self.clients[client_id],
                 &self.rooms[room_id],
-                self.clients.iter().map(|(_, c)| c),
+                self.iter_clients()
+                    .filter(move |c| c.room_id == Some(room_id)),
             ))
         }
     }