diff --git a/Plugins/LiveRadar/Configuration/LiveRadarConfiguration.cs b/Plugins/LiveRadar/Configuration/LiveRadarConfiguration.cs index 58c8150b4..99406236c 100644 --- a/Plugins/LiveRadar/Configuration/LiveRadarConfiguration.cs +++ b/Plugins/LiveRadar/Configuration/LiveRadarConfiguration.cs @@ -23,6 +23,7 @@ namespace LiveRadar.Configuration Bottom = 930, // yxmax Top = 44 // pymin }, + new MapInfo() { Name = "mp_rust", @@ -36,17 +37,30 @@ namespace LiveRadar.Configuration MaxBottom = -469 }, + new MapInfo() + { + Name = "mp_terminal", + Top = 174, + Bottom = 846, + Left = 18, + Right = 14, + MaxTop = 2929, + MaxBottom = -513, + MaxLeft = 7520, + MaxRight = 2447 + }, + new MapInfo() { Name = "mp_subbase", - MaxLeft = 1841, // ymax - MaxRight = -3817, // ymin - MaxBottom = -1585, // xmin - MaxTop = 2593, // xmax - Left = 18, // pxmin - Right = 968, // pxmax - Bottom = 864, // pymax - Top = 160, // pymin + MaxLeft = 1841, + MaxRight = -3817, + MaxBottom = -1585, + MaxTop = 2593, + Left = 18, + Right = 968, + Bottom = 864, + Top = 160, ViewPositionRotation = 180, }, diff --git a/SharedLibraryCore/Dtos/IW4MAdminInfo.cs b/SharedLibraryCore/Dtos/IW4MAdminInfo.cs new file mode 100644 index 000000000..835ca8bcd --- /dev/null +++ b/SharedLibraryCore/Dtos/IW4MAdminInfo.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SharedLibraryCore.Dtos +{ + public class IW4MAdminInfo + { + public int TotalClientCount { get; set; } + public int RecentClientCount { get; set; } + public int TotalOccupiedClientSlots { get; set; } + public int TotalAvailableClientSlots { get; set; } + } +} diff --git a/SharedLibraryCore/Services/ClientService.cs b/SharedLibraryCore/Services/ClientService.cs index efd89c83f..0e15abdf6 100644 --- a/SharedLibraryCore/Services/ClientService.cs +++ b/SharedLibraryCore/Services/ClientService.cs @@ -532,6 +532,23 @@ namespace SharedLibraryCore.Services } } + /// + /// Returns the number of clients seen today + /// + /// + public async Task GetRecentClientCount() + { + using (var context = new DatabaseContext(true)) + { + var startOfPeriod = DateTime.UtcNow.AddHours(-24); + var iqQuery = context.Clients.Where(_client => _client.LastConnection >= startOfPeriod); +#if DEBUG + string sql = iqQuery.ToSql(); +#endif + return await iqQuery.CountAsync(); + } + } + /// /// gets the 10 most recently added clients to IW4MAdmin /// diff --git a/SharedLibraryCore/Utilities.cs b/SharedLibraryCore/Utilities.cs index 3766cee6a..7b2fc0d64 100644 --- a/SharedLibraryCore/Utilities.cs +++ b/SharedLibraryCore/Utilities.cs @@ -16,6 +16,7 @@ using System.Reflection; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; +using static SharedLibraryCore.Database.Models.EFClient; using static SharedLibraryCore.Database.Models.EFPenalty; using static SharedLibraryCore.Server; @@ -834,6 +835,8 @@ namespace SharedLibraryCore return new[] { deltaX, deltaY }; } + public static bool ShouldHideLevel(this Permission perm) => perm == Permission.Flagged; + #if DEBUG == true private static readonly TypeInfo QueryCompilerTypeInfo = typeof(QueryCompiler).GetTypeInfo(); diff --git a/WebfrontCore/Controllers/ClientController.cs b/WebfrontCore/Controllers/ClientController.cs index 63787ac75..842a03d6e 100644 --- a/WebfrontCore/Controllers/ClientController.cs +++ b/WebfrontCore/Controllers/ClientController.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using static SharedLibraryCore.Database.Models.EFClient; using static SharedLibraryCore.Database.Models.EFPenalty; namespace WebfrontCore.Controllers @@ -25,11 +26,20 @@ namespace WebfrontCore.Controllers var activePenalties = (await Manager.GetPenaltyService().GetActivePenaltiesAsync(client.AliasLinkId, client.IPAddress)) .Where(_penalty => _penalty.Type != PenaltyType.Flag); + int displayLevelInt = (int)client.Level; + string displayLevel = client.Level.ToLocalizedLevelName(); + + if (!Authorized && client.Level.ShouldHideLevel()) + { + displayLevelInt = (int)Permission.User; + displayLevel = Permission.User.ToLocalizedLevelName(); + } + var clientDto = new PlayerInfo() { Name = client.Name, - Level = client.Level.ToLocalizedLevelName(), - LevelInt = (int)client.Level, + Level = displayLevel, + LevelInt = displayLevelInt, ClientId = client.ClientId, IPAddress = client.IPAddressString, NetworkId = client.NetworkId, @@ -129,6 +139,15 @@ namespace WebfrontCore.Controllers } var clientsDto = await Manager.GetClientService().FindClientsByIdentifier(clientName); + + foreach(var client in clientsDto) + { + if (!Authorized && ((Permission)Enum.Parse(typeof(Permission), client.Level)).ShouldHideLevel()) + { + client.LevelInt = (int)Permission.User; + client.Level = Permission.User.ToLocalizedLevelName(); + } + } ViewBag.Title = $"{clientsDto.Count} {Localization["WEBFRONT_CLIENT_SEARCH_MATCHING"]} \"{clientName}\""; return View("Find/Index", clientsDto); diff --git a/WebfrontCore/Controllers/HomeController.cs b/WebfrontCore/Controllers/HomeController.cs index 58cf2468e..c351122dc 100644 --- a/WebfrontCore/Controllers/HomeController.cs +++ b/WebfrontCore/Controllers/HomeController.cs @@ -1,17 +1,28 @@ using Microsoft.AspNetCore.Diagnostics; using Microsoft.AspNetCore.Mvc; +using SharedLibraryCore.Dtos; +using System.Linq; +using System.Threading.Tasks; namespace WebfrontCore.Controllers { public class HomeController : BaseController { - public IActionResult Index() + public async Task Index() { ViewBag.Description = "IW4MAdmin is a complete server administration tool for IW4x."; ViewBag.Title = Localization["WEBFRONT_HOME_TITLE"]; ViewBag.Keywords = "IW4MAdmin, server, administration, IW4x, MW2, Modern Warfare 2"; - return View(); + var model = new IW4MAdminInfo() + { + TotalAvailableClientSlots = Manager.GetServers().Sum(_server => _server.MaxClients), + TotalOccupiedClientSlots = Manager.GetActiveClients().Count, + TotalClientCount = await Manager.GetClientService().GetTotalClientsAsync(), + RecentClientCount = await Manager.GetClientService().GetRecentClientCount() + }; + + return View(model); } public IActionResult Error() diff --git a/WebfrontCore/Controllers/PenaltyController.cs b/WebfrontCore/Controllers/PenaltyController.cs index 903eec462..b3551a4da 100644 --- a/WebfrontCore/Controllers/PenaltyController.cs +++ b/WebfrontCore/Controllers/PenaltyController.cs @@ -45,7 +45,6 @@ namespace WebfrontCore.Controllers using (var ctx = new DatabaseContext(disableTracking: true)) { - // todo: this seems like it's pulling unnecessary info from LINQ to entities. var iqPenalties = ctx.Penalties .AsNoTracking() .Where(p => p.Type == PenaltyType.Ban && p.Active) diff --git a/WebfrontCore/Views/Client/Profile/Index.cshtml b/WebfrontCore/Views/Client/Profile/Index.cshtml index a32c09103..6127e300b 100644 --- a/WebfrontCore/Views/Client/Profile/Index.cshtml +++ b/WebfrontCore/Views/Client/Profile/Index.cshtml @@ -10,6 +10,8 @@ .OrderBy(_meta => _meta.Order) .GroupBy(_meta => _meta.Column) .OrderBy(_grouping => _grouping.Key); + + }
diff --git a/WebfrontCore/Views/Home/Index.cshtml b/WebfrontCore/Views/Home/Index.cshtml index 3b21869b8..e185c639c 100644 --- a/WebfrontCore/Views/Home/Index.cshtml +++ b/WebfrontCore/Views/Home/Index.cshtml @@ -1,4 +1,25 @@ -@await Component.InvokeAsync("ServerList") +@model SharedLibraryCore.Dtos.IW4MAdminInfo +@{ + var loc = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex; + string formatTranslation(string translationKey, params object[] values) + { + var split = loc[translationKey].Split("::"); + return $"{SharedLibraryCore.Utilities.FormatExt(split[0], values)}{split[1]}"; + } +} +
+
+
@Html.Raw(formatTranslation("WEBFRONT_HOME_CLIENTS_ONLINE", Model.TotalOccupiedClientSlots, Model.TotalAvailableClientSlots))
+
+
+
@Html.Raw(formatTranslation("WEBFRONT_HOME_RECENT_CLIENTS", Model.RecentClientCount.ToString("#,##0")))
+
+
+
@Html.Raw(formatTranslation("WEBFRONT_HOME_TOTAL_CLIENTS", Model.TotalClientCount.ToString("#,##0")))
+
+
+ +@await Component.InvokeAsync("ServerList") @section scripts { diff --git a/WebfrontCore/Views/Server/_Server.cshtml b/WebfrontCore/Views/Server/_Server.cshtml index 162bab054..38d451452 100644 --- a/WebfrontCore/Views/Server/_Server.cshtml +++ b/WebfrontCore/Views/Server/_Server.cshtml @@ -3,11 +3,11 @@ Layout = null; } -
+
@Model.Name - + @if (ViewBag.Authorized) @@ -21,8 +21,8 @@ @if (ViewBag.Authorized) { -
- +
+
}
diff --git a/WebfrontCore/wwwroot/js/loader.js b/WebfrontCore/wwwroot/js/loader.js index 167935b50..aa7610e0c 100644 --- a/WebfrontCore/wwwroot/js/loader.js +++ b/WebfrontCore/wwwroot/js/loader.js @@ -41,7 +41,7 @@ function loadMoreItems() { loaderOffset += loadCount; } -function ScrollHandler(e) { +function _ScrollHandler(e) { //throttle event: hasScrollBar = true; clearTimeout(_throttleTimer); @@ -81,8 +81,8 @@ function setupListeners() { $document.ready(function () { $window - .off('scroll', ScrollHandler) - .on('scroll', ScrollHandler); + .off('scroll', _ScrollHandler) + .on('scroll', _ScrollHandler); $('.loader-load-more:not(.disabled)').click(function (e) { if (!isLoaderLoading) { loadMoreItems(); diff --git a/WebfrontCore/wwwroot/js/penalty.js b/WebfrontCore/wwwroot/js/penalty.js index f42a710bc..db42da9f1 100644 --- a/WebfrontCore/wwwroot/js/penalty.js +++ b/WebfrontCore/wwwroot/js/penalty.js @@ -2,7 +2,7 @@ let isLoading = false; -function ScrollHandler(e) { +function PenaltyScrollHandler(e) { //throttle event: hasScrollBar = true; clearTimeout(_throttleTimer); @@ -67,8 +67,8 @@ if ($('#penalty_table').length === 1) { $document.ready(function () { $window - .off('scroll', ScrollHandler) - .on('scroll', ScrollHandler); + .off('scroll', PenaltyScrollHandle) + .on('scroll', PenaltyScrollHandle); $('#load_penalties_button').click(function () { loadMorePenalties(); diff --git a/version.txt b/version.txt index 4f0b2398b..667828ae2 100644 --- a/version.txt +++ b/version.txt @@ -2,6 +2,8 @@ Version 2.4: -added "live radar" feature -added chat message to server on server list view -added recently connected players dropdown option on webfront +-added "dashboard" to home view with quick stats +-hid flagged status of users on webfront unless logged in Version 2.3: -added configuration option to ignore bots