ProjectLighthouse/ProjectLighthouse.Servers.GameServer/Controllers/StatisticsController.cs
Josh 0af064ad1e
Some checks failed
Continuous Integration / Build & Test (map[database:true fullName:ubuntu-latest prettyName:Linux webTest:true]) (push) Has been cancelled
Upload Translations to Crowdin / crowdin-sync (push) Has been cancelled
Build Docker Image / Build and Publish (push) Has been cancelled
Implement player count per platform and player list API endpoints (#1014)
* Implement player count per platform and player list API endpoints

* Fix inconsistencies in the XML documentation

* Update PlayerListResponse.cs
2024-08-29 01:17:03 +00:00

52 lines
2 KiB
C#

using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Helpers;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using LBPUnion.ProjectLighthouse.Extensions;
using LBPUnion.ProjectLighthouse.Filter;
using LBPUnion.ProjectLighthouse.Filter.Filters;
using LBPUnion.ProjectLighthouse.Servers.GameServer.Extensions;
using LBPUnion.ProjectLighthouse.Types.Serialization;
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers;
[ApiController]
[Authorize]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/plain")]
public class StatisticsController : ControllerBase
{
private readonly DatabaseContext database;
public StatisticsController(DatabaseContext database)
{
this.database = database;
}
[HttpGet("playersInPodCount")]
public IActionResult PlayersInPodCount() => this.Ok(StatisticsHelper.RoomCountForPlatform(this.GetToken().Platform).ToString());
[HttpGet("totalPlayerCount")]
public async Task<IActionResult> TotalPlayerCount() =>
this.Ok((await StatisticsHelper.RecentMatches(this.database, l => l.GameVersion == this.GetToken().GameVersion)).ToString());
[HttpGet("planetStats")]
[Produces("text/xml")]
public async Task<IActionResult> PlanetStats()
{
SlotQueryBuilder defaultFilter = this.GetDefaultFilters(this.GetToken());
int totalSlotCount = await StatisticsHelper.SlotCount(this.database, defaultFilter);
defaultFilter.AddFilter(new TeamPickFilter());
int mmPicksCount = await StatisticsHelper.SlotCount(this.database, defaultFilter);
return this.Ok(new PlanetStatsResponse(totalSlotCount, mmPicksCount));
}
[HttpGet("planetStats/totalLevelCount")]
public async Task<IActionResult> TotalLevelCount()
{
SlotQueryBuilder defaultFilter = this.GetDefaultFilters(this.GetToken());
int totalSlotCount = await StatisticsHelper.SlotCount(this.database, defaultFilter);
return this.Ok(totalSlotCount.ToString());
}
}