diff --git a/ProjectLighthouse/Controllers/GameApi/Slots/SlotsController.cs b/ProjectLighthouse/Controllers/GameApi/Slots/SlotsController.cs index 5cd7247a..d297fd2a 100644 --- a/ProjectLighthouse/Controllers/GameApi/Slots/SlotsController.cs +++ b/ProjectLighthouse/Controllers/GameApi/Slots/SlotsController.cs @@ -24,6 +24,18 @@ public class SlotsController : ControllerBase this.database = database; } + private IQueryable getSlots(GameVersion gameVersion) + { + IQueryable query = this.database.Slots.Include(s => s.Creator).Include(s => s.Location); + + if (gameVersion == GameVersion.LittleBigPlanetVita || gameVersion == GameVersion.LittleBigPlanetPSP || gameVersion == GameVersion.Unknown) + { + return query.Where(s => s.GameVersion == gameVersion); + } + + return query.Where(s => s.GameVersion <= gameVersion); + } + [HttpGet("slots/by")] public async Task SlotsBy([FromQuery] string u, [FromQuery] int pageStart, [FromQuery] int pageSize) { @@ -37,9 +49,8 @@ public class SlotsController : ControllerBase string response = Enumerable.Aggregate ( - this.database.Slots.Where(s => s.GameVersion <= gameVersion) - .Include(s => s.Creator) - .Include(s => s.Location) + this.getSlots + (gameVersion) .Where(s => s.Creator!.Username == user.Username) .Skip(pageStart - 1) .Take(Math.Min(pageSize, ServerSettings.Instance.EntitledSlots)), @@ -77,10 +88,7 @@ public class SlotsController : ControllerBase GameVersion gameVersion = token.GameVersion; - Slot? slot = await this.database.Slots.Where(s => s.GameVersion <= gameVersion) - .Include(s => s.Creator) - .Include(s => s.Location) - .FirstOrDefaultAsync(s => s.SlotId == id); + Slot? slot = await this.getSlots(gameVersion).FirstOrDefaultAsync(s => s.SlotId == id); if (slot == null) return this.NotFound(); @@ -121,12 +129,8 @@ public class SlotsController : ControllerBase GameVersion gameVersion = token.GameVersion; - IQueryable slots = this.database.Slots.Where(s => s.GameVersion <= gameVersion) - .Include(s => s.Creator) - .Include(s => s.Location) - .OrderByDescending(s => s.FirstUploaded) - .Skip(pageStart - 1) - .Take(Math.Min(pageSize, 30)); + IQueryable slots = this.getSlots(gameVersion).OrderByDescending(s => s.FirstUploaded).Skip(pageStart - 1).Take(Math.Min(pageSize, 30)); + string response = Enumerable.Aggregate(slots, string.Empty, (current, slot) => current + slot.Serialize()); return this.Ok @@ -156,10 +160,8 @@ public class SlotsController : ControllerBase GameVersion gameVersion = token.GameVersion; - IQueryable slots = this.database.Slots.Where(s => s.GameVersion <= gameVersion) + IQueryable slots = this.getSlots(gameVersion) .Where(s => s.TeamPick) - .Include(s => s.Creator) - .Include(s => s.Location) .OrderByDescending(s => s.LastUpdated) .Skip(pageStart - 1) .Take(Math.Min(pageSize, 30)); @@ -192,11 +194,7 @@ public class SlotsController : ControllerBase GameVersion gameVersion = token.GameVersion; - IEnumerable slots = this.database.Slots.Where(s => s.GameVersion <= gameVersion) - .Include(s => s.Creator) - .Include(s => s.Location) - .OrderBy(_ => EF.Functions.Random()) - .Take(Math.Min(pageSize, 30)); + IEnumerable slots = this.getSlots(gameVersion).OrderBy(_ => EF.Functions.Random()).Take(Math.Min(pageSize, 30)); string response = slots.Aggregate(string.Empty, (current, slot) => current + slot.Serialize()); diff --git a/ProjectLighthouse/ProjectLighthouse.csproj b/ProjectLighthouse/ProjectLighthouse.csproj index dab4a803..13def370 100644 --- a/ProjectLighthouse/ProjectLighthouse.csproj +++ b/ProjectLighthouse/ProjectLighthouse.csproj @@ -48,6 +48,7 @@ Always + diff --git a/ProjectLighthouse/Types/User.cs b/ProjectLighthouse/Types/User.cs index 34113c26..be237d02 100644 --- a/ProjectLighthouse/Types/User.cs +++ b/ProjectLighthouse/Types/User.cs @@ -11,7 +11,6 @@ namespace LBPUnion.ProjectLighthouse.Types; public class User { - public readonly ClientsConnected ClientsConnected = new(); public int UserId { get; set; } public string Username { get; set; } @@ -172,7 +171,7 @@ public class User { string user = LbpSerializer.TaggedStringElement("npHandle", this.Username, "icon", this.IconHash) + LbpSerializer.StringElement("game", this.Game) + - this.SerializeSlots(gameVersion == GameVersion.LittleBigPlanetVita) + + this.SerializeSlots(gameVersion) + LbpSerializer.StringElement("lists", this.Lists) + LbpSerializer.StringElement("lists_quota", ServerSettings.Instance.ListsQuota) + // technically not a part of the user but LBP expects it LbpSerializer.StringElement("biography", this.Biography) + @@ -192,7 +191,6 @@ public class User LbpSerializer.StringElement("yay2", this.YayHash) + LbpSerializer.StringElement("boo2", this.BooHash) + LbpSerializer.StringElement("meh2", this.MehHash); - this.ClientsConnected.Serialize(); return LbpSerializer.TaggedStringElement("user", user, "type", "user"); } @@ -225,17 +223,16 @@ public class User private static readonly string[] slotTypes = { -// "lbp1", "lbp2", "lbp3", "crossControl", }; - private string SerializeSlots(bool isVita = false) + private string SerializeSlots(GameVersion gameVersion) { string slots = string.Empty; string[] slotTypesLocal; - if (isVita) + if (gameVersion == GameVersion.LittleBigPlanetVita) { slots += LbpSerializer.StringElement("lbp2UsedSlots", this.GetUsedSlotsForGame(GameVersion.LittleBigPlanetVita)); slotTypesLocal = new[]