From 2b5c8fd78283743fbe7e3c12c9b04856c94d0396 Mon Sep 17 00:00:00 2001 From: jvyden Date: Tue, 5 Apr 2022 17:32:30 -0400 Subject: [PATCH] Add proper support for level dive-ins --- .../Controllers/GameApi/Matching/MatchController.cs | 10 ++++++++-- ProjectLighthouse/Helpers/RoomHelper.cs | 12 ++++++++++-- .../Pages/Debug/RoomVisualizerPage.cshtml | 2 +- ProjectLighthouse/Types/Match/FindBestRoom.cs | 8 ++++++++ 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/ProjectLighthouse/Controllers/GameApi/Matching/MatchController.cs b/ProjectLighthouse/Controllers/GameApi/Matching/MatchController.cs index d250fb44..a2124f02 100644 --- a/ProjectLighthouse/Controllers/GameApi/Matching/MatchController.cs +++ b/ProjectLighthouse/Controllers/GameApi/Matching/MatchController.cs @@ -88,9 +88,15 @@ public class MatchController : ControllerBase room.State = (RoomState)playerData.RoomState; } - if (matchData is FindBestRoom && MatchHelper.UserLocations.Count > 1) + // Check how many people are online in release builds, disabled for debug for ..well debugging. + #if DEBUG + if (matchData is FindBestRoom diveInData) + #else + if (matchData is FindBestRoom diveInData && MatchHelper.UserLocations.Count > 1) + #endif { - FindBestRoomResponse? response = RoomHelper.FindBestRoom(user, gameToken.GameVersion, gameToken.Platform, gameToken.UserLocation); + FindBestRoomResponse? response = RoomHelper.FindBestRoom + (user, gameToken.GameVersion, diveInData.RoomSlot, gameToken.Platform, gameToken.UserLocation); if (response == null) return this.NotFound(); diff --git a/ProjectLighthouse/Helpers/RoomHelper.cs b/ProjectLighthouse/Helpers/RoomHelper.cs index 81db373a..cd549b30 100644 --- a/ProjectLighthouse/Helpers/RoomHelper.cs +++ b/ProjectLighthouse/Helpers/RoomHelper.cs @@ -42,11 +42,11 @@ public class RoomHelper internal static int RoomIdIncrement => roomIdIncrement++; - public static FindBestRoomResponse? FindBestRoom(User? user, GameVersion roomVersion, Platform? platform, string? location) + public static FindBestRoomResponse? FindBestRoom(User? user, GameVersion roomVersion, RoomSlot? slot, Platform? platform, string? location) { if (roomVersion == GameVersion.LittleBigPlanet1 || roomVersion == GameVersion.LittleBigPlanetPSP) { - Logger.Log($"Returning null for FindBestRoom, game ({roomVersion}) does not support dive in", LoggerLevelMatch.Instance); + Logger.Log($"Returning null for FindBestRoom, game ({roomVersion}) does not support dive in (should never happen?)", LoggerLevelMatch.Instance); return null; } @@ -62,6 +62,14 @@ public class RoomHelper rooms = rooms.Where(r => r.RoomVersion == roomVersion).ToList(); if (platform != null) rooms = rooms.Where(r => r.RoomPlatform == platform).ToList(); + // If the user is in the pod while trying to look for a room, then they're diving in. + // Otherwise they're looking for people to play with in a particular level. + // We handle that here: + if (slot != null && slot.SlotType != SlotType.Pod && slot.SlotId != 0) + { + rooms = rooms.Where(r => r.Slot.SlotType == slot.SlotType && r.Slot.SlotId == slot.SlotId).ToList(); + } + foreach (Room room in rooms) // Look for rooms looking for players before moving on to rooms that are idle. { diff --git a/ProjectLighthouse/Pages/Debug/RoomVisualizerPage.cshtml b/ProjectLighthouse/Pages/Debug/RoomVisualizerPage.cshtml index 265b4951..6a16b67c 100644 --- a/ProjectLighthouse/Pages/Debug/RoomVisualizerPage.cshtml +++ b/ProjectLighthouse/Pages/Debug/RoomVisualizerPage.cshtml @@ -52,7 +52,7 @@ { if (version == GameVersion.LittleBigPlanet1 || version == GameVersion.LittleBigPlanetPSP || version == GameVersion.Unknown) continue; - FindBestRoomResponse? response = RoomHelper.FindBestRoom(null, version, null, null); + FindBestRoomResponse? response = RoomHelper.FindBestRoom(null, version, null, null, null); string text = response == null ? "No room found." : "Room " + response.RoomId;

Best room for @version.ToPrettyString(): @text

diff --git a/ProjectLighthouse/Types/Match/FindBestRoom.cs b/ProjectLighthouse/Types/Match/FindBestRoom.cs index 324747e2..eebf2e57 100644 --- a/ProjectLighthouse/Types/Match/FindBestRoom.cs +++ b/ProjectLighthouse/Types/Match/FindBestRoom.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Text.Json.Serialization; +using LBPUnion.ProjectLighthouse.Types.Levels; namespace LBPUnion.ProjectLighthouse.Types.Match; @@ -24,4 +25,11 @@ public class FindBestRoom : IMatchData [JsonIgnore] public IEnumerable FirstSlot => this.Slots[0]; + + public RoomSlot RoomSlot + => new() + { + SlotType = (SlotType)this.Slots[0][0], + SlotId = this.Slots[0][1], + }; } \ No newline at end of file