From a07ce112b064d7d2f72544279d959ccc4add537d Mon Sep 17 00:00:00 2001 From: RaidMax Date: Mon, 26 Mar 2018 23:54:20 -0500 Subject: [PATCH] ban/unban buttons added to profile several css tweaks changed administratorIPs to PrivilegedClients added time step references to profile page --- Plugins/SimpleStats/Cheat/Detection.cs | 5 -- WebfrontCore/Application/Manager.cs | 22 +++-- WebfrontCore/Application/Server.cs | 26 +++--- WebfrontCore/Controllers/ActionController.cs | 75 +++++++++++++++++ WebfrontCore/Controllers/BaseController.cs | 28 +++++-- WebfrontCore/Controllers/ConsoleController.cs | 2 +- .../PenaltyListViewComponent.cs | 14 +++- WebfrontCore/ViewModels/ActionInfo.cs | 15 ++++ WebfrontCore/ViewModels/InputInfo.cs | 15 ++++ WebfrontCore/Views/Action/_ActionForm.cshtml | 22 +++++ .../Views/Client/Profile/Index.cshtml | 8 +- WebfrontCore/Views/Shared/_Layout.cshtml | 24 ++++++ WebfrontCore/wwwroot/css/Site.scss | 16 ++++ WebfrontCore/wwwroot/css/profile.css | 27 ++++--- WebfrontCore/wwwroot/js/profile.js | 81 ++++++++++++++++++- WebfrontCore/wwwroot/js/server.js | 12 +-- .../lib/bootstrap/dist/css/bootstrap.css | 12 +++ .../lib/bootstrap/dist/css/bootstrap.min.css | 2 +- 18 files changed, 349 insertions(+), 57 deletions(-) create mode 100644 WebfrontCore/Controllers/ActionController.cs create mode 100644 WebfrontCore/ViewModels/ActionInfo.cs create mode 100644 WebfrontCore/ViewModels/InputInfo.cs create mode 100644 WebfrontCore/Views/Action/_ActionForm.cshtml diff --git a/Plugins/SimpleStats/Cheat/Detection.cs b/Plugins/SimpleStats/Cheat/Detection.cs index 7fec01d46..c48292c6f 100644 --- a/Plugins/SimpleStats/Cheat/Detection.cs +++ b/Plugins/SimpleStats/Cheat/Detection.cs @@ -68,11 +68,6 @@ namespace StatsPlugin.Cheat double avg = AverageHitOffset / (float)avgcnt; } -/*r = distance, -x = playerX + r*cos(yaw)*cos(pitch), -y = playerY + r*sin(yaw)*cos(pitch) -z = playerZ + r*sin(360-pitch)*/ - #endregion #region SESSION_RATIOS diff --git a/WebfrontCore/Application/Manager.cs b/WebfrontCore/Application/Manager.cs index 56e79b6e2..ce20acbd8 100644 --- a/WebfrontCore/Application/Manager.cs +++ b/WebfrontCore/Application/Manager.cs @@ -25,7 +25,7 @@ namespace IW4MAdmin { private List _servers; public List Servers => _servers.OrderByDescending(s => s.ClientNum).ToList(); - public List AdministratorIPs { get; set; } + public Dictionary PrivilegedClients { get; set; } public ILogger Logger { get; private set; } public bool Running { get; private set; } public EventHandler ServerEventOccurred { get; private set; } @@ -54,7 +54,7 @@ namespace IW4MAdmin ClientSvc = new ClientService(); AliasSvc = new AliasService(); PenaltySvc = new PenaltyService(); - AdministratorIPs = new List(); + PrivilegedClients = new Dictionary(); ServerEventOccurred += EventAPI.OnServerEventOccurred; ConfigHandler = new BaseConfigurationHandler("IW4MAdminSettings"); } @@ -77,9 +77,21 @@ namespace IW4MAdmin public async Task Init() { #region DATABASE - AdministratorIPs = (await ClientSvc.Find(c => c.Level > Player.Permission.Trusted)) - .Select(c => c.IPAddress) - .ToList(); + var ipList = (await ClientSvc.Find(c => c.Level > Player.Permission.Trusted)) + .Select(c => new { c.IPAddress, c.ClientId }); + + foreach (var a in ipList) + { + try + { + PrivilegedClients.Add(a.IPAddress, a.ClientId); + } + + catch (ArgumentException) + { + continue; + } + } #endregion #region CONFIG diff --git a/WebfrontCore/Application/Server.cs b/WebfrontCore/Application/Server.cs index da9e98a06..810cf26e2 100644 --- a/WebfrontCore/Application/Server.cs +++ b/WebfrontCore/Application/Server.cs @@ -302,7 +302,7 @@ namespace IW4MAdmin string escapedName = Regex.Escape(E.Target.Name); var reg = new Regex($"(\"{escapedName}\")|({escapedName})", RegexOptions.IgnoreCase); E.Data = reg.Replace(E.Data, "", 1).Trim(); - + if (E.Data.Length == 0 && C.RequiredArgumentCount > 1) { await E.Origin.Tell($"Not enough arguments supplied!"); @@ -479,8 +479,8 @@ namespace IW4MAdmin playerCountStart = DateTime.Now; } - if (LastMessage.TotalSeconds > Manager.GetApplicationSettings().Configuration().AutoMessagePeriod - && BroadcastMessages.Count > 0 + if (LastMessage.TotalSeconds > Manager.GetApplicationSettings().Configuration().AutoMessagePeriod + && BroadcastMessages.Count > 0 && ClientNum > 0) { await Broadcast(Utilities.ProcessMessageToken(Manager.GetMessageTokens(), BroadcastMessages[NextMessage])); @@ -658,7 +658,7 @@ namespace IW4MAdmin LogFile = new IFile(logPath); //#else } - LogFile = new RemoteFile("https://raidmax.org/IW4MAdmin/getlog.php"); + LogFile = new RemoteFile("https://raidmax.org/IW4MAdmin/getlog.php"); //#endif Logger.WriteInfo($"Log file is {logPath}"); #if !DEBUG @@ -775,9 +775,13 @@ namespace IW4MAdmin CurrentMap = Maps.Find(m => m.Name == mapname) ?? new Map() { Alias = mapname, Name = mapname }; // todo: make this more efficient - ((ApplicationManager)(Manager)).AdministratorIPs = (await new GenericRepository().FindAsync(c => c.Level > Player.Permission.Trusted)) - .Select(c => c.IPAddress) - .ToList(); + ((ApplicationManager)(Manager)).PrivilegedClients = new Dictionary(); + var ClientSvc = new ClientService(); + var ipList = (await ClientSvc.Find(c => c.Level > Player.Permission.Trusted)) + .Select(c => new { c.IPAddress, c.ClientId }); + + foreach (var a in ipList) + ((ApplicationManager)(Manager)).PrivilegedClients.Add(a.IPAddress, a.ClientId); } if (E.Type == Event.GType.MapEnd) @@ -887,11 +891,10 @@ namespace IW4MAdmin return; } } - +#if !DEBUG else await Target.CurrentServer.ExecuteCommandAsync($"clientkick {Target.ClientNumber } \"^7Player Temporarily Banned: ^5{ Reason }\""); - -#if DEBUG +#else await Target.CurrentServer.RemovePlayer(Target.ClientNumber); #endif @@ -933,8 +936,9 @@ namespace IW4MAdmin { // this is set only because they're still in the server. Target.Level = Player.Permission.Banned; +#if !DEBUG await Target.CurrentServer.ExecuteCommandAsync($"clientkick {Target.ClientNumber} \"Player Banned: ^5{Message} ^7(appeal at {Website}) ^7\""); -#if DEBUG +#else await Target.CurrentServer.RemovePlayer(Target.ClientNumber); #endif } diff --git a/WebfrontCore/Controllers/ActionController.cs b/WebfrontCore/Controllers/ActionController.cs new file mode 100644 index 000000000..9a9dfd263 --- /dev/null +++ b/WebfrontCore/Controllers/ActionController.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using SharedLibrary; +using WebfrontCore.ViewModels; + +namespace WebfrontCore.Controllers +{ + public class ActionController : BaseController + { + public IActionResult BanForm() + { + var info = new ActionInfo() + { + ActionButtonLabel = "Ban", + Name = "Ban", + Inputs = new List() + { + new InputInfo() + { + Name = "Reason", + Placeholder = "" + } + }, + Action = "BanAsync" + }; + + return View("_ActionForm", info); + } + + public async Task BanAsync(int targetId, string Reason) + { + var server = Manager.GetServers().First(); + + return await Task.FromResult(RedirectToAction("ExecuteAsync", "Console", new + { + serverId = server.GetHashCode(), + command = $"!ban @{targetId} {Reason}" + })); + } + + public IActionResult UnbanForm() + { + var info = new ActionInfo() + { + ActionButtonLabel = "Unban", + Name = "Unban", + Inputs = new List() + { + new InputInfo() + { + Name = "Reason", + Placeholder = "" + } + }, + Action = "UnbanAsync" + }; + + return View("_ActionForm", info); + } + + public async Task UnbanAsync(int targetId, string Reason) + { + var server = Manager.GetServers().First(); + + return await Task.FromResult(RedirectToAction("ExecuteAsync", "Console", new + { + serverId = server.GetHashCode(), + command = $"!unban @{targetId} {Reason}" + })); + } + } +} diff --git a/WebfrontCore/Controllers/BaseController.cs b/WebfrontCore/Controllers/BaseController.cs index 57a5e27bf..ee8d1fb42 100644 --- a/WebfrontCore/Controllers/BaseController.cs +++ b/WebfrontCore/Controllers/BaseController.cs @@ -2,11 +2,8 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; using SharedLibrary; -using SharedLibrary.Interfaces; -using System; +using SharedLibrary.Database.Models; using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; namespace WebfrontCore.Controllers { @@ -14,19 +11,36 @@ namespace WebfrontCore.Controllers { protected ApplicationManager Manager; protected bool Authorized { get; private set; } + protected EFClient User { get; private set; } public override void OnActionExecuting(ActionExecutingContext context) { Manager = IW4MAdmin.Program.ServerManager; - Authorized = context.HttpContext.Connection.RemoteIpAddress.ToString() == "127.0.0.1" || - Manager.AdministratorIPs.Contains(context.HttpContext.Connection.RemoteIpAddress.ToString().ConvertToIP()); + + User = new EFClient() + { + ClientId = -1 + }; + + try + { + User.ClientId = Manager.PrivilegedClients[context.HttpContext.Connection.RemoteIpAddress.ToString().ConvertToIP()]; + } + + catch (KeyNotFoundException) + { + + } + + Authorized = context.HttpContext.Connection.RemoteIpAddress.ToString() == "127.0.0.1" || + User.ClientId >= 0; ViewBag.Authorized = Authorized; ViewBag.Url = Startup.Configuration["Web:Address"]; string inviteLink = Manager.GetApplicationSettings().Configuration().DiscordInviteCode; if (inviteLink != null) ViewBag.DiscordLink = inviteLink.Contains("https") ? inviteLink : $"https://discordapp.com/invite/{inviteLink}"; else - ViewBag.DiscorLink = ""; + ViewBag.DiscordLink = ""; base.OnActionExecuting(context); } } diff --git a/WebfrontCore/Controllers/ConsoleController.cs b/WebfrontCore/Controllers/ConsoleController.cs index 52ab4286e..7fc624917 100644 --- a/WebfrontCore/Controllers/ConsoleController.cs +++ b/WebfrontCore/Controllers/ConsoleController.cs @@ -41,7 +41,7 @@ namespace WebfrontCore.Controllers IPAddress = intIP }; #else - var origin = (await Manager.GetClientService().GetUnique(0)).AsPlayer(); + var origin = (await Manager.GetClientService().GetUnique(0)).AsPlayer(); #endif var server = Manager.Servers.First(s => s.GetHashCode() == serverId); diff --git a/WebfrontCore/ViewComponents/PenaltyListViewComponent.cs b/WebfrontCore/ViewComponents/PenaltyListViewComponent.cs index 4c38c1b12..fb17b3104 100644 --- a/WebfrontCore/ViewComponents/PenaltyListViewComponent.cs +++ b/WebfrontCore/ViewComponents/PenaltyListViewComponent.cs @@ -15,8 +15,18 @@ namespace WebfrontCore.ViewComponents int ip = HttpContext.Connection.RemoteIpAddress .ToString().ConvertToIP(); - bool authed = IW4MAdmin.ApplicationManager.GetInstance() - .AdministratorIPs.Contains(ip); + bool authed = false; + + try + { + var a = IW4MAdmin.ApplicationManager.GetInstance() + .PrivilegedClients[HttpContext.Connection.RemoteIpAddress.ToString().ConvertToIP()]; + } + + catch (KeyNotFoundException) + { + + } var penalties = await IW4MAdmin.ApplicationManager.GetInstance().GetPenaltyService().GetRecentPenalties(15, offset); var penaltiesDto = penalties.Select(p => new PenaltyInfo() diff --git a/WebfrontCore/ViewModels/ActionInfo.cs b/WebfrontCore/ViewModels/ActionInfo.cs new file mode 100644 index 000000000..fd7bac379 --- /dev/null +++ b/WebfrontCore/ViewModels/ActionInfo.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace WebfrontCore.ViewModels +{ + public class ActionInfo + { + public string Name { get; set; } + public List Inputs { get; set; } + public string ActionButtonLabel { get; set; } + public string Action { get; set; } + } +} diff --git a/WebfrontCore/ViewModels/InputInfo.cs b/WebfrontCore/ViewModels/InputInfo.cs new file mode 100644 index 000000000..c4b4b7436 --- /dev/null +++ b/WebfrontCore/ViewModels/InputInfo.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace WebfrontCore.ViewModels +{ + public class InputInfo + { + public string Name { get; set; } + public string Placeholder { get; set; } + public string Type { get; set; } + public string Value { get; set; } + } +} diff --git a/WebfrontCore/Views/Action/_ActionForm.cshtml b/WebfrontCore/Views/Action/_ActionForm.cshtml new file mode 100644 index 000000000..e0ef35a9c --- /dev/null +++ b/WebfrontCore/Views/Action/_ActionForm.cshtml @@ -0,0 +1,22 @@ +@model WebfrontCore.ViewModels.ActionInfo +@{ + Layout = null; +} +
+
+ @foreach (var input in Model.Inputs) + { + +
+ @input.Name +
+ { + string inputType = input.Type ?? "text"; + string value = input.Value ?? ""; + + + } + } +
+ +
\ No newline at end of file diff --git a/WebfrontCore/Views/Client/Profile/Index.cshtml b/WebfrontCore/Views/Client/Profile/Index.cshtml index e4da0021a..d9f237b08 100644 --- a/WebfrontCore/Views/Client/Profile/Index.cshtml +++ b/WebfrontCore/Views/Client/Profile/Index.cshtml @@ -26,12 +26,12 @@ if (Model.Level == SharedLibrary.Objects.Player.Permission.User.ToString()) { - + } if (Model.Level == SharedLibrary.Objects.Player.Permission.Banned.ToString()) { - + } } } @@ -85,6 +85,10 @@ +@section targetid { + +} + @section scripts {