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;
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
private readonly IConfigurationHandler<StatsConfiguration> _configurationHandler;
|
|
|
|
|
|
|
|
|
|
public TopPlayersViewComponent(IConfigurationHandler<StatsConfiguration> configurationHandler)
|
|
|
|
|
{
|
|
|
|
|
_configurationHandler = configurationHandler;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IViewComponentResult> InvokeAsync(int count, int offset, long? serverId = null)
|
|
|
|
|
{
|
|
|
|
|
if (serverId == 0)
|
|
|
|
|
{
|
|
|
|
|
serverId = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var server = Plugin.ServerManager.GetServers().FirstOrDefault(_server => _server.EndPoint == serverId);
|
|
|
|
|
|
|
|
|
|
if (server != null)
|
|
|
|
|
{
|
|
|
|
|
serverId = StatManager.GetIdForServer(server);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-01-22 14:30:32 -05:00
|
|
|
|
ViewBag.UseNewStats = _configurationHandler.Configuration()?.EnableAdvancedMetrics ?? true;
|
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
|
2021-03-22 12:09:25 -04:00
|
|
|
|
? await Plugin.Manager.GetNewTopStats(offset, count, serverId)
|
|
|
|
|
: await Plugin.Manager.GetTopStats(offset, count, serverId));
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-22 14:30:32 -05:00
|
|
|
|
}
|