Fix room deletions

This commit is contained in:
jvyden 2022-07-25 20:31:19 -04:00
commit 6f0752c247
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278

View file

@ -227,6 +227,13 @@ public class RoomHelper
roomsToUpdate.Add(room); roomsToUpdate.Add(room);
} }
// DO NOT REMOVE ROOMS BEFORE THIS POINT!
// this will cause the room to be added back to the database
foreach (Room room in roomsToUpdate)
{
rooms.Update(room);
}
// Delete old rooms based on host // Delete old rooms based on host
if (hostId != null) if (hostId != null)
{ {
@ -247,17 +254,11 @@ public class RoomHelper
{ {
foreach (int newRoomPlayer in newRoom.PlayerIds) foreach (int newRoomPlayer in newRoom.PlayerIds)
{ {
if (room.PlayerIds.Contains(newRoomPlayer)) if (room.PlayerIds.Contains(newRoomPlayer)) rooms.Remove(room);
rooms.Remove(room);
} }
} }
} }
foreach (Room room in roomsToUpdate)
{
rooms.Update(room);
}
rooms.RemoveAll(r => r.PlayerIds.Count == 0); // Remove empty rooms rooms.RemoveAll(r => r.PlayerIds.Count == 0); // Remove empty rooms
rooms.RemoveAll(r => r.HostId == -1); // Remove rooms with broken hosts rooms.RemoveAll(r => r.HostId == -1); // Remove rooms with broken hosts
rooms.RemoveAll(r => r.PlayerIds.Count > 4); // Remove obviously bogus rooms rooms.RemoveAll(r => r.PlayerIds.Count > 4); // Remove obviously bogus rooms