2021-03-22 12:09:25 -04:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using IW4MAdmin.Plugins.Stats;
|
|
|
|
|
using IW4MAdmin.Plugins.Stats.Helpers;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2023-04-04 23:10:37 -04:00
|
|
|
|
using SharedLibraryCore.Interfaces;
|
2021-11-23 18:26:33 -05:00
|
|
|
|
using Stats.Config;
|
2021-03-22 12:09:25 -04:00
|
|
|
|
|
|
|
|
|
namespace WebfrontCore.ViewComponents
|
|
|
|
|
{
|
|
|
|
|
public class TopPlayersViewComponent : ViewComponent
|
|
|
|
|
{
|
2022-01-28 18:28:49 -05:00
|
|
|
|
private readonly StatsConfiguration _config;
|
2023-04-04 23:10:37 -04:00
|
|
|
|
private readonly StatManager _statManager;
|
2021-03-22 12:09:25 -04:00
|
|
|
|
|
2023-04-04 23:10:37 -04:00
|
|
|
|
public TopPlayersViewComponent(StatsConfiguration config, StatManager statManager)
|
2021-03-22 12:09:25 -04:00
|
|
|
|
{
|
2022-01-28 18:28:49 -05:00
|
|
|
|
_config = config;
|
2023-04-04 23:10:37 -04:00
|
|
|
|
_statManager = statManager;
|
2021-03-22 12:09:25 -04:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-19 19:43:58 -04:00
|
|
|
|
public async Task<IViewComponentResult> InvokeAsync(int count, int offset, string serverEndpoint = null)
|
2021-03-22 12:09:25 -04:00
|
|
|
|
{
|
2022-04-19 19:43:58 -04:00
|
|
|
|
var server = Plugin.ServerManager.GetServers()
|
2023-04-04 23:10:37 -04:00
|
|
|
|
.FirstOrDefault(server => server.Id == serverEndpoint) as IGameServer;
|
2021-03-22 12:09:25 -04:00
|
|
|
|
|
2023-04-04 23:10:37 -04:00
|
|
|
|
var serverId = server?.LegacyDatabaseId;
|
2021-03-22 12:09:25 -04:00
|
|
|
|
|
2022-01-28 18:28:49 -05:00
|
|
|
|
ViewBag.UseNewStats = _config?.EnableAdvancedMetrics ?? true;
|
2023-04-04 23:10:37 -04:00
|
|
|
|
ViewBag.SelectedServerName = server?.ServerName;
|
2022-04-19 19:43:58 -04:00
|
|
|
|
|
2021-03-22 12:09:25 -04:00
|
|
|
|
return View("~/Views/Client/Statistics/Components/TopPlayers/_List.cshtml",
|
2022-01-22 14:30:32 -05:00
|
|
|
|
ViewBag.UseNewStats
|
2023-04-04 23:10:37 -04:00
|
|
|
|
? await _statManager.GetNewTopStats(offset, count, serverId)
|
|
|
|
|
: await _statManager.GetTopStats(offset, count, serverId));
|
2021-03-22 12:09:25 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-22 14:30:32 -05:00
|
|
|
|
}
|