mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-02 10:08:39 +00:00
Merge branch 'LBPUnion:main' into main
This commit is contained in:
commit
47ae36fb52
20 changed files with 398 additions and 81 deletions
15
.idea/.idea.ProjectLighthouse/.idea/git_toolbox_prj.xml
generated
Normal file
15
.idea/.idea.ProjectLighthouse/.idea/git_toolbox_prj.xml
generated
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="GitToolBoxProjectSettings">
|
||||||
|
<option name="commitMessageIssueKeyValidationOverride">
|
||||||
|
<BoolValueOverride>
|
||||||
|
<option name="enabled" value="true" />
|
||||||
|
</BoolValueOverride>
|
||||||
|
</option>
|
||||||
|
<option name="commitMessageValidationConfigOverride">
|
||||||
|
<CommitMessageValidationOverride>
|
||||||
|
<option name="enabled" value="true" />
|
||||||
|
</CommitMessageValidationOverride>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -72,10 +72,12 @@
|
||||||
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForBuiltInTypes/@EntryValue">UseExplicitType</s:String>
|
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForBuiltInTypes/@EntryValue">UseExplicitType</s:String>
|
||||||
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForOtherTypes/@EntryValue">UseExplicitType</s:String>
|
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForOtherTypes/@EntryValue">UseExplicitType</s:String>
|
||||||
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForSimpleTypes/@EntryValue">UseExplicitType</s:String>
|
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForSimpleTypes/@EntryValue">UseExplicitType</s:String>
|
||||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=DLC/@EntryIndexedValue">DLC</s:String>
|
||||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=LBP/@EntryIndexedValue">LBP</s:String>
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=LBP/@EntryIndexedValue">LBP</s:String>
|
||||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MM/@EntryIndexedValue">MM</s:String>
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MM/@EntryIndexedValue">MM</s:String>
|
||||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=NAT/@EntryIndexedValue">NAT</s:String>
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=NAT/@EntryIndexedValue">NAT</s:String>
|
||||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=NP/@EntryIndexedValue">NP</s:String>
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=NP/@EntryIndexedValue">NP</s:String>
|
||||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=PSP/@EntryIndexedValue">PSP</s:String>
|
||||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Method/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"><ExtraRule Prefix="" Suffix="" Style="aaBb" /></Policy></s:String>
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Method/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"><ExtraRule Prefix="" Suffix="" Style="aaBb" /></Policy></s:String>
|
||||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateConstants/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></s:String>
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateConstants/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></s:String>
|
||||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticReadonly/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></s:String>
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticReadonly/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></s:String>
|
||||||
|
@ -107,15 +109,20 @@
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=npdata/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=npdata/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=NPEA/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=NPEA/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=NPHG/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=NPHG/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=NPWR/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=PCAS/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=PCAS/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=PCJS/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=PCJS/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=PCKS/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=PCKS/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=PCSA/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=PCSA/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=PCSD/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=PCSF/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=PCSF/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Swingy/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Swingy/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=thumbsup/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=thumbsup/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=topscores/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=topscores/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=UCAS/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=UCAS/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=UCES/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=UCJS/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=UCUS/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=unfavourite/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=unfavourite/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unpublish/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unpublish/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=yourthumb/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=yourthumb/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
|
@ -30,7 +30,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
public async Task<IActionResult> GetLevelQueue(string username, [FromQuery] int pageSize, [FromQuery] int pageStart)
|
public async Task<IActionResult> GetLevelQueue(string username, [FromQuery] int pageSize, [FromQuery] int pageStart)
|
||||||
{
|
{
|
||||||
Token? token = await this.database.TokenFromRequest(this.Request);
|
Token? token = await this.database.TokenFromRequest(this.Request);
|
||||||
if (token == null) return this.BadRequest();
|
if (token == null) return this.StatusCode(403, "");
|
||||||
|
|
||||||
GameVersion gameVersion = token.GameVersion;
|
GameVersion gameVersion = token.GameVersion;
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
public async Task<IActionResult> GetFavouriteSlots(string username, [FromQuery] int pageSize, [FromQuery] int pageStart)
|
public async Task<IActionResult> GetFavouriteSlots(string username, [FromQuery] int pageSize, [FromQuery] int pageStart)
|
||||||
{
|
{
|
||||||
Token? token = await this.database.TokenFromRequest(this.Request);
|
Token? token = await this.database.TokenFromRequest(this.Request);
|
||||||
if (token == null) return this.BadRequest();
|
if (token == null) return this.StatusCode(403, "");
|
||||||
|
|
||||||
GameVersion gameVersion = token.GameVersion;
|
GameVersion gameVersion = token.GameVersion;
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Kettu;
|
using Kettu;
|
||||||
|
using LBPUnion.ProjectLighthouse.Helpers;
|
||||||
using LBPUnion.ProjectLighthouse.Logging;
|
using LBPUnion.ProjectLighthouse.Logging;
|
||||||
using LBPUnion.ProjectLighthouse.Types;
|
using LBPUnion.ProjectLighthouse.Types;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Settings;
|
using LBPUnion.ProjectLighthouse.Types.Settings;
|
||||||
|
@ -48,11 +49,16 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
Token? token = await this.database.AuthenticateUser(loginData, userLocation, titleId);
|
Token? token = await this.database.AuthenticateUser(loginData, userLocation, titleId);
|
||||||
if (token == null) return this.StatusCode(403, "");
|
if (token == null) return this.StatusCode(403, "");
|
||||||
|
|
||||||
Logger.Log
|
User? user = await this.database.UserFromToken(token);
|
||||||
(
|
if (user == null) return this.StatusCode(403, "");
|
||||||
$"Successfully logged in user {(await this.database.UserFromToken(token))!.Username} as {token.GameVersion} client ({titleId})",
|
|
||||||
LoggerLevelLogin.Instance
|
Logger.Log($"Successfully logged in user {user.Username} as {token.GameVersion} client ({titleId})", LoggerLevelLogin.Instance);
|
||||||
);
|
|
||||||
|
// Create a new room on LBP2+/Vita
|
||||||
|
if (token.GameVersion != GameVersion.LittleBigPlanet1)
|
||||||
|
{
|
||||||
|
RoomHelper.CreateRoom(user);
|
||||||
|
}
|
||||||
|
|
||||||
return this.Ok
|
return this.Ok
|
||||||
(
|
(
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#nullable enable
|
#nullable enable
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
@ -71,33 +72,6 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Process match data
|
|
||||||
|
|
||||||
if (matchData is UpdateMyPlayerData) MatchHelper.SetUserLocation(user.UserId, token.UserLocation);
|
|
||||||
|
|
||||||
if (matchData is FindBestRoom && MatchHelper.UserLocations.Count > 1)
|
|
||||||
{
|
|
||||||
foreach ((int id, string? location) in MatchHelper.UserLocations)
|
|
||||||
{
|
|
||||||
if (id == user.UserId) continue;
|
|
||||||
if (location == null) continue;
|
|
||||||
if (MatchHelper.DidUserRecentlyDiveInWith(user.UserId, id)) continue;
|
|
||||||
|
|
||||||
User? otherUser = await this.database.Users.FirstOrDefaultAsync(u => u.UserId == id);
|
|
||||||
if (otherUser == null) continue;
|
|
||||||
|
|
||||||
FindBestRoomResponse response = MatchHelper.FindBestRoomResponse(user.Username, otherUser.Username, token.UserLocation, location);
|
|
||||||
|
|
||||||
string serialized = JsonSerializer.Serialize(response, typeof(FindBestRoomResponse));
|
|
||||||
|
|
||||||
MatchHelper.AddUserRecentlyDivedIn(user.UserId, id);
|
|
||||||
|
|
||||||
return new ObjectResult($"[{{\"StatusCode\":200}},{serialized}]");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Update LastMatch
|
#region Update LastMatch
|
||||||
|
|
||||||
LastMatch? lastMatch = await this.database.LastMatches.Where(l => l.UserId == user.UserId).FirstOrDefaultAsync();
|
LastMatch? lastMatch = await this.database.LastMatches.Where(l => l.UserId == user.UserId).FirstOrDefaultAsync();
|
||||||
|
@ -119,6 +93,54 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Process match data
|
||||||
|
|
||||||
|
if (matchData is UpdateMyPlayerData playerData)
|
||||||
|
{
|
||||||
|
MatchHelper.SetUserLocation(user.UserId, token.UserLocation);
|
||||||
|
Room? room = RoomHelper.FindRoomByUser(user, true);
|
||||||
|
|
||||||
|
if (playerData.RoomState != null)
|
||||||
|
{
|
||||||
|
if (room != null && Equals(room.Host, user)) room.State = (RoomState)playerData.RoomState;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (matchData is FindBestRoom && MatchHelper.UserLocations.Count > 1)
|
||||||
|
{
|
||||||
|
FindBestRoomResponse? response = RoomHelper.FindBestRoom(user, token.UserLocation);
|
||||||
|
|
||||||
|
if (response == null) return this.NotFound();
|
||||||
|
|
||||||
|
string serialized = JsonSerializer.Serialize(response, typeof(FindBestRoomResponse));
|
||||||
|
foreach (Player player in response.Players)
|
||||||
|
{
|
||||||
|
MatchHelper.AddUserRecentlyDivedIn(user.UserId, player.User.UserId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.Ok($"[{{\"StatusCode\":200}},{serialized}]");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (matchData is CreateRoom createRoom && MatchHelper.UserLocations.Count >= 1)
|
||||||
|
{
|
||||||
|
List<User> users = new();
|
||||||
|
foreach (string playerUsername in createRoom.Players)
|
||||||
|
{
|
||||||
|
User? player = await this.database.Users.FirstOrDefaultAsync(u => u.Username == playerUsername);
|
||||||
|
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
||||||
|
if (player != null)
|
||||||
|
{
|
||||||
|
users.Add(player);
|
||||||
|
}
|
||||||
|
else return this.BadRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a new one as requested
|
||||||
|
RoomHelper.CreateRoom(users, createRoom.RoomSlot);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
return this.Ok("[{\"StatusCode\":200}]");
|
return this.Ok("[{\"StatusCode\":200}]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
public async Task<IActionResult> SlotsBy([FromQuery] string u, [FromQuery] int pageStart, [FromQuery] int pageSize)
|
public async Task<IActionResult> SlotsBy([FromQuery] string u, [FromQuery] int pageStart, [FromQuery] int pageSize)
|
||||||
{
|
{
|
||||||
Token? token = await this.database.TokenFromRequest(this.Request);
|
Token? token = await this.database.TokenFromRequest(this.Request);
|
||||||
if (token == null) return this.BadRequest();
|
if (token == null) return this.StatusCode(403, "");
|
||||||
|
|
||||||
GameVersion gameVersion = token.GameVersion;
|
GameVersion gameVersion = token.GameVersion;
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
if (user == null) return this.StatusCode(403, "");
|
if (user == null) return this.StatusCode(403, "");
|
||||||
|
|
||||||
Token? token = await this.database.TokenFromRequest(this.Request);
|
Token? token = await this.database.TokenFromRequest(this.Request);
|
||||||
if (token == null) return this.BadRequest();
|
if (token == null) return this.StatusCode(403, "");
|
||||||
|
|
||||||
GameVersion gameVersion = token.GameVersion;
|
GameVersion gameVersion = token.GameVersion;
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
public async Task<IActionResult> NewestSlots([FromQuery] int pageStart, [FromQuery] int pageSize)
|
public async Task<IActionResult> NewestSlots([FromQuery] int pageStart, [FromQuery] int pageSize)
|
||||||
{
|
{
|
||||||
Token? token = await this.database.TokenFromRequest(this.Request);
|
Token? token = await this.database.TokenFromRequest(this.Request);
|
||||||
if (token == null) return this.BadRequest();
|
if (token == null) return this.StatusCode(403, "");
|
||||||
|
|
||||||
GameVersion gameVersion = token.GameVersion;
|
GameVersion gameVersion = token.GameVersion;
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
public async Task<IActionResult> TeamPickedSlots([FromQuery] int pageStart, [FromQuery] int pageSize)
|
public async Task<IActionResult> TeamPickedSlots([FromQuery] int pageStart, [FromQuery] int pageSize)
|
||||||
{
|
{
|
||||||
Token? token = await this.database.TokenFromRequest(this.Request);
|
Token? token = await this.database.TokenFromRequest(this.Request);
|
||||||
if (token == null) return this.BadRequest();
|
if (token == null) return this.StatusCode(403, "");
|
||||||
|
|
||||||
GameVersion gameVersion = token.GameVersion;
|
GameVersion gameVersion = token.GameVersion;
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
public async Task<IActionResult> LuckyDipSlots([FromQuery] int pageStart, [FromQuery] int pageSize, [FromQuery] int seed)
|
public async Task<IActionResult> LuckyDipSlots([FromQuery] int pageStart, [FromQuery] int pageSize, [FromQuery] int seed)
|
||||||
{
|
{
|
||||||
Token? token = await this.database.TokenFromRequest(this.Request);
|
Token? token = await this.database.TokenFromRequest(this.Request);
|
||||||
if (token == null) return this.BadRequest();
|
if (token == null) return this.StatusCode(403, "");
|
||||||
|
|
||||||
GameVersion gameVersion = token.GameVersion;
|
GameVersion gameVersion = token.GameVersion;
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
|
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
EXPOSE 80
|
EXPOSE 10060
|
||||||
EXPOSE 443
|
|
||||||
|
|
||||||
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
|
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
COPY ["ProjectLighthouse/ProjectLighthouse.csproj", "ProjectLighthouse/"]
|
COPY ["ProjectLighthouse/ProjectLighthouse.csproj", "ProjectLighthouse/"]
|
||||||
RUN dotnet restore "ProjectLighthouse/ProjectLighthouse.csproj"
|
RUN dotnet restore "ProjectLighthouse/ProjectLighthouse.csproj"
|
||||||
|
|
|
@ -79,7 +79,12 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
||||||
|
|
||||||
public static readonly string[] LittleBigPlanetVitaTitleIds =
|
public static readonly string[] LittleBigPlanetVitaTitleIds =
|
||||||
{
|
{
|
||||||
"PCSF00021", "PCSA00017", "PCSC00013", "PCSD00006", "PCSA00549", "PCSF00516"
|
"PCSF00021", "PCSA00017", "PCSC00013", "PCSD00006", "PCSA00549", "PCSF00516",
|
||||||
|
};
|
||||||
|
|
||||||
|
public static readonly string[] LittleBigPlanetPSPTitleIds =
|
||||||
|
{
|
||||||
|
"NPWR00500", "UCAS40262", "UCES01264", "UCUS98744", "UCJS10107",
|
||||||
};
|
};
|
||||||
|
|
||||||
public static GameVersion FromTitleId(string titleId)
|
public static GameVersion FromTitleId(string titleId)
|
||||||
|
@ -88,6 +93,7 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
||||||
if (LittleBigPlanet2TitleIds.Contains(titleId)) return GameVersion.LittleBigPlanet2;
|
if (LittleBigPlanet2TitleIds.Contains(titleId)) return GameVersion.LittleBigPlanet2;
|
||||||
if (LittleBigPlanet3TitleIds.Contains(titleId)) return GameVersion.LittleBigPlanet3;
|
if (LittleBigPlanet3TitleIds.Contains(titleId)) return GameVersion.LittleBigPlanet3;
|
||||||
if (LittleBigPlanetVitaTitleIds.Contains(titleId)) return GameVersion.LittleBigPlanetVita;
|
if (LittleBigPlanetVitaTitleIds.Contains(titleId)) return GameVersion.LittleBigPlanetVita;
|
||||||
|
if (LittleBigPlanetPSPTitleIds.Contains(titleId)) return GameVersion.LittleBigPlanetPSP;
|
||||||
|
|
||||||
return GameVersion.LittleBigPlanet1;
|
return GameVersion.LittleBigPlanet1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,37 +39,6 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
||||||
return recentlyDivedIn.Contains(otherUserId);
|
return recentlyDivedIn.Contains(otherUserId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FindBestRoomResponse FindBestRoomResponse(string username, string otherUsername, string location, string otherLocation)
|
|
||||||
=> new()
|
|
||||||
{
|
|
||||||
Players = new List<Player>
|
|
||||||
{
|
|
||||||
new()
|
|
||||||
{
|
|
||||||
MatchingRes = 0,
|
|
||||||
PlayerId = otherUsername,
|
|
||||||
},
|
|
||||||
new()
|
|
||||||
{
|
|
||||||
MatchingRes = 1,
|
|
||||||
PlayerId = username,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Locations = new List<string>
|
|
||||||
{
|
|
||||||
location,
|
|
||||||
otherLocation,
|
|
||||||
},
|
|
||||||
Slots = new List<List<int>>
|
|
||||||
{
|
|
||||||
new()
|
|
||||||
{
|
|
||||||
5,
|
|
||||||
0,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
public static IMatchData? Deserialize(string data)
|
public static IMatchData? Deserialize(string data)
|
||||||
{
|
{
|
||||||
string matchType = "";
|
string matchType = "";
|
||||||
|
|
162
ProjectLighthouse/Helpers/RoomHelper.cs
Normal file
162
ProjectLighthouse/Helpers/RoomHelper.cs
Normal file
|
@ -0,0 +1,162 @@
|
||||||
|
#nullable enable
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Linq;
|
||||||
|
using Kettu;
|
||||||
|
using LBPUnion.ProjectLighthouse.Logging;
|
||||||
|
using LBPUnion.ProjectLighthouse.Types;
|
||||||
|
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||||
|
using LBPUnion.ProjectLighthouse.Types.Match;
|
||||||
|
|
||||||
|
namespace LBPUnion.ProjectLighthouse.Helpers
|
||||||
|
{
|
||||||
|
public class RoomHelper
|
||||||
|
{
|
||||||
|
public static readonly List<Room> Rooms = new();
|
||||||
|
|
||||||
|
public static readonly RoomSlot PodSlot = new()
|
||||||
|
{
|
||||||
|
SlotType = SlotType.Pod,
|
||||||
|
SlotId = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
private static int roomIdIncrement = 0;
|
||||||
|
|
||||||
|
internal static int RoomIdIncrement => roomIdIncrement++;
|
||||||
|
|
||||||
|
public static FindBestRoomResponse? FindBestRoom(User user, string location)
|
||||||
|
{
|
||||||
|
bool anyRoomsLookingForPlayers = Rooms.Any(r => r.IsLookingForPlayers);
|
||||||
|
|
||||||
|
List<Room> rooms = anyRoomsLookingForPlayers ? Rooms.Where(r => anyRoomsLookingForPlayers && r.IsLookingForPlayers).ToList() : Rooms;
|
||||||
|
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;
|
||||||
|
|
||||||
|
Dictionary<int, string> relevantUserLocations = new();
|
||||||
|
|
||||||
|
// Determine if all players in a room have UserLocations stored, also store the relevant userlocations while we're at it
|
||||||
|
bool allPlayersHaveLocations = room.Players.All
|
||||||
|
(
|
||||||
|
p =>
|
||||||
|
{
|
||||||
|
bool gotValue = MatchHelper.UserLocations.TryGetValue(p.UserId, out string? value);
|
||||||
|
|
||||||
|
if (gotValue && value != null)
|
||||||
|
{
|
||||||
|
relevantUserLocations.Add(p.UserId, value);
|
||||||
|
}
|
||||||
|
return gotValue;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// If we don't have all locations then the game won't know how to communicate. Thus, it's not a valid room.
|
||||||
|
if (!allPlayersHaveLocations) continue;
|
||||||
|
|
||||||
|
// If we got here then it should be a valid room.
|
||||||
|
|
||||||
|
FindBestRoomResponse response = new();
|
||||||
|
|
||||||
|
response.Players = new List<Player>();
|
||||||
|
response.Locations = new List<string>();
|
||||||
|
foreach (User player in room.Players)
|
||||||
|
{
|
||||||
|
response.Players.Add
|
||||||
|
(
|
||||||
|
new Player
|
||||||
|
{
|
||||||
|
MatchingRes = 0,
|
||||||
|
User = player,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
response.Locations.Add(relevantUserLocations.GetValueOrDefault(player.UserId)); // Already validated to exist
|
||||||
|
}
|
||||||
|
|
||||||
|
response.Players.Add
|
||||||
|
(
|
||||||
|
new Player
|
||||||
|
{
|
||||||
|
MatchingRes = 1,
|
||||||
|
User = user,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
response.Locations.Add(location);
|
||||||
|
|
||||||
|
response.Slots = new List<List<int>>
|
||||||
|
{
|
||||||
|
new()
|
||||||
|
{
|
||||||
|
(int)room.Slot.SlotType,
|
||||||
|
room.Slot.SlotId,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Room CreateRoom(User user, RoomSlot? slot = null)
|
||||||
|
=> CreateRoom
|
||||||
|
(
|
||||||
|
new List<User>
|
||||||
|
{
|
||||||
|
user,
|
||||||
|
},
|
||||||
|
slot
|
||||||
|
);
|
||||||
|
public static Room CreateRoom(List<User> users, RoomSlot? slot = null)
|
||||||
|
{
|
||||||
|
Room room = new()
|
||||||
|
{
|
||||||
|
RoomId = RoomIdIncrement,
|
||||||
|
Players = users,
|
||||||
|
State = RoomState.Idle,
|
||||||
|
Slot = slot ?? PodSlot,
|
||||||
|
};
|
||||||
|
|
||||||
|
CleanupRooms(room.Host, room);
|
||||||
|
Rooms.Add(room);
|
||||||
|
Logger.Log($"Created room (id: {room.RoomId}) for host {room.Host.Username} (id: {room.Host.UserId})", LoggerLevelMatch.Instance);
|
||||||
|
|
||||||
|
return room;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Room? FindRoomByUser(User user, bool createIfDoesNotExist = false)
|
||||||
|
{
|
||||||
|
foreach (Room room in Rooms)
|
||||||
|
{
|
||||||
|
foreach (User player in room.Players)
|
||||||
|
{
|
||||||
|
if (user == player) return room;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return createIfDoesNotExist ? CreateRoom(user) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
[SuppressMessage("ReSharper", "InvertIf")]
|
||||||
|
public static void CleanupRooms(User? host = null, Room? newRoom = null)
|
||||||
|
{
|
||||||
|
// Delete old rooms based on host
|
||||||
|
if (host != null)
|
||||||
|
{
|
||||||
|
Rooms.RemoveAll(r => r.Host == host);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove players in this new room from other rooms
|
||||||
|
if (newRoom != null)
|
||||||
|
{
|
||||||
|
foreach (Room room in Rooms)
|
||||||
|
{
|
||||||
|
if (room == newRoom) continue;
|
||||||
|
|
||||||
|
foreach (User newRoomPlayer in newRoom.Players) room.Players.RemoveAll(p => p == newRoomPlayer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,6 +6,7 @@ namespace LBPUnion.ProjectLighthouse.Types
|
||||||
LittleBigPlanet2 = 1,
|
LittleBigPlanet2 = 1,
|
||||||
LittleBigPlanet3 = 2,
|
LittleBigPlanet3 = 2,
|
||||||
LittleBigPlanetVita = 3,
|
LittleBigPlanetVita = 3,
|
||||||
|
LittleBigPlanetPSP = 4,
|
||||||
Unknown = -1,
|
Unknown = -1,
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Types.Match
|
namespace LBPUnion.ProjectLighthouse.Types.Match
|
||||||
{
|
{
|
||||||
|
@ -21,6 +22,13 @@ namespace LBPUnion.ProjectLighthouse.Types.Match
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public IEnumerable<int> FirstSlot => this.Slots[0];
|
public IEnumerable<int> FirstSlot => this.Slots[0];
|
||||||
|
|
||||||
|
public RoomSlot RoomSlot
|
||||||
|
=> new()
|
||||||
|
{
|
||||||
|
SlotType = (SlotType)Slots[0][0],
|
||||||
|
SlotId = Slots[0][1],
|
||||||
|
};
|
||||||
|
|
||||||
public List<int> NAT;
|
public List<int> NAT;
|
||||||
public RoomState RoomState;
|
public RoomState RoomState;
|
||||||
public int HostMood;
|
public int HostMood;
|
||||||
|
|
|
@ -1,5 +1,28 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Types.Match
|
namespace LBPUnion.ProjectLighthouse.Types.Match
|
||||||
{
|
{
|
||||||
public class FindBestRoom : CreateRoom
|
// Schema is the EXACT SAME as CreateRoom (but cant be a subclass here), so see comments there for details
|
||||||
{}
|
[SuppressMessage("ReSharper", "CollectionNeverUpdated.Global")]
|
||||||
|
public class FindBestRoom : IMatchData
|
||||||
|
{
|
||||||
|
public List<string> Players { get; set; }
|
||||||
|
|
||||||
|
public List<string> Reservations { get; set; }
|
||||||
|
public List<List<int>> Slots { get; set; }
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public IEnumerable<int> FirstSlot => this.Slots[0];
|
||||||
|
|
||||||
|
public List<int> NAT;
|
||||||
|
public RoomState RoomState;
|
||||||
|
public int HostMood;
|
||||||
|
public int PassedNoJoinPoint;
|
||||||
|
public List<int> Location;
|
||||||
|
public int Language;
|
||||||
|
public int BuildVersion;
|
||||||
|
public string Search;
|
||||||
|
}
|
||||||
}
|
}
|
9
ProjectLighthouse/Types/Match/NatType.cs
Normal file
9
ProjectLighthouse/Types/Match/NatType.cs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
namespace LBPUnion.ProjectLighthouse.Types.Match
|
||||||
|
{
|
||||||
|
public enum NatType
|
||||||
|
{
|
||||||
|
Open = 1,
|
||||||
|
Moderate = 2,
|
||||||
|
Strict = 3,
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Types.Match
|
namespace LBPUnion.ProjectLighthouse.Types.Match
|
||||||
|
@ -6,7 +7,11 @@ namespace LBPUnion.ProjectLighthouse.Types.Match
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class Player
|
public class Player
|
||||||
{
|
{
|
||||||
public string PlayerId { get; set; }
|
[JsonIgnore]
|
||||||
|
public User User { get; set; }
|
||||||
|
|
||||||
|
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
||||||
|
public string PlayerId => User.Username;
|
||||||
|
|
||||||
[JsonPropertyName("matching_res")]
|
[JsonPropertyName("matching_res")]
|
||||||
public int MatchingRes { get; set; }
|
public int MatchingRes { get; set; }
|
||||||
|
|
32
ProjectLighthouse/Types/Match/Room.cs
Normal file
32
ProjectLighthouse/Types/Match/Room.cs
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||||
|
|
||||||
|
namespace LBPUnion.ProjectLighthouse.Types.Match
|
||||||
|
{
|
||||||
|
public class Room
|
||||||
|
{
|
||||||
|
public int RoomId;
|
||||||
|
|
||||||
|
public List<User> Players;
|
||||||
|
public RoomState State;
|
||||||
|
public RoomSlot Slot;
|
||||||
|
|
||||||
|
public bool IsInPod => Slot.SlotType == SlotType.Pod;
|
||||||
|
public bool IsLookingForPlayers => this.State == RoomState.DivingIntoLevel || this.State == RoomState.DivingInWaiting;
|
||||||
|
|
||||||
|
public User Host => this.Players[0];
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
public static bool operator ==(Room? room1, Room? room2)
|
||||||
|
{
|
||||||
|
if (ReferenceEquals(room1, room2)) return true;
|
||||||
|
if ((object?)room1 == null || (object?)room2 == null) return false;
|
||||||
|
|
||||||
|
return room1.RoomId == room2.RoomId;
|
||||||
|
}
|
||||||
|
public static bool operator !=(Room? room1, Room? room2) => !(room1 == room2);
|
||||||
|
|
||||||
|
public override int GetHashCode() => this.RoomId;
|
||||||
|
#nullable disable
|
||||||
|
}
|
||||||
|
}
|
10
ProjectLighthouse/Types/Match/RoomSlot.cs
Normal file
10
ProjectLighthouse/Types/Match/RoomSlot.cs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||||
|
|
||||||
|
namespace LBPUnion.ProjectLighthouse.Types.Match
|
||||||
|
{
|
||||||
|
public class RoomSlot
|
||||||
|
{
|
||||||
|
public SlotType SlotType;
|
||||||
|
public int SlotId;
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,10 +2,29 @@ namespace LBPUnion.ProjectLighthouse.Types.Match
|
||||||
{
|
{
|
||||||
public enum RoomState
|
public enum RoomState
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The room isn't doing anything in particular.
|
||||||
|
/// </summary>
|
||||||
Idle = 0,
|
Idle = 0,
|
||||||
LookingForPlayersForLevel = 1,
|
|
||||||
|
/// <summary>
|
||||||
|
/// The room is looking to join an existing room playing a specific slot.
|
||||||
|
/// </summary>
|
||||||
|
DivingIntoLevel = 1,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ???
|
||||||
|
/// </summary>
|
||||||
Unknown = 2,
|
Unknown = 2,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The room is looking for other rooms to join.
|
||||||
|
/// </summary>
|
||||||
DivingIn = 3,
|
DivingIn = 3,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The room is waiting for players to join their room.
|
||||||
|
/// </summary>
|
||||||
DivingInWaiting = 4,
|
DivingInWaiting = 4,
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,10 @@
|
||||||
|
#nullable enable
|
||||||
namespace LBPUnion.ProjectLighthouse.Types.Match
|
namespace LBPUnion.ProjectLighthouse.Types.Match
|
||||||
{
|
{
|
||||||
public class UpdateMyPlayerData : IMatchData
|
public class UpdateMyPlayerData : IMatchData
|
||||||
{
|
{
|
||||||
public string Player;
|
public string Player { get; set; }
|
||||||
|
|
||||||
|
public RoomState? RoomState { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using LBPUnion.ProjectLighthouse.Serialization;
|
using LBPUnion.ProjectLighthouse.Serialization;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Profiles;
|
using LBPUnion.ProjectLighthouse.Types.Profiles;
|
||||||
|
@ -187,5 +188,25 @@ namespace LBPUnion.ProjectLighthouse.Types
|
||||||
|
|
||||||
#endregion Slots
|
#endregion Slots
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
public override bool Equals(object? obj)
|
||||||
|
{
|
||||||
|
if (obj is User user) return user.UserId == UserId;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
[SuppressMessage("ReSharper", "ConditionIsAlwaysTrueOrFalse")]
|
||||||
|
public static bool operator ==(User? user1, User? user2)
|
||||||
|
{
|
||||||
|
if (ReferenceEquals(user1, user2)) return true;
|
||||||
|
if ((object?)user1 == null || (object?)user2 == null) return false;
|
||||||
|
|
||||||
|
return user1.UserId == user2.UserId;
|
||||||
|
}
|
||||||
|
public static bool operator !=(User? user1, User? user2) => !(user1 == user2);
|
||||||
|
|
||||||
|
public override int GetHashCode() => this.UserId;
|
||||||
|
#nullable disable
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue