mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-03 18:48:40 +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();
|
await this.database.SaveChangesAsync();
|
||||||
|
|
||||||
// Create a new room on LBP2/3/Vita
|
// 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
|
return this.Ok
|
||||||
(
|
(
|
||||||
|
|
|
@ -77,7 +77,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
if (matchData is UpdateMyPlayerData playerData)
|
if (matchData is UpdateMyPlayerData playerData)
|
||||||
{
|
{
|
||||||
MatchHelper.SetUserLocation(user.UserId, gameToken.UserLocation);
|
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 (playerData.RoomState != null)
|
||||||
if (room != null && Equals(room.Host, user))
|
if (room != null && Equals(room.Host, user))
|
||||||
|
@ -86,7 +86,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
|
|
||||||
if (matchData is FindBestRoom && MatchHelper.UserLocations.Count > 1)
|
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();
|
if (response == null) return this.NotFound();
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new one as requested
|
// Create a new one as requested
|
||||||
RoomHelper.CreateRoom(users, createRoom.RoomSlot);
|
RoomHelper.CreateRoom(users, gameToken.GameVersion, createRoom.RoomSlot);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
@ -24,8 +24,10 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
||||||
|
|
||||||
internal static int RoomIdIncrement => roomIdIncrement++;
|
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;
|
bool anyRoomsLookingForPlayers;
|
||||||
List<Room> rooms;
|
List<Room> rooms;
|
||||||
|
|
||||||
|
@ -35,10 +37,12 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
||||||
rooms = anyRoomsLookingForPlayers ? Rooms.Where(r => anyRoomsLookingForPlayers && r.IsLookingForPlayers).ToList() : Rooms;
|
rooms = anyRoomsLookingForPlayers ? Rooms.Where(r => anyRoomsLookingForPlayers && r.IsLookingForPlayers).ToList() : Rooms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rooms = rooms.Where(r => r.RoomVersion == roomVersion).ToList();
|
||||||
|
|
||||||
foreach (Room room in rooms)
|
foreach (Room room in rooms)
|
||||||
// Look for rooms looking for players before moving on to rooms that are idle.
|
// 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();
|
Dictionary<int, string> relevantUserLocations = new();
|
||||||
|
|
||||||
|
@ -77,6 +81,8 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
||||||
response.Locations.Add(relevantUserLocations.GetValueOrDefault(player.UserId)); // Already validated to exist
|
response.Locations.Add(relevantUserLocations.GetValueOrDefault(player.UserId)); // Already validated to exist
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (user != null)
|
||||||
|
{
|
||||||
response.Players.Add
|
response.Players.Add
|
||||||
(
|
(
|
||||||
new Player
|
new Player
|
||||||
|
@ -85,6 +91,7 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
||||||
User = user,
|
User = user,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
response.Locations.Add(location);
|
response.Locations.Add(location);
|
||||||
|
|
||||||
|
@ -103,16 +110,17 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Room CreateRoom(User user, RoomSlot? slot = null)
|
public static Room CreateRoom(User user, GameVersion roomVersion, RoomSlot? slot = null)
|
||||||
=> CreateRoom
|
=> CreateRoom
|
||||||
(
|
(
|
||||||
new List<User>
|
new List<User>
|
||||||
{
|
{
|
||||||
user,
|
user,
|
||||||
},
|
},
|
||||||
|
roomVersion,
|
||||||
slot
|
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()
|
Room room = new()
|
||||||
{
|
{
|
||||||
|
@ -120,6 +128,7 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
||||||
Players = users,
|
Players = users,
|
||||||
State = RoomState.Idle,
|
State = RoomState.Idle,
|
||||||
Slot = slot ?? PodSlot,
|
Slot = slot ?? PodSlot,
|
||||||
|
RoomVersion = roomVersion,
|
||||||
};
|
};
|
||||||
|
|
||||||
CleanupRooms(room.Host, room);
|
CleanupRooms(room.Host, room);
|
||||||
|
@ -129,14 +138,14 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
||||||
return room;
|
return room;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Room? FindRoomByUser(User user, bool createIfDoesNotExist = false)
|
public static Room? FindRoomByUser(User user, GameVersion roomVersion, bool createIfDoesNotExist = false)
|
||||||
{
|
{
|
||||||
lock(Rooms)
|
lock(Rooms)
|
||||||
{
|
{
|
||||||
foreach (Room room in Rooms.Where(room => room.Players.Any(player => user == player))) return room;
|
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")]
|
[SuppressMessage("ReSharper", "InvertIf")]
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
{
|
{
|
||||||
<div class="ui blue inverted segment">
|
<div class="ui blue inverted segment">
|
||||||
<h2>Room @room.RoomId</h2>
|
<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>
|
<p>Slot type: @room.Slot.SlotType, slot id: @room.Slot.SlotId</p>
|
||||||
@foreach (User player in room.Players)
|
@foreach (User player in room.Players)
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,17 +6,18 @@ namespace LBPUnion.ProjectLighthouse.Types.Match
|
||||||
{
|
{
|
||||||
public class Room
|
public class Room
|
||||||
{
|
{
|
||||||
|
|
||||||
public List<User> Players;
|
public List<User> Players;
|
||||||
public int RoomId;
|
public int RoomId;
|
||||||
public RoomSlot Slot;
|
public RoomSlot Slot;
|
||||||
public RoomState State;
|
public RoomState State;
|
||||||
|
|
||||||
public bool IsInPod => this.Slot.SlotType == SlotType.Pod;
|
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 User Host => this.Players[0];
|
||||||
|
|
||||||
|
public GameVersion RoomVersion;
|
||||||
|
|
||||||
#nullable enable
|
#nullable enable
|
||||||
public override bool Equals(object? obj)
|
public override bool Equals(object? obj)
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,9 +11,9 @@ namespace LBPUnion.ProjectLighthouse.Types.Match
|
||||||
Idle = 0,
|
Idle = 0,
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
DivingIntoLevel = 1,
|
PlayingLevel = 1,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ???
|
/// ???
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue