update controllers to use DI stat manager
This commit is contained in:
parent
da54c5d327
commit
6fa172d757
@ -30,10 +30,11 @@ namespace IW4MAdmin.Plugins.Web.StatsWeb.Controllers
|
|||||||
private readonly IDatabaseContextFactory _contextFactory;
|
private readonly IDatabaseContextFactory _contextFactory;
|
||||||
private readonly StatsConfiguration _config;
|
private readonly StatsConfiguration _config;
|
||||||
private readonly IServerDataViewer _serverDataViewer;
|
private readonly IServerDataViewer _serverDataViewer;
|
||||||
|
private readonly StatManager _statManager;
|
||||||
|
|
||||||
public StatsController(ILogger<StatsController> logger, IManager manager, IResourceQueryHelper<ChatSearchQuery,
|
public StatsController(ILogger<StatsController> logger, IManager manager, IResourceQueryHelper<ChatSearchQuery,
|
||||||
MessageResponse> resourceQueryHelper, ITranslationLookup translationLookup,
|
MessageResponse> resourceQueryHelper, ITranslationLookup translationLookup,
|
||||||
IDatabaseContextFactory contextFactory, StatsConfiguration config, IServerDataViewer serverDataViewer) : base(manager)
|
IDatabaseContextFactory contextFactory, StatsConfiguration config, IServerDataViewer serverDataViewer, StatManager statManager) : base(manager)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_manager = manager;
|
_manager = manager;
|
||||||
@ -42,6 +43,7 @@ namespace IW4MAdmin.Plugins.Web.StatsWeb.Controllers
|
|||||||
_contextFactory = contextFactory;
|
_contextFactory = contextFactory;
|
||||||
_config = config;
|
_config = config;
|
||||||
_serverDataViewer = serverDataViewer;
|
_serverDataViewer = serverDataViewer;
|
||||||
|
_statManager = statManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
@ -52,23 +54,23 @@ namespace IW4MAdmin.Plugins.Web.StatsWeb.Controllers
|
|||||||
ViewBag.Localization = _translationLookup;
|
ViewBag.Localization = _translationLookup;
|
||||||
ViewBag.SelectedServerId = serverId;
|
ViewBag.SelectedServerId = serverId;
|
||||||
|
|
||||||
var server = _manager.GetServers().FirstOrDefault(server => server.ToString() == serverId);
|
var server = _manager.GetServers().FirstOrDefault(server => server.Id == serverId) as IGameServer;
|
||||||
long? matchedServerId = null;
|
long? matchedServerId = null;
|
||||||
|
|
||||||
if (server != null)
|
if (server != null)
|
||||||
{
|
{
|
||||||
matchedServerId = StatManager.GetIdForServer(server);
|
matchedServerId = server.LegacyDatabaseId;
|
||||||
}
|
}
|
||||||
|
|
||||||
ViewBag.TotalRankedClients = await _serverDataViewer.RankedClientsCountAsync(matchedServerId, token);
|
ViewBag.TotalRankedClients = await _serverDataViewer.RankedClientsCountAsync(matchedServerId, token);
|
||||||
ViewBag.ServerId = matchedServerId;
|
ViewBag.ServerId = matchedServerId;
|
||||||
|
|
||||||
return View("~/Views/Client/Statistics/Index.cshtml", _manager.GetServers()
|
return View("~/Views/Client/Statistics/Index.cshtml", _manager.GetServers()
|
||||||
.Select(server => new ServerInfo
|
.Select(selectedServer => new ServerInfo
|
||||||
{
|
{
|
||||||
Name = server.Hostname,
|
Name = selectedServer.Hostname,
|
||||||
IPAddress = server.IP,
|
IPAddress = selectedServer.ListenAddress,
|
||||||
Port = server.Port
|
Port = selectedServer.ListenPort
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,16 +83,14 @@ namespace IW4MAdmin.Plugins.Web.StatsWeb.Controllers
|
|||||||
serverId = null;
|
serverId = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var server = _manager.GetServers().FirstOrDefault(_server => _server.EndPoint == serverId);
|
if (_manager.GetServers().FirstOrDefault(activeServer => activeServer.EndPoint == serverId) is IGameServer server)
|
||||||
|
|
||||||
if (server != null)
|
|
||||||
{
|
{
|
||||||
serverId = StatManager.GetIdForServer(server);
|
serverId = server.LegacyDatabaseId;
|
||||||
}
|
}
|
||||||
|
|
||||||
var results = _config?.EnableAdvancedMetrics ?? true
|
var results = _config?.EnableAdvancedMetrics ?? true
|
||||||
? await Plugin.Manager.GetNewTopStats(offset, count, serverId)
|
? await _statManager.GetNewTopStats(offset, count, serverId)
|
||||||
: await Plugin.Manager.GetTopStats(offset, count, serverId);
|
: await _statManager.GetTopStats(offset, count, serverId);
|
||||||
|
|
||||||
// this returns an empty result so we know to stale the loader
|
// this returns an empty result so we know to stale the loader
|
||||||
if (results.Count == 0 && offset > 0)
|
if (results.Count == 0 && offset > 0)
|
||||||
@ -205,7 +205,7 @@ namespace IW4MAdmin.Plugins.Web.StatsWeb.Controllers
|
|||||||
.Include(s => s.CurrentViewAngle)
|
.Include(s => s.CurrentViewAngle)
|
||||||
.Include(s => s.Server)
|
.Include(s => s.Server)
|
||||||
.Include(s => s.PredictedViewAngles)
|
.Include(s => s.PredictedViewAngles)
|
||||||
.ThenInclude(_angles => _angles.Vector)
|
.ThenInclude(angles => angles.Vector)
|
||||||
.OrderBy(s => s.When)
|
.OrderBy(s => s.When)
|
||||||
.ThenBy(s => s.Hits);
|
.ThenBy(s => s.Hits);
|
||||||
|
|
||||||
|
@ -22,36 +22,36 @@ namespace WebfrontCore.Controllers
|
|||||||
[ResponseCache(NoStore = true, Duration = 0)]
|
[ResponseCache(NoStore = true, Duration = 0)]
|
||||||
public IActionResult ClientActivity(long id)
|
public IActionResult ClientActivity(long id)
|
||||||
{
|
{
|
||||||
var s = Manager.GetServers().FirstOrDefault(_server => _server.EndPoint == id);
|
var matchingServer = Manager.GetServers().FirstOrDefault(server => server.EndPoint == id);
|
||||||
|
|
||||||
if (s == null)
|
if (matchingServer == null)
|
||||||
{
|
{
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
var serverInfo = new ServerInfo
|
var serverInfo = new ServerInfo
|
||||||
{
|
{
|
||||||
Name = s.Hostname,
|
Name = matchingServer.Hostname,
|
||||||
ID = s.EndPoint,
|
ID = matchingServer.EndPoint,
|
||||||
Port = s.Port,
|
Port = matchingServer.ListenPort,
|
||||||
Map = s.CurrentMap.Alias,
|
Map = matchingServer.CurrentMap?.Alias,
|
||||||
Game = (Reference.Game)s.GameName,
|
Game = (Reference.Game)matchingServer.GameName,
|
||||||
ClientCount = s.Clients.Count(client => client != null),
|
ClientCount = matchingServer.ClientNum,
|
||||||
MaxClients = s.MaxClients,
|
MaxClients = matchingServer.MaxClients,
|
||||||
GameType = s.GametypeName,
|
GameType = matchingServer.GametypeName,
|
||||||
Players = s.GetClientsAsList()
|
Players = matchingServer.GetClientsAsList()
|
||||||
.Select(p => new PlayerInfo
|
.Select(client => new PlayerInfo
|
||||||
{
|
{
|
||||||
Name = p.Name,
|
Name = client.Name,
|
||||||
ClientId = p.ClientId,
|
ClientId = client.ClientId,
|
||||||
Level = p.Level.ToLocalizedLevelName(),
|
Level = client.Level.ToLocalizedLevelName(),
|
||||||
LevelInt = (int) p.Level,
|
LevelInt = (int)client.Level,
|
||||||
ZScore = p.GetAdditionalProperty<EFClientStatistics>(StatManager
|
ZScore = client.GetAdditionalProperty<EFClientStatistics>(StatManager
|
||||||
.CLIENT_STATS_KEY)?.ZScore
|
.CLIENT_STATS_KEY)?.ZScore
|
||||||
}).ToList(),
|
}).ToList(),
|
||||||
ChatHistory = s.ChatHistory.ToList(),
|
ChatHistory = matchingServer.ChatHistory.ToList(),
|
||||||
ClientHistory = s.ClientHistory,
|
ClientHistory = matchingServer.ClientHistory,
|
||||||
IsPasswordProtected = !string.IsNullOrEmpty(s.GamePassword)
|
IsPasswordProtected = !string.IsNullOrEmpty(matchingServer.GamePassword)
|
||||||
};
|
};
|
||||||
return PartialView("_ClientActivity", serverInfo);
|
return PartialView("_ClientActivity", serverInfo);
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ using System.Linq;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Data.Models;
|
using Data.Models;
|
||||||
using Data.Models.Client.Stats;
|
using Data.Models.Client.Stats;
|
||||||
|
using IW4MAdmin.Plugins.Stats.Helpers;
|
||||||
using SharedLibraryCore.Configuration;
|
using SharedLibraryCore.Configuration;
|
||||||
using SharedLibraryCore.Interfaces;
|
using SharedLibraryCore.Interfaces;
|
||||||
using static SharedLibraryCore.Server;
|
using static SharedLibraryCore.Server;
|
||||||
@ -68,10 +69,10 @@ namespace WebfrontCore.ViewComponents
|
|||||||
{
|
{
|
||||||
Name = server.Hostname,
|
Name = server.Hostname,
|
||||||
ID = server.EndPoint,
|
ID = server.EndPoint,
|
||||||
Port = server.Port,
|
Port = server.ListenPort,
|
||||||
Map = server.CurrentMap.Alias,
|
Map = server.CurrentMap?.Alias,
|
||||||
Game = (Reference.Game)server.GameName,
|
Game = (Reference.Game)server.GameName,
|
||||||
ClientCount = server.Clients.Count(client => client != null),
|
ClientCount = server.ClientNum,
|
||||||
MaxClients = server.MaxClients,
|
MaxClients = server.MaxClients,
|
||||||
GameType = server.GametypeName,
|
GameType = server.GametypeName,
|
||||||
ClientHistory = new ClientHistoryInfo
|
ClientHistory = new ClientHistoryInfo
|
||||||
@ -80,15 +81,14 @@ namespace WebfrontCore.ViewComponents
|
|||||||
ClientCounts = counts.ToList()
|
ClientCounts = counts.ToList()
|
||||||
},
|
},
|
||||||
Players = server.GetClientsAsList()
|
Players = server.GetClientsAsList()
|
||||||
.Select(p => new PlayerInfo()
|
.Select(client => new PlayerInfo
|
||||||
{
|
{
|
||||||
Name = p.Name,
|
Name = client.Name,
|
||||||
ClientId = p.ClientId,
|
ClientId = client.ClientId,
|
||||||
Level = p.Level.ToLocalizedLevelName(),
|
Level = client.Level.ToLocalizedLevelName(),
|
||||||
LevelInt = (int) p.Level,
|
LevelInt = (int)client.Level,
|
||||||
Tag = p.Tag,
|
Tag = client.Tag,
|
||||||
ZScore = p.GetAdditionalProperty<EFClientStatistics>(IW4MAdmin.Plugins.Stats.Helpers
|
ZScore = client.GetAdditionalProperty<EFClientStatistics>(StatManager
|
||||||
.StatManager
|
|
||||||
.CLIENT_STATS_KEY)?.ZScore
|
.CLIENT_STATS_KEY)?.ZScore
|
||||||
}).ToList(),
|
}).ToList(),
|
||||||
ChatHistory = server.ChatHistory.ToList(),
|
ChatHistory = server.ChatHistory.ToList(),
|
||||||
@ -97,7 +97,7 @@ namespace WebfrontCore.ViewComponents
|
|||||||
ExternalIPAddress = server.ResolvedIpEndPoint.Address.IsInternal() ? Program.Manager.ExternalIPAddress : server.IP,
|
ExternalIPAddress = server.ResolvedIpEndPoint.Address.IsInternal() ? Program.Manager.ExternalIPAddress : server.IP,
|
||||||
ConnectProtocolUrl = server.EventParser.URLProtocolFormat.FormatExt(
|
ConnectProtocolUrl = server.EventParser.URLProtocolFormat.FormatExt(
|
||||||
server.ResolvedIpEndPoint.Address.IsInternal() ? Program.Manager.ExternalIPAddress : server.IP,
|
server.ResolvedIpEndPoint.Address.IsInternal() ? Program.Manager.ExternalIPAddress : server.IP,
|
||||||
server.Port)
|
server.ListenPort)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ using System.Threading.Tasks;
|
|||||||
using IW4MAdmin.Plugins.Stats;
|
using IW4MAdmin.Plugins.Stats;
|
||||||
using IW4MAdmin.Plugins.Stats.Helpers;
|
using IW4MAdmin.Plugins.Stats.Helpers;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using SharedLibraryCore.Interfaces;
|
||||||
using Stats.Config;
|
using Stats.Config;
|
||||||
|
|
||||||
namespace WebfrontCore.ViewComponents
|
namespace WebfrontCore.ViewComponents
|
||||||
@ -10,26 +11,28 @@ namespace WebfrontCore.ViewComponents
|
|||||||
public class TopPlayersViewComponent : ViewComponent
|
public class TopPlayersViewComponent : ViewComponent
|
||||||
{
|
{
|
||||||
private readonly StatsConfiguration _config;
|
private readonly StatsConfiguration _config;
|
||||||
|
private readonly StatManager _statManager;
|
||||||
|
|
||||||
public TopPlayersViewComponent(StatsConfiguration config)
|
public TopPlayersViewComponent(StatsConfiguration config, StatManager statManager)
|
||||||
{
|
{
|
||||||
_config = config;
|
_config = config;
|
||||||
|
_statManager = statManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IViewComponentResult> InvokeAsync(int count, int offset, string serverEndpoint = null)
|
public async Task<IViewComponentResult> InvokeAsync(int count, int offset, string serverEndpoint = null)
|
||||||
{
|
{
|
||||||
var server = Plugin.ServerManager.GetServers()
|
var server = Plugin.ServerManager.GetServers()
|
||||||
.FirstOrDefault(server => server.ToString() == serverEndpoint);
|
.FirstOrDefault(server => server.Id == serverEndpoint) as IGameServer;
|
||||||
|
|
||||||
var serverId = server is null ? (long?)null : StatManager.GetIdForServer(server);
|
var serverId = server?.LegacyDatabaseId;
|
||||||
|
|
||||||
ViewBag.UseNewStats = _config?.EnableAdvancedMetrics ?? true;
|
ViewBag.UseNewStats = _config?.EnableAdvancedMetrics ?? true;
|
||||||
ViewBag.SelectedServerName = server?.Hostname;
|
ViewBag.SelectedServerName = server?.ServerName;
|
||||||
|
|
||||||
return View("~/Views/Client/Statistics/Components/TopPlayers/_List.cshtml",
|
return View("~/Views/Client/Statistics/Components/TopPlayers/_List.cshtml",
|
||||||
ViewBag.UseNewStats
|
ViewBag.UseNewStats
|
||||||
? await Plugin.Manager.GetNewTopStats(offset, count, serverId)
|
? await _statManager.GetNewTopStats(offset, count, serverId)
|
||||||
: await Plugin.Manager.GetTopStats(offset, count, serverId));
|
: await _statManager.GetTopStats(offset, count, serverId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user