Eliminate duplicate rooms

This commit is contained in:
jvyden 2022-07-25 19:57:13 -04:00
parent 5d6e339fa8
commit be592bbacb
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
3 changed files with 27 additions and 7 deletions

View file

@ -46,4 +46,17 @@ public class RoomVisualizerController : ControllerBase
return this.Redirect("/debug/roomVisualizer"); return this.Redirect("/debug/roomVisualizer");
#endif #endif
} }
[HttpGet("createRoomsWithDuplicatePlayers")]
public async Task<IActionResult> CreateRoomsWithDuplicatePlayers()
{
#if !DEBUG
return this.NotFound();
#else
List<int> users = await this.database.Users.OrderByDescending(_ => EF.Functions.Random()).Take(1).Select(u => u.UserId).ToListAsync();
RoomHelper.CreateRoom(users, GameVersion.LittleBigPlanet2, Platform.PS3);
RoomHelper.CreateRoom(users, GameVersion.LittleBigPlanet2, Platform.PS3);
return this.Redirect("/debug/roomVisualizer");
#endif
}
} }

View file

@ -44,6 +44,10 @@
<div class="ui blue button">Create Fake Room</div> <div class="ui blue button">Create Fake Room</div>
</a> </a>
<a href="/debug/roomVisualizer/createRoomsWithDuplicatePlayers">
<div class="ui blue button">Create Rooms With Duplicate Players</div>
</a>
<a href="/debug/roomVisualizer/deleteRooms"> <a href="/debug/roomVisualizer/deleteRooms">
<div class="ui red button">Nuke all rooms</div> <div class="ui red button">Nuke all rooms</div>
</a> </a>

View file

@ -225,7 +225,7 @@ public class RoomHelper
{ {
try try
{ {
rooms.RemoveAll(r => r.HostId == hostId); rooms.RemoveAll(r => r.PlayerIds.Contains((int)hostId));
} }
catch catch
{ {
@ -233,14 +233,17 @@ public class RoomHelper
} }
} }
// Remove players in this new room from other rooms // Remove rooms containing players in this new room
if (newRoom != null) if (newRoom != null)
foreach (Room room in rooms)
{ {
if (room == newRoom) continue; foreach (Room room in rooms.Where(room => room != newRoom))
{
foreach (int newRoomPlayer in newRoom.PlayerIds) room.PlayerIds.RemoveAll(p => p == newRoomPlayer); foreach (int newRoomPlayer in newRoom.PlayerIds)
roomsToUpdate.Add(room); {
if (room.PlayerIds.Contains(newRoomPlayer))
rooms.Remove(room);
}
}
} }
foreach (Room room in roomsToUpdate) foreach (Room room in roomsToUpdate)