fix phantom rooms
authoralfadur
Fri, 10 Apr 2020 21:58:09 +0300
changeset 15573 7478568cffbe
parent 15572 0b16baefefd1
child 15574 0031683bfa76
fix phantom rooms
rust/hedgewars-server/src/core/server.rs
rust/hedgewars-server/src/handlers/inroom.rs
--- a/rust/hedgewars-server/src/core/server.rs	Thu Mar 12 15:09:16 2020 -0400
+++ b/rust/hedgewars-server/src/core/server.rs	Fri Apr 10 21:58:09 2020 +0300
@@ -523,6 +523,7 @@
     server: &'a mut HwServer,
     client_id: ClientId,
     room_id: RoomId,
+    is_room_removed: bool
 }
 
 impl<'a> HwRoomControl<'a> {
@@ -533,6 +534,7 @@
                 server,
                 client_id,
                 room_id,
+                is_room_removed: false
             })
         } else {
             None
@@ -540,6 +542,13 @@
     }
 
     #[inline]
+    pub fn cleanup_room(self) {
+        if self.is_room_removed {
+            self.server.rooms.remove(self.room_id);
+        }
+    }
+
+    #[inline]
     pub fn server(&self) -> &HwServer {
         self.server
     }
@@ -618,7 +627,7 @@
 
         if !is_fixed {
             if room.players_number == 0 {
-                self.server.rooms.remove(self.room_id);
+                self.is_room_removed = true
             } else if room.master_id == None {
                 let protocol_number = room.protocol_number;
                 let new_master_id = self.server.room_client_ids(self.room_id).next();
--- a/rust/hedgewars-server/src/handlers/inroom.rs	Thu Mar 12 15:09:16 2020 -0400
+++ b/rust/hedgewars-server/src/handlers/inroom.rs	Fri Apr 10 21:58:09 2020 +0300
@@ -120,6 +120,7 @@
                 result,
                 response,
             );
+            room_control.cleanup_room();
         }
         Chat(msg) => {
             response.add(