From b8a310bb07fc114cf9cd32ba519dae6408b75116 Mon Sep 17 00:00:00 2001 From: RaidMax Date: Tue, 6 Aug 2019 13:36:37 -0500 Subject: [PATCH] prevent flag icon from showing on banned profiles implement automated penalty info for profanity determent issue #75 --- Plugins/ProfanityDeterment/Plugin.cs | 25 ++++++++++-- Plugins/Stats/Controllers/StatsController.cs | 39 ++++++++++++------- .../Views/Client/Profile/Index.cshtml | 8 ++-- .../Components/ProfileMetaList/_List.cshtml | 4 +- WebfrontCore/wwwroot/js/profile.js | 6 +-- 5 files changed, 57 insertions(+), 25 deletions(-) diff --git a/Plugins/ProfanityDeterment/Plugin.cs b/Plugins/ProfanityDeterment/Plugin.cs index 2adeac0d1..4f601fd3d 100644 --- a/Plugins/ProfanityDeterment/Plugin.cs +++ b/Plugins/ProfanityDeterment/Plugin.cs @@ -1,9 +1,11 @@ -using System.Linq; +using System.Collections.Generic; +using System.Linq; using System.Reflection; using System.Text.RegularExpressions; using System.Threading.Tasks; using SharedLibraryCore; using SharedLibraryCore.Configuration; +using SharedLibraryCore.Database.Models; using SharedLibraryCore.Interfaces; namespace IW4MAdmin.Plugins.ProfanityDeterment @@ -41,7 +43,15 @@ namespace IW4MAdmin.Plugins.ProfanityDeterment if (containsObjectionalWord) { - E.Origin.Kick(Settings.Configuration().ProfanityKickMessage, Utilities.IW4MAdminClient(E.Owner)); + var sender = Utilities.IW4MAdminClient(E.Owner); + sender.AdministeredPenalties = new List() + { + new EFPenalty() + { + AutomatedOffense = E.Origin.Name + } + }; + E.Origin.Kick(Settings.Configuration().ProfanityKickMessage, sender); }; } @@ -78,7 +88,16 @@ namespace IW4MAdmin.Plugins.ProfanityDeterment else if (profanityInfringments < Settings.Configuration().KickAfterInfringementCount) { E.Origin.SetAdditionalProperty("_profanityInfringements", profanityInfringments + 1); - E.Origin.Warn(Settings.Configuration().ProfanityWarningMessage, Utilities.IW4MAdminClient(E.Owner)); + + var sender = Utilities.IW4MAdminClient(E.Owner); + sender.AdministeredPenalties = new List() + { + new EFPenalty() + { + AutomatedOffense = E.Data + } + }; + E.Origin.Warn(Settings.Configuration().ProfanityWarningMessage, sender); } } } diff --git a/Plugins/Stats/Controllers/StatsController.cs b/Plugins/Stats/Controllers/StatsController.cs index 28554a4a5..b20a86ba1 100644 --- a/Plugins/Stats/Controllers/StatsController.cs +++ b/Plugins/Stats/Controllers/StatsController.cs @@ -102,21 +102,16 @@ namespace IW4MAdmin.Plugins.Stats.Web.Controllers [HttpGet] [Authorize] - public async Task GetAutomatedPenaltyInfoAsync(int clientId) + public async Task GetAutomatedPenaltyInfoAsync(int penaltyId) { using (var ctx = new SharedLibraryCore.Database.DatabaseContext(true)) { - int linkId = await ctx.Clients - .Where(_client => _client.ClientId == clientId) - .Select(_client => _client.AliasLinkId) - .FirstOrDefaultAsync(); + var penalty = await ctx.Penalties + .Select(_penalty => new { _penalty.OffenderId, _penalty.PenaltyId, _penalty.When, _penalty.AutomatedOffense }) + .FirstOrDefaultAsync(_penalty => _penalty.PenaltyId == penaltyId); - var clientIds = await ctx.Clients.Where(_client => _client.AliasLinkId == linkId) - .Select(_client => _client.ClientId) - .ToListAsync(); - - var iqPenaltyInfo = ctx.Set() - .Where(s => clientIds.Contains(s.ClientId)) + var iqSnapshotInfo = ctx.Set() + .Where(s => s.ClientId == penalty.OffenderId) .Include(s => s.LastStrainAngle) .Include(s => s.HitOrigin) .Include(s => s.HitDestination) @@ -126,12 +121,28 @@ namespace IW4MAdmin.Plugins.Stats.Web.Controllers .ThenBy(s => s.Hits); #if DEBUG == true - var sql = iqPenaltyInfo.ToSql(); + var sql = iqSnapshotInfo.ToSql(); #endif + var penaltyInfo = await iqSnapshotInfo.ToListAsync(); - var penaltyInfo = await iqPenaltyInfo.ToListAsync(); + if (penaltyInfo.Count > 0) + { + return View("_PenaltyInfo", penaltyInfo); + } - return View("_PenaltyInfo", penaltyInfo); + // we want to show anything related to the automated offense + else + { + return View("_MessageContext", new[] + { + new ChatInfo() + { + ClientId = penalty.OffenderId, + Message = penalty.AutomatedOffense, + Time = penalty.When + } + }); + } } } } diff --git a/WebfrontCore/Views/Client/Profile/Index.cshtml b/WebfrontCore/Views/Client/Profile/Index.cshtml index a564d868d..d24aec794 100644 --- a/WebfrontCore/Views/Client/Profile/Index.cshtml +++ b/WebfrontCore/Views/Client/Profile/Index.cshtml @@ -6,13 +6,12 @@ string gravatarUrl = Model.Meta.FirstOrDefault(m => m.Key == "GravatarEmail")?.Value; bool isTempBanned = Model.ActivePenaltyType == "TempBan"; bool isFlagged = Model.LevelInt == (int)SharedLibraryCore.Database.Models.EFClient.Permission.Flagged; + bool isPermBanned = Model.LevelInt == (int)SharedLibraryCore.Database.Models.EFClient.Permission.Banned; var informationMeta = Model.Meta .Where(_meta => _meta.Type == SharedLibraryCore.Dtos.ProfileMeta.MetaType.Information) .OrderBy(_meta => _meta.Order) .GroupBy(_meta => _meta.Column) .OrderBy(_grouping => _grouping.Key); - - }
@@ -57,7 +56,10 @@ @if (ViewBag.Authorized) {
- + @if (!isPermBanned) + { + + } @if (Model.LevelInt < (int)ViewBag.User.Level && !Model.HasActivePenalty) { diff --git a/WebfrontCore/Views/Shared/Components/ProfileMetaList/_List.cshtml b/WebfrontCore/Views/Shared/Components/ProfileMetaList/_List.cshtml index 14f79a053..40595b51e 100644 --- a/WebfrontCore/Views/Shared/Components/ProfileMetaList/_List.cshtml +++ b/WebfrontCore/Views/Shared/Components/ProfileMetaList/_List.cshtml @@ -21,12 +21,12 @@ return meta.Type == SharedLibraryCore.Dtos.ProfileMeta.MetaType.Penalized ? string.Format(localizationMessage, $"{penalty.OffenderName}", - $"{penalty.Offense} {(ViewBag.Authorized ? penalty.AdditionalPenaltyInformation : "")}") + $"{penalty.Offense} {(ViewBag.Authorized ? penalty.AdditionalPenaltyInformation : "")}") .Replace("{", "") .Replace("}", "") : string.Format(localizationMessage, $"{penalty.PunisherName}", - $"{penalty.Offense} {(ViewBag.Authorized ? penalty.AdditionalPenaltyInformation : "")}", + $"{penalty.Offense} {(ViewBag.Authorized ? penalty.AdditionalPenaltyInformation : "")}", penalty.Offense) .Replace("{", "") .Replace("}", ""); diff --git a/WebfrontCore/wwwroot/js/profile.js b/WebfrontCore/wwwroot/js/profile.js index a914f9956..cf4d7087b 100644 --- a/WebfrontCore/wwwroot/js/profile.js +++ b/WebfrontCore/wwwroot/js/profile.js @@ -35,14 +35,14 @@ }); /* - * load info on ban/flag - */ + * load info on ban/flag + */ $(document).off('click', '.automated-penalty-info-detailed'); $(document).on('click', '.automated-penalty-info-detailed', function (e) { showLoader(); const location = $(this).parent(); $.get('/Stats/GetAutomatedPenaltyInfoAsync', { - 'clientId': $(this).data('clientid') + 'penaltyId': $(this).data('penalty-id') }) .done(function (response) { $('.penalty-info-context').remove();