2021-03-22 12:09:25 -04:00
|
|
|
|
using System.Linq;
|
2022-06-09 10:56:41 -04:00
|
|
|
|
using System.Threading;
|
2021-03-22 12:09:25 -04:00
|
|
|
|
using System.Threading.Tasks;
|
2022-06-09 10:56:41 -04:00
|
|
|
|
using IW4MAdmin.Plugins.Stats.Helpers;
|
2021-03-22 12:09:25 -04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
using SharedLibraryCore.Configuration;
|
|
|
|
|
using SharedLibraryCore.Interfaces;
|
|
|
|
|
using Stats.Dtos;
|
|
|
|
|
|
|
|
|
|
namespace WebfrontCore.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Route("clientstatistics")]
|
|
|
|
|
public class ClientStatisticsController : BaseController
|
|
|
|
|
{
|
|
|
|
|
private IResourceQueryHelper<StatsInfoRequest, AdvancedStatsInfo> _queryHelper;
|
|
|
|
|
private readonly DefaultSettings _defaultConfig;
|
2022-06-09 10:56:41 -04:00
|
|
|
|
private readonly IServerDataViewer _serverDataViewer;
|
2021-03-22 12:09:25 -04:00
|
|
|
|
|
|
|
|
|
public ClientStatisticsController(IManager manager,
|
|
|
|
|
IResourceQueryHelper<StatsInfoRequest, AdvancedStatsInfo> queryHelper,
|
2022-06-09 10:56:41 -04:00
|
|
|
|
DefaultSettings defaultConfig, IServerDataViewer serverDataViewer) : base(manager)
|
2021-03-22 12:09:25 -04:00
|
|
|
|
{
|
|
|
|
|
_queryHelper = queryHelper;
|
2022-01-28 18:28:49 -05:00
|
|
|
|
_defaultConfig = defaultConfig;
|
2022-06-09 10:56:41 -04:00
|
|
|
|
_serverDataViewer = serverDataViewer;
|
2021-03-22 12:09:25 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet("{id:int}/advanced")]
|
2022-06-09 10:56:41 -04:00
|
|
|
|
public async Task<IActionResult> Advanced(int id, [FromQuery] string serverId, CancellationToken token = default)
|
2021-03-22 12:09:25 -04:00
|
|
|
|
{
|
|
|
|
|
ViewBag.Config = _defaultConfig.GameStrings;
|
2022-06-09 10:56:41 -04:00
|
|
|
|
var hitInfo = (await _queryHelper.QueryResource(new StatsInfoRequest
|
2021-03-22 12:09:25 -04:00
|
|
|
|
{
|
|
|
|
|
ClientId = id,
|
|
|
|
|
ServerEndpoint = serverId
|
2022-06-15 20:37:34 -04:00
|
|
|
|
}))?.Results?.First();
|
|
|
|
|
|
|
|
|
|
if (hitInfo is null)
|
|
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
2022-06-09 10:56:41 -04:00
|
|
|
|
|
|
|
|
|
var server = Manager.GetServers().FirstOrDefault(server => server.ToString() == serverId);
|
|
|
|
|
long? matchedServerId = null;
|
2021-03-22 12:09:25 -04:00
|
|
|
|
|
2022-06-09 10:56:41 -04:00
|
|
|
|
if (server != null)
|
|
|
|
|
{
|
|
|
|
|
matchedServerId = StatManager.GetIdForServer(server);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hitInfo.TotalRankedClients = await _serverDataViewer.RankedClientsCountAsync(matchedServerId, token);
|
|
|
|
|
|
|
|
|
|
return View("~/Views/Client/Statistics/Advanced.cshtml", hitInfo);
|
2021-03-22 12:09:25 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-28 18:28:49 -05:00
|
|
|
|
}
|