mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-29 16:38:37 +00:00
Filter slots to only contain vita slots on vita
This commit is contained in:
parent
a4ecf8628b
commit
2b63952f94
3 changed files with 23 additions and 27 deletions
|
@ -24,6 +24,18 @@ public class SlotsController : ControllerBase
|
|||
this.database = database;
|
||||
}
|
||||
|
||||
private IQueryable<Slot> getSlots(GameVersion gameVersion)
|
||||
{
|
||||
IQueryable<Slot> 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<IActionResult> 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<Slot> 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<Slot> 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<Slot> slots = this.database.Slots.Where(s => s.GameVersion <= gameVersion)
|
||||
IQueryable<Slot> 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<Slot> 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<Slot> slots = this.getSlots(gameVersion).OrderBy(_ => EF.Functions.Random()).Take(Math.Min(pageSize, 30));
|
||||
|
||||
string response = slots.Aggregate(string.Empty, (current, slot) => current + slot.Serialize());
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@
|
|||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</EmbeddedResource>
|
||||
<None Remove="recent-activity.xml"/>
|
||||
<None Remove="r.tar.gz"/>
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
|
||||
|
|
|
@ -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[]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue