mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-23 21:51:29 +00:00
Implement story mode player counts endpoint (#400)
This commit is contained in:
parent
2ab1e72037
commit
6c989e7923
2 changed files with 38 additions and 6 deletions
|
@ -90,6 +90,31 @@ public class SlotsController : ControllerBase
|
|||
return this.Ok(LbpSerializer.TaggedStringElement("slots", serialized, "total", serializedSlots.Count));
|
||||
}
|
||||
|
||||
[HttpGet("slots/developer")]
|
||||
public async Task<IActionResult> StoryPlayers()
|
||||
{
|
||||
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, "");
|
||||
|
||||
List<int> activeSlotIds = RoomHelper.Rooms.Where(r => r.Slot.SlotType == SlotType.Developer).Select(r => r.Slot.SlotId).ToList();
|
||||
|
||||
List<string> serializedSlots = new();
|
||||
|
||||
foreach (int id in activeSlotIds)
|
||||
{
|
||||
int placeholderSlotId = await SlotHelper.GetPlaceholderSlotId(this.database, id, SlotType.Developer);
|
||||
Slot slot = await this.database.Slots.FirstAsync(s => s.SlotId == placeholderSlotId);
|
||||
serializedSlots.Add(slot.SerializeDevSlot(false));
|
||||
}
|
||||
|
||||
string serialized = serializedSlots.Aggregate(string.Empty, (current, slot) => current + slot);
|
||||
|
||||
return this.Ok(LbpSerializer.StringElement("slots", serialized));
|
||||
}
|
||||
|
||||
[HttpGet("s/developer/{id:int}")]
|
||||
public async Task<IActionResult> SDev(int id)
|
||||
{
|
||||
|
|
|
@ -242,19 +242,26 @@ public class Slot
|
|||
LbpSerializer.StringElement("sizeOfResources", this.Resources.Sum(FileHelper.ResourceSize));
|
||||
}
|
||||
|
||||
public string SerializeDevSlot()
|
||||
public string SerializeDevSlot(bool includeExtras = true)
|
||||
{
|
||||
int comments = this.database.Comments.Count(c => c.Type == CommentType.Level && c.TargetId == this.SlotId);
|
||||
|
||||
int photos = this.database.Photos.Count(c => c.SlotId == this.SlotId);
|
||||
int comments = 0, photos = 0;
|
||||
if (includeExtras)
|
||||
{
|
||||
comments = this.database.Comments.Count(c => c.Type == CommentType.Level && c.TargetId == this.SlotId);
|
||||
|
||||
photos = this.database.Photos.Count(c => c.SlotId == this.SlotId);
|
||||
}
|
||||
|
||||
int players = RoomHelper.Rooms
|
||||
.Where(r => r.Slot.SlotType == SlotType.Developer && r.Slot.SlotId == this.InternalSlotId)
|
||||
.Sum(r => r.PlayerIds.Count);
|
||||
|
||||
string slotData = LbpSerializer.StringElement("id", this.InternalSlotId) +
|
||||
LbpSerializer.StringElement("playerCount", players) +
|
||||
LbpSerializer.StringElement("commentCount", comments) +
|
||||
LbpSerializer.StringElement("playerCount", players);
|
||||
|
||||
if(includeExtras)
|
||||
slotData += LbpSerializer.StringElement("commentCount", comments) +
|
||||
LbpSerializer.StringElement("photoCount", photos);
|
||||
|
||||
return LbpSerializer.TaggedStringElement("slot", slotData, "type", "developer");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue