mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-19 11:41:30 +00:00
Lots of bug fixes and performance improvements (#410)
* Many bug fixes and performance enhancements * Fix warnings and speed up photos with me * Finish refactoring user serialization * Finish refactoring user serialization Use GameTokens instead of User when possible Prevent negative page sizes * Fix debug compilation * Add gzip compression to example nginx config * Remove deflate changes * Add UsernameFromWebToken Co-authored-by: Jayden <jvyden@jvyden.xyz>
This commit is contained in:
parent
8dbd0e63ff
commit
d23a264b8a
43 changed files with 625 additions and 505 deletions
|
@ -2,7 +2,6 @@
|
|||
using LBPUnion.ProjectLighthouse.Levels;
|
||||
using LBPUnion.ProjectLighthouse.PlayerData;
|
||||
using LBPUnion.ProjectLighthouse.PlayerData.Profiles;
|
||||
using LBPUnion.ProjectLighthouse.Types;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
|
@ -23,38 +22,35 @@ public class EnterLevelController : ControllerBase
|
|||
[HttpPost("play/user/{slotId}")]
|
||||
public async Task<IActionResult> PlayLevel(int slotId)
|
||||
{
|
||||
User? user = await this.database.UserFromGameRequest(this.Request);
|
||||
if (user == null) return this.StatusCode(403, "");
|
||||
GameToken? token = await this.database.GameTokenFromRequest(this.Request);
|
||||
if (token == null) return this.StatusCode(403, "");
|
||||
|
||||
Slot? slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == slotId);
|
||||
if (slot == null) return this.StatusCode(403, "");
|
||||
|
||||
GameToken? token = await this.database.GameTokenFromRequest(this.Request);
|
||||
if (token == null) return this.StatusCode(403, "");
|
||||
|
||||
GameVersion gameVersion = token.GameVersion;
|
||||
|
||||
IQueryable<VisitedLevel> visited = this.database.VisitedLevels.Where(s => s.SlotId == slotId && s.UserId == user.UserId);
|
||||
IQueryable<VisitedLevel> visited = this.database.VisitedLevels.Where(s => s.SlotId == slotId && s.UserId == token.UserId);
|
||||
VisitedLevel? v;
|
||||
if (!visited.Any())
|
||||
{
|
||||
switch (gameVersion)
|
||||
{
|
||||
case GameVersion.LittleBigPlanet2:
|
||||
case GameVersion.LittleBigPlanetVita:
|
||||
slot.PlaysLBP2Unique++;
|
||||
break;
|
||||
case GameVersion.LittleBigPlanet3:
|
||||
slot.PlaysLBP3Unique++;
|
||||
break;
|
||||
case GameVersion.LittleBigPlanetVita:
|
||||
slot.PlaysLBPVitaUnique++;
|
||||
break;
|
||||
default: return this.BadRequest();
|
||||
}
|
||||
|
||||
v = new VisitedLevel();
|
||||
v.SlotId = slotId;
|
||||
v.UserId = user.UserId;
|
||||
v = new VisitedLevel
|
||||
{
|
||||
SlotId = slotId,
|
||||
UserId = token.UserId,
|
||||
};
|
||||
this.database.VisitedLevels.Add(v);
|
||||
}
|
||||
else
|
||||
|
@ -67,6 +63,7 @@ public class EnterLevelController : ControllerBase
|
|||
switch (gameVersion)
|
||||
{
|
||||
case GameVersion.LittleBigPlanet2:
|
||||
case GameVersion.LittleBigPlanetVita:
|
||||
slot.PlaysLBP2++;
|
||||
v.PlaysLBP2++;
|
||||
break;
|
||||
|
@ -74,12 +71,9 @@ public class EnterLevelController : ControllerBase
|
|||
slot.PlaysLBP3++;
|
||||
v.PlaysLBP3++;
|
||||
break;
|
||||
case GameVersion.LittleBigPlanetVita:
|
||||
slot.PlaysLBPVita++;
|
||||
v.PlaysLBPVita++;
|
||||
break;
|
||||
case GameVersion.LittleBigPlanetPSP: throw new NotImplementedException();
|
||||
case GameVersion.Unknown:
|
||||
case GameVersion.LittleBigPlanet1:
|
||||
default:
|
||||
return this.BadRequest();
|
||||
}
|
||||
|
@ -93,21 +87,23 @@ public class EnterLevelController : ControllerBase
|
|||
[HttpGet("enterLevel/{id:int}")]
|
||||
public async Task<IActionResult> EnterLevel(int id)
|
||||
{
|
||||
User? user = await this.database.UserFromGameRequest(this.Request);
|
||||
if (user == null) return this.StatusCode(403, "");
|
||||
GameToken? token = await this.database.GameTokenFromRequest(this.Request);
|
||||
if (token == null) return this.StatusCode(403, "");
|
||||
|
||||
Slot? slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == id);
|
||||
if (slot == null) return this.NotFound();
|
||||
|
||||
IQueryable<VisitedLevel> visited = this.database.VisitedLevels.Where(s => s.SlotId == id && s.UserId == user.UserId);
|
||||
IQueryable<VisitedLevel> visited = this.database.VisitedLevels.Where(s => s.SlotId == id && s.UserId == token.UserId);
|
||||
VisitedLevel? v;
|
||||
if (!visited.Any())
|
||||
{
|
||||
slot.PlaysLBP1Unique++;
|
||||
|
||||
v = new VisitedLevel();
|
||||
v.SlotId = id;
|
||||
v.UserId = user.UserId;
|
||||
v = new VisitedLevel
|
||||
{
|
||||
SlotId = id,
|
||||
UserId = token.UserId,
|
||||
};
|
||||
this.database.VisitedLevels.Add(v);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -86,9 +86,9 @@ public class MatchController : ControllerBase
|
|||
|
||||
// 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)
|
||||
#else
|
||||
if (matchData is FindBestRoom diveInData && MatchHelper.UserLocations.Count > 1)
|
||||
else if (matchData is FindBestRoom diveInData && MatchHelper.UserLocations.Count > 1)
|
||||
#endif
|
||||
{
|
||||
FindBestRoomResponse? response = RoomHelper.FindBestRoom
|
||||
|
@ -102,7 +102,7 @@ public class MatchController : ControllerBase
|
|||
return this.Ok($"[{{\"StatusCode\":200}},{serialized}]");
|
||||
}
|
||||
|
||||
if (matchData is CreateRoom createRoom && MatchHelper.UserLocations.Count >= 1)
|
||||
else if (matchData is CreateRoom createRoom && MatchHelper.UserLocations.Count >= 1)
|
||||
{
|
||||
List<int> users = new();
|
||||
foreach (string playerUsername in createRoom.Players)
|
||||
|
@ -117,7 +117,7 @@ public class MatchController : ControllerBase
|
|||
RoomHelper.CreateRoom(users, gameToken.GameVersion, gameToken.Platform, createRoom.RoomSlot);
|
||||
}
|
||||
|
||||
if (matchData is UpdatePlayersInRoom updatePlayersInRoom)
|
||||
else if (matchData is UpdatePlayersInRoom updatePlayersInRoom)
|
||||
{
|
||||
Room? room = RoomHelper.Rooms.FirstOrDefault(r => r.HostId == user.UserId);
|
||||
|
||||
|
@ -133,7 +133,7 @@ public class MatchController : ControllerBase
|
|||
}
|
||||
|
||||
room.PlayerIds = users.Select(u => u.UserId).ToList();
|
||||
RoomHelper.CleanupRooms(null, room);
|
||||
await RoomHelper.CleanupRooms(null, room);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue