From be592bbacb4ceaf9889a68ea3d64d0fb0a23eafd Mon Sep 17 00:00:00 2001 From: jvyden Date: Mon, 25 Jul 2022 19:57:13 -0400 Subject: [PATCH] Eliminate duplicate rooms --- .../Debug/RoomVisualizerController.cs | 13 +++++++++++++ .../Pages/Debug/RoomVisualizerPage.cshtml | 4 ++++ ProjectLighthouse/Match/Rooms/RoomHelper.cs | 17 ++++++++++------- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/ProjectLighthouse.Servers.Website/Controllers/Debug/RoomVisualizerController.cs b/ProjectLighthouse.Servers.Website/Controllers/Debug/RoomVisualizerController.cs index 7039a9bf..b4772da5 100644 --- a/ProjectLighthouse.Servers.Website/Controllers/Debug/RoomVisualizerController.cs +++ b/ProjectLighthouse.Servers.Website/Controllers/Debug/RoomVisualizerController.cs @@ -46,4 +46,17 @@ public class RoomVisualizerController : ControllerBase return this.Redirect("/debug/roomVisualizer"); #endif } + + [HttpGet("createRoomsWithDuplicatePlayers")] + public async Task CreateRoomsWithDuplicatePlayers() + { + #if !DEBUG + return this.NotFound(); + #else + List 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 + } } \ No newline at end of file diff --git a/ProjectLighthouse.Servers.Website/Pages/Debug/RoomVisualizerPage.cshtml b/ProjectLighthouse.Servers.Website/Pages/Debug/RoomVisualizerPage.cshtml index 9845e193..f8b81b74 100644 --- a/ProjectLighthouse.Servers.Website/Pages/Debug/RoomVisualizerPage.cshtml +++ b/ProjectLighthouse.Servers.Website/Pages/Debug/RoomVisualizerPage.cshtml @@ -44,6 +44,10 @@
Create Fake Room
+ +
Create Rooms With Duplicate Players
+
+
Nuke all rooms
diff --git a/ProjectLighthouse/Match/Rooms/RoomHelper.cs b/ProjectLighthouse/Match/Rooms/RoomHelper.cs index b65c3b3e..6c6f4fff 100644 --- a/ProjectLighthouse/Match/Rooms/RoomHelper.cs +++ b/ProjectLighthouse/Match/Rooms/RoomHelper.cs @@ -225,7 +225,7 @@ public class RoomHelper { try { - rooms.RemoveAll(r => r.HostId == hostId); + rooms.RemoveAll(r => r.PlayerIds.Contains((int)hostId)); } catch { @@ -233,15 +233,18 @@ public class RoomHelper } } - // Remove players in this new room from other rooms + // Remove rooms containing players in this new room if (newRoom != null) - foreach (Room room in rooms) + { + foreach (Room room in rooms.Where(room => room != newRoom)) { - if (room == newRoom) continue; - - foreach (int newRoomPlayer in newRoom.PlayerIds) room.PlayerIds.RemoveAll(p => p == newRoomPlayer); - roomsToUpdate.Add(room); + foreach (int newRoomPlayer in newRoom.PlayerIds) + { + if (room.PlayerIds.Contains(newRoomPlayer)) + rooms.Remove(room); + } } + } foreach (Room room in roomsToUpdate) {