update top level client count stats to support filtering per game

This commit is contained in:
RaidMax
2023-04-19 19:55:33 -05:00
parent c53e0de7d0
commit 92992dfb13
8 changed files with 126 additions and 87 deletions

View File

@ -2,6 +2,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Data.Models;
using Microsoft.AspNetCore.Mvc;
using SharedLibraryCore;
using SharedLibraryCore.Interfaces;
@ -21,13 +22,13 @@ public class Info : BaseController
}
[HttpGet]
public async Task<IActionResult> Get(int period = 24, CancellationToken token = default)
public async Task<IActionResult> Get(int period = 24, Reference.Game? game = null, CancellationToken token = default)
{
// todo: this is hardcoded currently because the cache doesn't take into consideration the duration, so
// we could impact the webfront usage too
var duration = TimeSpan.FromHours(24);
var (totalClients, totalRecentClients) =
await _serverDataViewer.ClientCountsAsync(duration, token);
await _serverDataViewer.ClientCountsAsync(duration, game, token);
var (maxConcurrent, maxConcurrentTime) = await _serverDataViewer.MaxConcurrentClientsAsync(overPeriod: duration, token: token);
var response = new InfoResponse
{

View File

@ -7,8 +7,8 @@ using SharedLibraryCore.Interfaces;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Data.Models;
using Microsoft.Extensions.Logging;
using static SharedLibraryCore.Server;
using ILogger = Microsoft.Extensions.Logging.ILogger;
namespace WebfrontCore.Controllers
@ -27,26 +27,31 @@ namespace WebfrontCore.Controllers
_serverDataViewer = serverDataViewer;
}
public async Task<IActionResult> Index(Game? game = null, CancellationToken cancellationToken = default)
public async Task<IActionResult> Index(Reference.Game? game = null,
CancellationToken cancellationToken = default)
{
ViewBag.Description = Localization["WEBFRONT_DESCRIPTION_HOME"];
ViewBag.Title = Localization["WEBFRONT_HOME_TITLE"];
ViewBag.Keywords = Localization["WEBFRONT_KEWORDS_HOME"];
var servers = Manager.GetServers().Where(_server => !game.HasValue || _server.GameName == game);
var (clientCount, time) = await _serverDataViewer.MaxConcurrentClientsAsync(token: cancellationToken);
var (count, recentCount) = await _serverDataViewer.ClientCountsAsync(token: cancellationToken);
var servers = Manager.GetServers().Where(server => game is null || server.GameName == (Server.Game?)game)
.ToList();
var (clientCount, time) =
await _serverDataViewer.MaxConcurrentClientsAsync(gameCode: game, token: cancellationToken);
var (count, recentCount) =
await _serverDataViewer.ClientCountsAsync(gameCode: game, token: cancellationToken);
var model = new IW4MAdminInfo()
var model = new IW4MAdminInfo
{
TotalAvailableClientSlots = servers.Sum(_server => _server.MaxClients),
TotalOccupiedClientSlots = servers.SelectMany(_server => _server.GetClientsAsList()).Count(),
TotalAvailableClientSlots = servers.Sum(server => server.MaxClients),
TotalOccupiedClientSlots = servers.SelectMany(server => server.GetClientsAsList()).Count(),
TotalClientCount = count,
RecentClientCount = recentCount,
MaxConcurrentClients = clientCount ?? 0,
MaxConcurrentClientsTime = time ?? DateTime.UtcNow,
Game = game,
ActiveServerGames = Manager.GetServers().Select(_server => _server.GameName).Distinct().ToArray()
ActiveServerGames = Manager.GetServers().Select(server => (Reference.Game)server.GameName).Distinct()
.ToArray()
};
return View(model);