From 4899ef86cc980f6610710c6c19023e701e440295 Mon Sep 17 00:00:00 2001 From: RaidMax Date: Sun, 28 Nov 2021 10:17:56 -0600 Subject: [PATCH] update to show full gametype name on webfront --- Application/IW4MServer.cs | 2 +- SharedLibraryCore/Server.cs | 7 ++++++- WebfrontCore/Controllers/ServerController.cs | 9 ++++++--- WebfrontCore/ViewComponents/ServerListViewComponent.cs | 4 ++-- WebfrontCore/Views/Server/_Server.cshtml | 4 ++-- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Application/IW4MServer.cs b/Application/IW4MServer.cs index e58cce774..a3898d83f 100644 --- a/Application/IW4MServer.cs +++ b/Application/IW4MServer.cs @@ -57,7 +57,7 @@ namespace IW4MAdmin serverConfiguration, serviceProvider.GetRequiredService(), serviceProvider.GetRequiredService(), - serviceProvider.GetRequiredService()) + serviceProvider.GetRequiredService(), serviceProvider) { _translationLookup = lookup; _metaService = metaService; diff --git a/SharedLibraryCore/Server.cs b/SharedLibraryCore/Server.cs index fdd7a2d6c..73cdd3c48 100644 --- a/SharedLibraryCore/Server.cs +++ b/SharedLibraryCore/Server.cs @@ -13,11 +13,13 @@ using SharedLibraryCore.Interfaces; using SharedLibraryCore.Database.Models; using ILogger = Microsoft.Extensions.Logging.ILogger; using Data.Models; +using Microsoft.Extensions.DependencyInjection; namespace SharedLibraryCore { public abstract class Server : IGameServer { + protected readonly DefaultSettings DefaultSettings; public enum Game { COD = -1, @@ -36,7 +38,7 @@ namespace SharedLibraryCore public Server(ILogger logger, SharedLibraryCore.Interfaces.ILogger deprecatedLogger, ServerConfiguration config, IManager mgr, IRConConnectionFactory rconConnectionFactory, - IGameLogReaderFactory gameLogReaderFactory) + IGameLogReaderFactory gameLogReaderFactory, IServiceProvider serviceProvider) { Password = config.Password; IP = config.IPAddress; @@ -55,6 +57,7 @@ namespace SharedLibraryCore this.gameLogReaderFactory = gameLogReaderFactory; RConConnectionFactory = rconConnectionFactory; ServerLogger = logger; + DefaultSettings = serviceProvider.GetRequiredService(); InitializeTokens(); InitializeAutoMessages(); } @@ -307,6 +310,8 @@ namespace SharedLibraryCore public string Hostname { get => ServerConfig.CustomHostname ?? hostname; protected set => hostname = value; } public string Website { get; protected set; } public string Gametype { get; set; } + public string GametypeName => DefaultSettings.Gametypes.FirstOrDefault(gt => gt.Game == GameName)?.Gametypes + ?.FirstOrDefault(gt => gt.Name == Gametype)?.Alias ?? Gametype; public string GamePassword { get; protected set; } public Map CurrentMap { get; set; } public int ClientNum diff --git a/WebfrontCore/Controllers/ServerController.cs b/WebfrontCore/Controllers/ServerController.cs index d9a05ed79..e5681946a 100644 --- a/WebfrontCore/Controllers/ServerController.cs +++ b/WebfrontCore/Controllers/ServerController.cs @@ -4,14 +4,17 @@ using SharedLibraryCore.Dtos; using SharedLibraryCore.Interfaces; using System.Linq; using Data.Models.Client.Stats; +using SharedLibraryCore.Configuration; namespace WebfrontCore.Controllers { public class ServerController : BaseController { - public ServerController(IManager manager) : base(manager) + private readonly DefaultSettings _defaultSettings; + + public ServerController(IManager manager, DefaultSettings defaultSettings) : base(manager) { - + _defaultSettings = defaultSettings; } [HttpGet] @@ -33,7 +36,7 @@ namespace WebfrontCore.Controllers Map = s.CurrentMap.Alias, ClientCount = s.Clients.Count(client => client != null), MaxClients = s.MaxClients, - GameType = s.Gametype, + GameType = s.GametypeName, Players = s.GetClientsAsList() .Select(p => new PlayerInfo { diff --git a/WebfrontCore/ViewComponents/ServerListViewComponent.cs b/WebfrontCore/ViewComponents/ServerListViewComponent.cs index 734112f70..7fcf9b414 100644 --- a/WebfrontCore/ViewComponents/ServerListViewComponent.cs +++ b/WebfrontCore/ViewComponents/ServerListViewComponent.cs @@ -62,7 +62,7 @@ namespace WebfrontCore.ViewComponents Map = server.CurrentMap.Alias, ClientCount = server.Clients.Count(client => client != null), MaxClients = server.MaxClients, - GameType = server.Gametype, + GameType = server.GametypeName, PlayerHistory = server.ClientHistory.ToArray(), Players = server.GetClientsAsList() .Select(p => new PlayerInfo() @@ -92,4 +92,4 @@ namespace WebfrontCore.ViewComponents return View("_List", serverInfo); } } -} \ No newline at end of file +} diff --git a/WebfrontCore/Views/Server/_Server.cshtml b/WebfrontCore/Views/Server/_Server.cshtml index 285345380..b65986c52 100644 --- a/WebfrontCore/Views/Server/_Server.cshtml +++ b/WebfrontCore/Views/Server/_Server.cshtml @@ -21,7 +21,7 @@ @if (!string.IsNullOrEmpty(Model.GameType) && Model.GameType.Length > 1) { - @Model.GameType.ToUpper() + @Model.GameType }
@@ -54,4 +54,4 @@ data-clienthistory='@Html.Raw(Json.Serialize(Model.PlayerHistory))' data-clienthistory-ex='@Html.Raw(Json.Serialize(Model.ClientCountHistory))' data-online="@Model.Online">
- \ No newline at end of file +