Fix collection modified error when cleaning up rooms

This commit is contained in:
jvyden 2022-02-18 16:32:33 -05:00
commit 7b5ce09fb4
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278

View file

@ -192,10 +192,9 @@ public class RoomHelper
// Remove offline players from rooms
foreach (Room room in Rooms)
{
foreach (User player in room.Players.Where(player => player.Status.StatusType == StatusType.Offline))
{
room.Players.Remove(player);
}
// do not shorten, this prevents collection modified errors
List<User> playersToRemove = room.Players.Where(player => player.Status.StatusType == StatusType.Offline).ToList();
foreach (User user in playersToRemove) room.Players.Remove(user);
}
// Delete old rooms based on host