diff --git a/ProjectLighthouse/Controllers/LoginController.cs b/ProjectLighthouse/Controllers/LoginController.cs index a2c381af..a8695b17 100644 --- a/ProjectLighthouse/Controllers/LoginController.cs +++ b/ProjectLighthouse/Controllers/LoginController.cs @@ -139,7 +139,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers await this.database.SaveChangesAsync(); // Create a new room on LBP2/3/Vita - if (token.GameVersion != GameVersion.LittleBigPlanet1) RoomHelper.CreateRoom(user); + if (token.GameVersion != GameVersion.LittleBigPlanet1) RoomHelper.CreateRoom(user, token.GameVersion); return this.Ok ( diff --git a/ProjectLighthouse/Controllers/MatchController.cs b/ProjectLighthouse/Controllers/MatchController.cs index 42ddd75e..a865fa9e 100644 --- a/ProjectLighthouse/Controllers/MatchController.cs +++ b/ProjectLighthouse/Controllers/MatchController.cs @@ -77,7 +77,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers if (matchData is UpdateMyPlayerData playerData) { MatchHelper.SetUserLocation(user.UserId, gameToken.UserLocation); - Room? room = RoomHelper.FindRoomByUser(user, true); + Room? room = RoomHelper.FindRoomByUser(user, gameToken.GameVersion, true); if (playerData.RoomState != null) if (room != null && Equals(room.Host, user)) @@ -86,7 +86,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers if (matchData is FindBestRoom && MatchHelper.UserLocations.Count > 1) { - FindBestRoomResponse? response = RoomHelper.FindBestRoom(user, gameToken.UserLocation); + FindBestRoomResponse? response = RoomHelper.FindBestRoom(user, gameToken.GameVersion, gameToken.UserLocation); if (response == null) return this.NotFound(); @@ -108,7 +108,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers } // Create a new one as requested - RoomHelper.CreateRoom(users, createRoom.RoomSlot); + RoomHelper.CreateRoom(users, gameToken.GameVersion, createRoom.RoomSlot); } #endregion diff --git a/ProjectLighthouse/Helpers/RoomHelper.cs b/ProjectLighthouse/Helpers/RoomHelper.cs index 4d8cb234..c89e2acd 100644 --- a/ProjectLighthouse/Helpers/RoomHelper.cs +++ b/ProjectLighthouse/Helpers/RoomHelper.cs @@ -24,8 +24,10 @@ namespace LBPUnion.ProjectLighthouse.Helpers internal static int RoomIdIncrement => roomIdIncrement++; - public static FindBestRoomResponse? FindBestRoom(User user, string location) + public static FindBestRoomResponse? FindBestRoom(User? user, GameVersion roomVersion, string location) { + if (roomVersion == GameVersion.LittleBigPlanet1 || roomVersion == GameVersion.LittleBigPlanetPSP) return null; + bool anyRoomsLookingForPlayers; List rooms; @@ -35,10 +37,12 @@ namespace LBPUnion.ProjectLighthouse.Helpers rooms = anyRoomsLookingForPlayers ? Rooms.Where(r => anyRoomsLookingForPlayers && r.IsLookingForPlayers).ToList() : Rooms; } + rooms = rooms.Where(r => r.RoomVersion == roomVersion).ToList(); + foreach (Room room in rooms) // Look for rooms looking for players before moving on to rooms that are idle. { - if (MatchHelper.DidUserRecentlyDiveInWith(user.UserId, room.Host.UserId)) continue; + if (user != null && MatchHelper.DidUserRecentlyDiveInWith(user.UserId, room.Host.UserId)) continue; Dictionary relevantUserLocations = new(); @@ -77,14 +81,17 @@ namespace LBPUnion.ProjectLighthouse.Helpers response.Locations.Add(relevantUserLocations.GetValueOrDefault(player.UserId)); // Already validated to exist } - response.Players.Add - ( - new Player - { - MatchingRes = 1, - User = user, - } - ); + if (user != null) + { + response.Players.Add + ( + new Player + { + MatchingRes = 1, + User = user, + } + ); + } response.Locations.Add(location); @@ -103,16 +110,17 @@ namespace LBPUnion.ProjectLighthouse.Helpers return null; } - public static Room CreateRoom(User user, RoomSlot? slot = null) + public static Room CreateRoom(User user, GameVersion roomVersion, RoomSlot? slot = null) => CreateRoom ( new List { user, }, + roomVersion, slot ); - public static Room CreateRoom(List users, RoomSlot? slot = null) + public static Room CreateRoom(List users, GameVersion roomVersion, RoomSlot? slot = null) { Room room = new() { @@ -120,6 +128,7 @@ namespace LBPUnion.ProjectLighthouse.Helpers Players = users, State = RoomState.Idle, Slot = slot ?? PodSlot, + RoomVersion = roomVersion, }; CleanupRooms(room.Host, room); @@ -129,14 +138,14 @@ namespace LBPUnion.ProjectLighthouse.Helpers return room; } - public static Room? FindRoomByUser(User user, bool createIfDoesNotExist = false) + public static Room? FindRoomByUser(User user, GameVersion roomVersion, bool createIfDoesNotExist = false) { lock(Rooms) { foreach (Room room in Rooms.Where(room => room.Players.Any(player => user == player))) return room; } - return createIfDoesNotExist ? CreateRoom(user) : null; + return createIfDoesNotExist ? CreateRoom(user, roomVersion) : null; } [SuppressMessage("ReSharper", "InvertIf")] diff --git a/ProjectLighthouse/Pages/Debug/RoomVisualizerPage.cshtml b/ProjectLighthouse/Pages/Debug/RoomVisualizerPage.cshtml index 1f77aba7..455c21e5 100644 --- a/ProjectLighthouse/Pages/Debug/RoomVisualizerPage.cshtml +++ b/ProjectLighthouse/Pages/Debug/RoomVisualizerPage.cshtml @@ -18,7 +18,7 @@ {

Room @room.RoomId

-

@room.Players.Count players, State is @room.State

+

@room.Players.Count players, state is @room.State, version is @room.RoomVersion.ToPrettyString()

Slot type: @room.Slot.SlotType, slot id: @room.Slot.SlotId

@foreach (User player in room.Players) { diff --git a/ProjectLighthouse/Types/Match/Room.cs b/ProjectLighthouse/Types/Match/Room.cs index 18bb962f..2af8302a 100644 --- a/ProjectLighthouse/Types/Match/Room.cs +++ b/ProjectLighthouse/Types/Match/Room.cs @@ -6,17 +6,18 @@ namespace LBPUnion.ProjectLighthouse.Types.Match { public class Room { - public List Players; public int RoomId; public RoomSlot Slot; public RoomState State; public bool IsInPod => this.Slot.SlotType == SlotType.Pod; - public bool IsLookingForPlayers => this.State == RoomState.DivingIntoLevel || this.State == RoomState.DivingInWaiting; + public bool IsLookingForPlayers => this.State == RoomState.PlayingLevel || this.State == RoomState.DivingInWaiting; public User Host => this.Players[0]; + public GameVersion RoomVersion; + #nullable enable public override bool Equals(object? obj) { diff --git a/ProjectLighthouse/Types/Match/RoomState.cs b/ProjectLighthouse/Types/Match/RoomState.cs index c674a7fc..0f542223 100644 --- a/ProjectLighthouse/Types/Match/RoomState.cs +++ b/ProjectLighthouse/Types/Match/RoomState.cs @@ -11,9 +11,9 @@ namespace LBPUnion.ProjectLighthouse.Types.Match Idle = 0, /// - /// The room is looking to join an existing room playing a specific slot. + /// The room is hosting a room on a slot for others to join. /// - DivingIntoLevel = 1, + PlayingLevel = 1, /// /// ???