mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-01 01:38:39 +00:00
Make rooms dependent on game version
This commit is contained in:
parent
1823cf55a2
commit
a2ec13205f
6 changed files with 33 additions and 23 deletions
|
@ -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
|
||||
(
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<Room> 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<int, string> 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>
|
||||
{
|
||||
user,
|
||||
},
|
||||
roomVersion,
|
||||
slot
|
||||
);
|
||||
public static Room CreateRoom(List<User> users, RoomSlot? slot = null)
|
||||
public static Room CreateRoom(List<User> 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")]
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
{
|
||||
<div class="ui blue inverted segment">
|
||||
<h2>Room @room.RoomId</h2>
|
||||
<p>@room.Players.Count players, State is @room.State</p>
|
||||
<p>@room.Players.Count players, state is @room.State, version is @room.RoomVersion.ToPrettyString()</p>
|
||||
<p>Slot type: @room.Slot.SlotType, slot id: @room.Slot.SlotId</p>
|
||||
@foreach (User player in room.Players)
|
||||
{
|
||||
|
|
|
@ -6,17 +6,18 @@ namespace LBPUnion.ProjectLighthouse.Types.Match
|
|||
{
|
||||
public class Room
|
||||
{
|
||||
|
||||
public List<User> 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)
|
||||
{
|
||||
|
|
|
@ -11,9 +11,9 @@ namespace LBPUnion.ProjectLighthouse.Types.Match
|
|||
Idle = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
DivingIntoLevel = 1,
|
||||
PlayingLevel = 1,
|
||||
|
||||
/// <summary>
|
||||
/// ???
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue