From d0be08629dd09382babb3a7afae12e9563765bba Mon Sep 17 00:00:00 2001 From: RaidMax Date: Fri, 3 Aug 2018 17:10:20 -0500 Subject: [PATCH] add page list to manager so we can inject pages into the layout view --- Application/Manager.cs | 4 +++ Application/PageList.cs | 26 +++++++++++++++++++ Application/Server.cs | 8 +++--- Plugins/Stats/Plugin.cs | 10 +++++++ SharedLibraryCore/Database/DatabaseContext.cs | 2 ++ SharedLibraryCore/Interfaces/IManager.cs | 5 ++++ WebfrontCore/Controllers/BaseController.cs | 11 +++++++- WebfrontCore/ViewModels/Page.cs | 13 ++++++++++ WebfrontCore/Views/Shared/_Layout.cshtml | 6 +++++ 9 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 Application/PageList.cs create mode 100644 WebfrontCore/ViewModels/Page.cs diff --git a/Application/Manager.cs b/Application/Manager.cs index 7f20f6beb..d1a7db1f7 100644 --- a/Application/Manager.cs +++ b/Application/Manager.cs @@ -46,6 +46,7 @@ namespace IW4MAdmin.Application EventApi Api; GameEventHandler Handler; ManualResetEventSlim OnEvent; + readonly IPageList PageList; private ApplicationManager() { @@ -63,6 +64,7 @@ namespace IW4MAdmin.Application ConfigHandler = new BaseConfigurationHandler("IW4MAdminSettings"); StartTime = DateTime.UtcNow; OnEvent = new ManualResetEventSlim(); + PageList = new PageList(); } public IList GetServers() @@ -519,5 +521,7 @@ namespace IW4MAdmin.Application } public IList GetPluginAssemblies() => SharedLibraryCore.Plugins.PluginImporter.PluginAssemblies; + + public IPageList GetPageList() => PageList; } } diff --git a/Application/PageList.cs b/Application/PageList.cs new file mode 100644 index 000000000..641308289 --- /dev/null +++ b/Application/PageList.cs @@ -0,0 +1,26 @@ +using SharedLibraryCore.Interfaces; +using System; +using System.Collections.Generic; +using System.Text; + +namespace IW4MAdmin.Application +{ + /// + /// implementatin of IPageList that supports basic + /// pages title and page location for webfront + /// + class PageList : IPageList + { + /// + /// Pages dictionary + /// Key = page name + /// Value = page location (url) + /// + public IDictionary Pages { get; set; } + + public PageList() + { + Pages = new Dictionary(); + } + } +} diff --git a/Application/Server.cs b/Application/Server.cs index 830332d78..3fc22e9cf 100644 --- a/Application/Server.cs +++ b/Application/Server.cs @@ -26,7 +26,7 @@ namespace IW4MAdmin { public class IW4MServer : Server { - private static Index loc = Utilities.CurrentLocalization.LocalizationIndex; + private static readonly Index loc = Utilities.CurrentLocalization.LocalizationIndex; private GameLogEvent LogEvent; private ClientAuthentication AuthQueue; @@ -170,8 +170,6 @@ namespace IW4MAdmin // we need to update their new ip and name to the virtual property client.Name = polledPlayer.Name; client.IPAddress = polledPlayer.IPAddress; - - await Manager.GetClientService().Update(client); } else @@ -181,6 +179,8 @@ namespace IW4MAdmin client.Name = existingAlias.Name; client.IPAddress = existingAlias.IPAddress; } + + await Manager.GetClientService().Update(client); player = client.AsPlayer(); } @@ -288,7 +288,7 @@ namespace IW4MAdmin if (cNum >= 0 && Players[cNum] != null) { Player Leaving = Players[cNum]; - Logger.WriteInfo($"Client {Leaving} disconnecting..."); + Logger.WriteInfo($"Client {Leaving}, state {Leaving.State.ToString()} disconnecting..."); if (!Leaving.IsAuthenticated || Leaving.State != Player.ClientState.Connected) { diff --git a/Plugins/Stats/Plugin.cs b/Plugins/Stats/Plugin.cs index a86ede8c2..23f436cef 100644 --- a/Plugins/Stats/Plugin.cs +++ b/Plugins/Stats/Plugin.cs @@ -13,6 +13,8 @@ using SharedLibraryCore.Services; using IW4MAdmin.Plugins.Stats.Config; using IW4MAdmin.Plugins.Stats.Helpers; using IW4MAdmin.Plugins.Stats.Models; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Routing; namespace IW4MAdmin.Plugins.Stats { @@ -104,6 +106,14 @@ namespace IW4MAdmin.Plugins.Stats await Config.Save(); } + // register the topstats page + // todo:generate the URL/Location instead of hardcoding + manager.GetPageList() + .Pages.Add( + Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_COMMANDS_TOP_TEXT"], + "/Stats/TopPlayersAsync"); + + // meta data info async Task> getStats(int clientId) { diff --git a/SharedLibraryCore/Database/DatabaseContext.cs b/SharedLibraryCore/Database/DatabaseContext.cs index e801e3512..ea6844c44 100644 --- a/SharedLibraryCore/Database/DatabaseContext.cs +++ b/SharedLibraryCore/Database/DatabaseContext.cs @@ -27,6 +27,8 @@ namespace SharedLibraryCore.Database public DatabaseContext(DbContextOptions opt) : base(opt) { } + public DatabaseContext() { } + public DatabaseContext(string connStr) { _ConnectionString = connStr; diff --git a/SharedLibraryCore/Interfaces/IManager.cs b/SharedLibraryCore/Interfaces/IManager.cs index 8b18e118a..a37bdb966 100644 --- a/SharedLibraryCore/Interfaces/IManager.cs +++ b/SharedLibraryCore/Interfaces/IManager.cs @@ -35,5 +35,10 @@ namespace SharedLibraryCore.Interfaces void SetHasEvent(); bool ShutdownRequested(); IList GetPluginAssemblies(); + /// + /// provides a page list to add and remove from + /// + /// + IPageList GetPageList(); } } diff --git a/WebfrontCore/Controllers/BaseController.cs b/WebfrontCore/Controllers/BaseController.cs index c4340a902..536fc2905 100644 --- a/WebfrontCore/Controllers/BaseController.cs +++ b/WebfrontCore/Controllers/BaseController.cs @@ -9,6 +9,7 @@ using SharedLibraryCore.Database; using SharedLibraryCore.Database.Models; using SharedLibraryCore.Interfaces; using SharedLibraryCore.Objects; +using WebfrontCore.ViewModels; namespace WebfrontCore.Controllers { @@ -19,7 +20,7 @@ namespace WebfrontCore.Controllers protected bool Authorized { get; set; } protected SharedLibraryCore.Localization.Index Localization { get; private set; } protected EFClient Client { get; private set; } - private static byte[] LocalHost = { 127, 0, 0, 1 }; + private static readonly byte[] LocalHost = { 127, 0, 0, 1 }; private static string SocialLink; private static string SocialTitle; @@ -89,6 +90,14 @@ namespace WebfrontCore.Controllers ViewBag.SocialLink = SocialLink ?? ""; ViewBag.SocialTitle = SocialTitle; + // grab the pages from plugins + ViewBag.Pages = Manager.GetPageList().Pages + .Select(page => new Page + { + Name = page.Key, + Location = page.Value + }).ToList(); + base.OnActionExecuting(context); } } diff --git a/WebfrontCore/ViewModels/Page.cs b/WebfrontCore/ViewModels/Page.cs new file mode 100644 index 000000000..b39347f38 --- /dev/null +++ b/WebfrontCore/ViewModels/Page.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace WebfrontCore.ViewModels +{ + public class Page + { + public string Name { get; set; } + public string Location { get; set; } + } +} diff --git a/WebfrontCore/Views/Shared/_Layout.cshtml b/WebfrontCore/Views/Shared/_Layout.cshtml index 653517158..15cdb3679 100644 --- a/WebfrontCore/Views/Shared/_Layout.cshtml +++ b/WebfrontCore/Views/Shared/_Layout.cshtml @@ -38,6 +38,12 @@ + @foreach (var _page in ViewBag.Pages) + { + + } @if (!string.IsNullOrEmpty(ViewBag.SocialLink)) {