IW4M-Admin/WebfrontCore/ViewComponents/TopPlayersViewComponent.cs

39 lines
1.3 KiB
C#
Raw Permalink Normal View History

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