diff --git a/Application/ApplicationManager.cs b/Application/ApplicationManager.cs index 9cdb4dc9..a2d145e6 100644 --- a/Application/ApplicationManager.cs +++ b/Application/ApplicationManager.cs @@ -250,10 +250,10 @@ namespace IW4MAdmin.Application ConfigHandler.Set((ApplicationConfiguration)new ApplicationConfiguration().Generate()); var newConfig = ConfigHandler.Configuration(); - newConfig.AutoMessagePeriod = defaultConfig.AutoMessagePeriod; newConfig.AutoMessages = defaultConfig.AutoMessages; newConfig.GlobalRules = defaultConfig.GlobalRules; newConfig.Maps = defaultConfig.Maps; + newConfig.QuickMessages = defaultConfig.QuickMessages; if (newConfig.Servers == null) { @@ -493,27 +493,15 @@ namespace IW4MAdmin.Application return new List(); } - var penalties = await GetPenaltyService().GetAllClientPenaltiesAsync(clientId, count, offset, startAt); + var penalties = await GetPenaltyService().GetClientPenaltyForMetaAsync(clientId, count, offset, startAt); return penalties.Select(_penalty => new ProfileMeta() { - Id = _penalty.PenaltyId, + Id = _penalty.Id, Type = _penalty.PunisherId == clientId ? ProfileMeta.MetaType.Penalized : ProfileMeta.MetaType.ReceivedPenalty, - Value = new PenaltyInfo - { - Id = _penalty.PenaltyId, - OffenderName = _penalty.Offender.Name, - OffenderId = _penalty.OffenderId, - PunisherName = _penalty.Punisher.Name, - PunisherId = _penalty.PunisherId, - Offense = _penalty.Offense, - PenaltyType = _penalty.Type.ToString(), - TimeRemaining = _penalty.Expires.HasValue ? (DateTime.Now > _penalty.Expires ? "" : _penalty.Expires.ToString()) : DateTime.MaxValue.ToString(), - AutomatedOffense = _penalty.AutomatedOffense, - Expired = _penalty.Expires.HasValue && _penalty.Expires <= DateTime.UtcNow - }, - When = _penalty.When, - Sensitive = _penalty.Type == Penalty.PenaltyType.Flag + Value = _penalty, + When = _penalty.TimePunished, + Sensitive = _penalty.Sensitive }) .ToList(); } diff --git a/Application/DefaultSettings.json b/Application/DefaultSettings.json index 15347418..657eaccc 100644 --- a/Application/DefaultSettings.json +++ b/Application/DefaultSettings.json @@ -16,6 +16,51 @@ "Keep grenade launcher use to a minimum", "Balance teams at ALL times" ], + "QuickMessages": [ + { + "Game": "IW4", + "Messages": { + "QUICKMESSAGE_AREA_SECURE": "Area secure!", + "QUICKMESSAGE_ARE_YOU_CRAZY": "Are you crazy?", + "QUICKMESSAGE_ATTACK_LEFT_FLANK": "Attack left flank!", + "QUICKMESSAGE_ATTACK_RIGHT_FLANK": "Attack right flank!", + "QUICKMESSAGE_COME_ON": "Come on.", + "QUICKMESSAGE_ENEMIES_SPOTTED": "Multiple contacts!", + "QUICKMESSAGE_ENEMY_DOWN": "Enemy down!", + "QUICKMESSAGE_ENEMY_GRENADE": "Enemy grenade!", + "QUICKMESSAGE_ENEMY_SPOTTED": "Contact!", + "QUICKMESSAGE_FALL_BACK": "Fall back!", + "QUICKMESSAGE_FOLLOW_ME": "On me!", + "QUICKMESSAGE_GREAT_SHOT": "Nice shot!", + "QUICKMESSAGE_GRENADE": "Grenade!", + "QUICKMESSAGE_HOLD_THIS_POSITION": "Hold this position!", + "QUICKMESSAGE_HOLD_YOUR_FIRE": "Hold your fire!", + "QUICKMESSAGE_IM_IN_POSITION": "In position.", + "QUICKMESSAGE_IM_ON_MY_WAY": "Moving.", + "QUICKMESSAGE_MOVE_IN": "Move in!", + "QUICKMESSAGE_NEED_REINFORCEMENTS": "Need reinforcements!", + "QUICKMESSAGE_NO_SIR": "Negative.", + "QUICKMESSAGE_ON_MY_WAY": "On my way.", + "QUICKMESSAGE_REGROUP": "Regroup!", + "QUICKMESSAGE_SNIPER": "Sniper!", + "QUICKMESSAGE_SORRY": "Sorry.", + "QUICKMESSAGE_SQUAD_ATTACK_LEFT_FLANK": "Squad, attack left flank!", + "QUICKMESSAGE_SQUAD_ATTACK_RIGHT_FLANK": "Squad, attack right flank!", + "QUICKMESSAGE_SQUAD_HOLD_THIS_POSITION": "Squad, hold this position!", + "QUICKMESSAGE_SQUAD_REGROUP": "Squad, regroup!", + "QUICKMESSAGE_SQUAD_STICK_TOGETHER": "Squad, stick together!", + "QUICKMESSAGE_STICK_TOGETHER": "Stick together!", + "QUICKMESSAGE_SUPPRESSING_FIRE": "Base of fire!", + "QUICKMESSAGE_TOOK_LONG_ENOUGH": "Took long enough!", + "QUICKMESSAGE_TOOK_YOU_LONG_ENOUGH": "Took you long enough!", + "QUICKMESSAGE_WATCH_SIX": "Watch your six!", + "QUICKMESSAGE_YES_SIR": "Roger.", + "QUICKMESSAGE_YOURE_CRAZY": "You're crazy!", + "QUICKMESSAGE_YOURE_NUTS": "You're nuts!", + "QUICKMESSAGE_YOU_OUTTA_YOUR_MIND": "You outta your mind?" + } + } + ], "Maps": [ { "Game": "IW3", diff --git a/Plugins/Stats/Controllers/StatsController.cs b/Plugins/Stats/Controllers/StatsController.cs index 88160efa..e28ea18c 100644 --- a/Plugins/Stats/Controllers/StatsController.cs +++ b/Plugins/Stats/Controllers/StatsController.cs @@ -89,16 +89,30 @@ namespace IW4MAdmin.Plugins.Stats.Web.Controllers { using (var ctx = new SharedLibraryCore.Database.DatabaseContext(true)) { - var penaltyInfo = await ctx.Set() - .Where(s => s.ClientId == clientId) + int linkId = await ctx.Clients + .Where(_client => _client.ClientId == clientId) + .Select(_client => _client.AliasLinkId) + .FirstOrDefaultAsync(); + + 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)) .Include(s => s.LastStrainAngle) .Include(s => s.HitOrigin) .Include(s => s.HitDestination) .Include(s => s.CurrentViewAngle) .Include(s => s.PredictedViewAngles) .OrderBy(s => s.When) - .ThenBy(s => s.Hits) - .ToListAsync(); + .ThenBy(s => s.Hits); + +#if DEBUG == true + var sql = iqPenaltyInfo.ToSql(); +#endif + + var penaltyInfo = await iqPenaltyInfo.ToListAsync(); return View("_PenaltyInfo", penaltyInfo); } diff --git a/Plugins/Web/StatsWeb/Views/Stats/_MessageContext.cshtml b/Plugins/Web/StatsWeb/Views/Stats/_MessageContext.cshtml index 74076f45..311d36b0 100644 --- a/Plugins/Web/StatsWeb/Views/Stats/_MessageContext.cshtml +++ b/Plugins/Web/StatsWeb/Views/Stats/_MessageContext.cshtml @@ -3,10 +3,12 @@ Layout = null; } -
-
@Model.First().Time.ToString()
- @foreach (var message in Model) - { - @Html.ActionLink(@message.Name, "ProfileAsync", "Client", new { id = message.ClientId}) — @message.Message
- } +
+
@Model.First().Time.ToString()
+
+ @foreach (var message in Model) + { + @message.Name — @message.Message
+ } +
\ No newline at end of file diff --git a/SharedLibraryCore/Configuration/ApplicationConfiguration.cs b/SharedLibraryCore/Configuration/ApplicationConfiguration.cs index 39a26e92..1f8771ce 100644 --- a/SharedLibraryCore/Configuration/ApplicationConfiguration.cs +++ b/SharedLibraryCore/Configuration/ApplicationConfiguration.cs @@ -57,6 +57,7 @@ namespace SharedLibraryCore.Configuration public List AutoMessages { get; set; } public List GlobalRules { get; set; } public List Maps { get; set; } + public List QuickMessages { get; set; } public List DisallowedClientNames { get; set; } public IBaseConfiguration Generate() diff --git a/SharedLibraryCore/Configuration/DefaultConfiguration.cs b/SharedLibraryCore/Configuration/DefaultConfiguration.cs index 0dfd3480..38b2b3dc 100644 --- a/SharedLibraryCore/Configuration/DefaultConfiguration.cs +++ b/SharedLibraryCore/Configuration/DefaultConfiguration.cs @@ -7,10 +7,10 @@ namespace SharedLibraryCore.Configuration { public class DefaultConfiguration : IBaseConfiguration { - public int AutoMessagePeriod { get; set; } public List AutoMessages { get; set; } public List GlobalRules { get; set; } public List Maps { get; set; } + public List QuickMessages {get; set;} public IBaseConfiguration Generate() => this; diff --git a/SharedLibraryCore/Configuration/QuickMessageConfiguration.cs b/SharedLibraryCore/Configuration/QuickMessageConfiguration.cs new file mode 100644 index 00000000..22438d77 --- /dev/null +++ b/SharedLibraryCore/Configuration/QuickMessageConfiguration.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; +using static SharedLibraryCore.Server; + +namespace SharedLibraryCore.Configuration +{ + public class QuickMessageConfiguration + { + + public Game Game { get; set; } + public Dictionary Messages { get; set; } + } +} diff --git a/SharedLibraryCore/Dtos/PenaltyInfo.cs b/SharedLibraryCore/Dtos/PenaltyInfo.cs index 995bc098..fccd6ba0 100644 --- a/SharedLibraryCore/Dtos/PenaltyInfo.cs +++ b/SharedLibraryCore/Dtos/PenaltyInfo.cs @@ -1,8 +1,6 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using static SharedLibraryCore.Database.Models.EFClient; +using static SharedLibraryCore.Objects.Penalty; namespace SharedLibraryCore.Dtos { @@ -16,13 +14,19 @@ namespace SharedLibraryCore.Dtos public int PunisherId { get; set; } public ulong PunisherNetworkId { get; set; } public string PunisherIPAddress { get; set; } - public string PunisherLevel { get; set; } - public int PunisherLevelId { get; set; } + public Permission PunisherLevel { get; set; } + public string PunisherLevelText => PunisherLevel.ToLocalizedLevelName(); public string Offense { get; set; } public string AutomatedOffense { get; set; } - public string PenaltyType { get; set; } - public string TimePunished { get; set; } - public string TimeRemaining { get; set; } - public bool Expired { get; set; } + public PenaltyType PenaltyType { get; set; } + public string PenaltyTypeText => PenaltyType.ToString(); + public DateTime TimePunished { get; set; } + public string TimePunishedString => Utilities.GetTimePassed(TimePunished, true); + public string TimeRemaining => DateTime.UtcNow > Expires ? "" : $"{((Expires ?? DateTime.MaxValue).Year == DateTime.MaxValue.Year ? Utilities.GetTimePassed(TimePunished, true) : Utilities.TimeSpanText((Expires ?? DateTime.MaxValue) - DateTime.UtcNow))}"; + public bool Expired => Expires.HasValue && Expires <= DateTime.UtcNow; + public DateTime? Expires { get; set; } + public override bool Sensitive => PenaltyType == PenaltyType.Flag; + public bool IsEvade { get; set; } + public string AdditionalPenaltyInformation => $"{(!string.IsNullOrEmpty(AutomatedOffense) ? $" ({AutomatedOffense})" : "")}{(IsEvade ? $" ({Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_PENALTY_EVADE"]})" : "")}"; } } diff --git a/SharedLibraryCore/Dtos/PlayerInfo.cs b/SharedLibraryCore/Dtos/PlayerInfo.cs index f6d99104..a72516f3 100644 --- a/SharedLibraryCore/Dtos/PlayerInfo.cs +++ b/SharedLibraryCore/Dtos/PlayerInfo.cs @@ -22,6 +22,8 @@ namespace SharedLibraryCore.Dtos public List Meta { get; set; } public bool Online { get; set; } public string TimeOnline { get; set; } + public DateTime LastConnection { get; set; } + public string LastConnectionText => Utilities.GetTimePassed(LastConnection, true); public IDictionary LinkedAccounts { get; set; } } } diff --git a/SharedLibraryCore/Dtos/SharedInfo.cs b/SharedLibraryCore/Dtos/SharedInfo.cs index 5e142de8..73e0cb41 100644 --- a/SharedLibraryCore/Dtos/SharedInfo.cs +++ b/SharedLibraryCore/Dtos/SharedInfo.cs @@ -3,8 +3,8 @@ namespace SharedLibraryCore.Dtos { public class SharedInfo { - public bool Sensitive { get; set; } + public virtual bool Sensitive { get; set; } public bool Show { get; set; } = true; - public int Id {get;set;} -} + public int Id { get; set; } + } } \ No newline at end of file diff --git a/SharedLibraryCore/Services/PenaltyService.cs b/SharedLibraryCore/Services/PenaltyService.cs index 82f43f57..b8390422 100644 --- a/SharedLibraryCore/Services/PenaltyService.cs +++ b/SharedLibraryCore/Services/PenaltyService.cs @@ -130,22 +130,6 @@ namespace SharedLibraryCore.Services throw new NotImplementedException(); } - public async Task> GetRecentPenalties(int count, int offset, Penalty.PenaltyType showOnly = Penalty.PenaltyType.Any) - { - using (var context = new DatabaseContext(true)) - { - return await context.Penalties - .Include(p => p.Offender.CurrentAlias) - .Include(p => p.Punisher.CurrentAlias) - .Where(p => showOnly == Penalty.PenaltyType.Any ? p.Type != Penalty.PenaltyType.Any : p.Type == showOnly) - .Where(p => p.Active) - .OrderByDescending(p => p.When) - .Skip(offset) - .Take(count) - .ToListAsync(); - } - } - public async Task> GetClientPenaltiesAsync(int clientId) { using (var context = new DatabaseContext(true)) @@ -159,136 +143,79 @@ namespace SharedLibraryCore.Services } } - public async Task> GetAllClientPenaltiesAsync(int clientId, int count, int offset, DateTime? startAt) + public async Task> GetRecentPenalties(int count, int offset, Penalty.PenaltyType showOnly = Penalty.PenaltyType.Any) { - using (var ctx = new DatabaseContext(true)) + using (var context = new DatabaseContext(true)) { - var iqPenalties = ctx.Penalties.AsNoTracking() - .Include(_penalty => _penalty.Offender.CurrentAlias) - .Include(_penalty => _penalty.Punisher.CurrentAlias) - .Where(_penalty => _penalty.Active) - .Where(_penalty => _penalty.OffenderId == clientId || _penalty.PunisherId == clientId) - .Where(_penalty => _penalty.When < startAt) - .OrderByDescending(_penalty => _penalty.When) + var iqPenalties = context.Penalties + .Where(p => showOnly == Penalty.PenaltyType.Any ? p.Type != Penalty.PenaltyType.Any : p.Type == showOnly) + .Where(p => p.Active) + .OrderByDescending(p => p.When) .Skip(offset) - .Take(count); + .Take(count) + .Select(_penalty => new PenaltyInfo() + { + Id = _penalty.PenaltyId, + Offense = _penalty.Offense, + AutomatedOffense = _penalty.AutomatedOffense, + OffenderId = _penalty.OffenderId, + OffenderName = _penalty.Offender.CurrentAlias.Name, + PunisherId = _penalty.PunisherId, + PunisherName = _penalty.Punisher.CurrentAlias.Name, + PunisherLevel = _penalty.Punisher.Level, + PenaltyType = _penalty.Type, + Expires = _penalty.Expires, + TimePunished = _penalty.When, + IsEvade = _penalty.IsEvadedOffense + }); +#if DEBUG == true + var querySql = iqPenalties.ToSql(); +#endif return await iqPenalties.ToListAsync(); } } /// - /// Get a read-only copy of client penalties + /// retrieves penalty information for meta service /// - /// - /// Retreive penalties for clients receiving penalties, other wise given + /// database id of the client + /// how many items to retrieve + /// not used + /// retreive penalties older than this /// - public async Task> ReadGetClientPenaltiesAsync(int clientId, bool victim = true) + public async Task> GetClientPenaltyForMetaAsync(int clientId, int count, int offset, DateTime? startAt) { - using (var context = new DatabaseContext(true)) + using (var ctx = new DatabaseContext(true)) { - // todo: clean this up - if (victim) - { - var now = DateTime.UtcNow; - var iqPenalties = from penalty in context.Penalties.AsNoTracking() - where penalty.OffenderId == clientId - join victimClient in context.Clients.AsNoTracking() - on penalty.OffenderId equals victimClient.ClientId - join victimAlias in context.Aliases.AsNoTracking() - on victimClient.CurrentAliasId equals victimAlias.AliasId - join punisherClient in context.Clients.AsNoTracking() - on penalty.PunisherId equals punisherClient.ClientId - join punisherAlias in context.Aliases.AsNoTracking() - on punisherClient.CurrentAliasId equals punisherAlias.AliasId - //orderby penalty.When descending - select new ProfileMeta() - { - Key = "Event.Penalty", - Value = new PenaltyInfo - { - Id = penalty.PenaltyId, - OffenderName = victimAlias.Name, - OffenderId = victimClient.ClientId, - PunisherName = punisherAlias.Name, - PunisherId = penalty.PunisherId, - Offense = penalty.Offense, - PenaltyType = penalty.Type.ToString(), - TimeRemaining = penalty.Expires.HasValue ? (now > penalty.Expires ? "" : penalty.Expires.ToString()) : DateTime.MaxValue.ToString(), - AutomatedOffense = penalty.AutomatedOffense, - Expired = penalty.Expires.HasValue && penalty.Expires <= DateTime.UtcNow - }, - When = penalty.When, - Sensitive = penalty.Type == Penalty.PenaltyType.Flag - }; - // fixme: is this good and fast? - var list = await iqPenalties.ToListAsync(); - list.ForEach(p => + var iqPenalties = ctx.Penalties.AsNoTracking() + .Where(_penalty => _penalty.Active) + .Where(_penalty => _penalty.OffenderId == clientId || _penalty.PunisherId == clientId) + .Where(_penalty => _penalty.When < startAt) + .OrderByDescending(_penalty => _penalty.When) + .Skip(offset) + .Take(count) + .Select(_penalty => new PenaltyInfo() { - // todo: why does this have to be done? - if (((PenaltyInfo)p.Value).PenaltyType.Length < 2) - { - ((PenaltyInfo)p.Value).PenaltyType = ((Penalty.PenaltyType)Convert.ToInt32(((PenaltyInfo)p.Value).PenaltyType)).ToString(); - } - - var pi = ((PenaltyInfo)p.Value); - if (pi.TimeRemaining?.Length > 0) - { - pi.TimeRemaining = (DateTime.Parse(((PenaltyInfo)p.Value).TimeRemaining) - now).TimeSpanText(); - - if (!pi.Expired) - { - pi.TimeRemaining = $"{pi.TimeRemaining} {Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_PENALTY_TEMPLATE_REMAINING"]}"; - } - } - }); - return list; - } - - else - { - var iqPenalties = from penalty in context.Penalties.AsNoTracking() - where penalty.PunisherId == clientId - join victimClient in context.Clients.AsNoTracking() - on penalty.OffenderId equals victimClient.ClientId - join victimAlias in context.Aliases - on victimClient.CurrentAliasId equals victimAlias.AliasId - join punisherClient in context.Clients - on penalty.PunisherId equals punisherClient.ClientId - join punisherAlias in context.Aliases - on punisherClient.CurrentAliasId equals punisherAlias.AliasId - //orderby penalty.When descending - select new ProfileMeta() - { - Key = "Event.Penalty", - Value = new PenaltyInfo - { - Id = penalty.PenaltyId, - OffenderName = victimAlias.Name, - OffenderId = victimClient.ClientId, - PunisherName = punisherAlias.Name, - PunisherId = penalty.PunisherId, - Offense = penalty.Offense, - PenaltyType = penalty.Type.ToString(), - AutomatedOffense = penalty.AutomatedOffense - }, - When = penalty.When, - Sensitive = penalty.Type == Penalty.PenaltyType.Flag - }; - // fixme: is this good and fast? - var list = await iqPenalties.ToListAsync(); - - list.ForEach(p => - { - // todo: why does this have to be done? - if (((PenaltyInfo)p.Value).PenaltyType.Length < 2) - { - ((PenaltyInfo)p.Value).PenaltyType = ((Penalty.PenaltyType)Convert.ToInt32(((PenaltyInfo)p.Value).PenaltyType)).ToString(); - } + Id = _penalty.PenaltyId, + Offense = _penalty.Offense, + AutomatedOffense = _penalty.AutomatedOffense, + OffenderId = _penalty.OffenderId, + OffenderName = _penalty.Offender.CurrentAlias.Name, + PunisherId = _penalty.PunisherId, + PunisherName = _penalty.Punisher.CurrentAlias.Name, + PunisherLevel = _penalty.Punisher.Level, + PenaltyType = _penalty.Type, + Expires = _penalty.Expires, + TimePunished = _penalty.When, + IsEvade = _penalty.IsEvadedOffense }); - return list; - } +#if DEBUG == true + var querySql = iqPenalties.ToSql(); +#endif + + return await iqPenalties.ToListAsync(); } } diff --git a/SharedLibraryCore/Utilities.cs b/SharedLibraryCore/Utilities.cs index a24e1b00..a0f5d5bb 100644 --- a/SharedLibraryCore/Utilities.cs +++ b/SharedLibraryCore/Utilities.cs @@ -596,19 +596,6 @@ namespace SharedLibraryCore return response; } - public static int ClientIdFromString(String[] lineSplit, int cIDPos) - { - int pID = -2; // apparently falling = -1 cID so i can't use it now - int.TryParse(lineSplit[cIDPos].Trim(), out pID); - - if (pID == -1) // special case similar to mod_suicide - { - int.TryParse(lineSplit[2], out pID); - } - - return pID; - } - public static Dictionary DictionaryFromKeyValue(this string eventLine) { string[] values = eventLine.Substring(1).Split('\\'); diff --git a/WebfrontCore/Controllers/AccountController.cs b/WebfrontCore/Controllers/AccountController.cs index 4052070f..a75437aa 100644 --- a/WebfrontCore/Controllers/AccountController.cs +++ b/WebfrontCore/Controllers/AccountController.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Mvc; +using SharedLibraryCore; using System; using System.Security.Claims; using System.Threading.Tasks; @@ -24,10 +25,14 @@ namespace WebfrontCore.Controllers try { +#if DEBUG == true + var client = Utilities.IW4MAdminClient(); + bool loginSuccess = true; +#else var client = Manager.GetPrivilegedClients()[clientId]; - bool loginSuccess = Manager.TokenAuthenticator.AuthorizeToken(client.NetworkId, password) || (await Task.FromResult(SharedLibraryCore.Helpers.Hashing.Hash(password, client.PasswordSalt)))[0] == client.Password; +#endif if (loginSuccess) { diff --git a/WebfrontCore/Controllers/ClientController.cs b/WebfrontCore/Controllers/ClientController.cs index 6ad7706d..dbfc5ab4 100644 --- a/WebfrontCore/Controllers/ClientController.cs +++ b/WebfrontCore/Controllers/ClientController.cs @@ -119,7 +119,7 @@ namespace WebfrontCore.Controllers Name = c.Name, Level = c.Level.ToLocalizedLevelName(), LevelInt = (int)c.Level, - // todo: add back last seen for search + LastConnection = c.LastConnection, ClientId = c.ClientId }) .ToList(); diff --git a/WebfrontCore/Controllers/PenaltyController.cs b/WebfrontCore/Controllers/PenaltyController.cs index 6d1c5084..86695057 100644 --- a/WebfrontCore/Controllers/PenaltyController.cs +++ b/WebfrontCore/Controllers/PenaltyController.cs @@ -10,12 +10,13 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using WebfrontCore.ViewComponents; +using static SharedLibraryCore.Objects.Penalty; namespace WebfrontCore.Controllers { public class PenaltyController : BaseController { - public IActionResult List(int showOnly = (int)SharedLibraryCore.Objects.Penalty.PenaltyType.Any) + public IActionResult List(PenaltyType showOnly = PenaltyType.Any) { ViewBag.Description = "List of all the recent penalties (bans, kicks, warnings) on IW4MAdmin"; ViewBag.Title = Localization["WEBFRONT_PENALTY_TITLE"]; @@ -24,12 +25,12 @@ namespace WebfrontCore.Controllers return View((SharedLibraryCore.Objects.Penalty.PenaltyType)showOnly); } - public async Task ListAsync(int offset = 0, int showOnly = (int)SharedLibraryCore.Objects.Penalty.PenaltyType.Any) + public async Task ListAsync(int offset = 0, PenaltyType showOnly = PenaltyType.Any) { return await Task.FromResult(View("_List", new ViewModels.PenaltyFilterInfo() { Offset = offset, - ShowOnly = (SharedLibraryCore.Objects.Penalty.PenaltyType)showOnly + ShowOnly = showOnly })); } @@ -47,7 +48,7 @@ namespace WebfrontCore.Controllers // todo: this seems like it's pulling unnecessary info from LINQ to entities. var iqPenalties = ctx.Penalties .AsNoTracking() - .Where(p => p.Type == SharedLibraryCore.Objects.Penalty.PenaltyType.Ban && p.Active) + .Where(p => p.Type == PenaltyType.Ban && p.Active) .OrderByDescending(_penalty => _penalty.When) .Select(p => new PenaltyInfo() { @@ -61,9 +62,7 @@ namespace WebfrontCore.Controllers PunisherNetworkId = (ulong)p.Punisher.NetworkId, PunisherName = p.Punisher.CurrentAlias.Name, PunisherIPAddress = Authorized ? p.Punisher.CurrentAlias.IPAddress.ConvertIPtoString() : null, - PenaltyType = p.Type.ToString(), - TimePunished = p.When.ToString(), - TimeRemaining = null, + TimePunished = p.When, AutomatedOffense = Authorized ? p.AutomatedOffense : null, }); #if DEBUG == true diff --git a/WebfrontCore/ViewComponents/PenaltyListViewComponent.cs b/WebfrontCore/ViewComponents/PenaltyListViewComponent.cs index c95c63ab..553937f3 100644 --- a/WebfrontCore/ViewComponents/PenaltyListViewComponent.cs +++ b/WebfrontCore/ViewComponents/PenaltyListViewComponent.cs @@ -1,9 +1,5 @@ using Microsoft.AspNetCore.Mvc; -using SharedLibraryCore; -using SharedLibraryCore.Database.Models; -using SharedLibraryCore.Dtos; using SharedLibraryCore.Objects; -using System; using System.Linq; using System.Threading.Tasks; @@ -11,42 +7,14 @@ namespace WebfrontCore.ViewComponents { public class PenaltyListViewComponent : ViewComponent { + private const int PENALTY_COUNT = 15; + public async Task InvokeAsync(int offset, Penalty.PenaltyType showOnly) { - string showEvadeString(EFPenalty penalty) => penalty.IsEvadedOffense == true ? - $"({Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_PENALTY_EVADE"]}) " : ""; + var penalties = await Program.Manager.GetPenaltyService().GetRecentPenalties(PENALTY_COUNT, offset, showOnly); + penalties = User.Identity.IsAuthenticated ? penalties : penalties.Where(p => !p.Sensitive).ToList(); - var penalties = await Program.Manager.GetPenaltyService().GetRecentPenalties(12, offset, showOnly); - var penaltiesDto = penalties.Select(p => new PenaltyInfo() - { - Id = p.PenaltyId, - OffenderId = p.OffenderId, - OffenderName = p.Offender.Name, - PunisherId = p.PunisherId, - PunisherName = p.Punisher.Name, - PunisherLevel = p.Punisher.Level.ToLocalizedLevelName(), - PunisherLevelId = (int)p.Punisher.Level, -#if DEBUG - Offense = !string.IsNullOrEmpty(p.AutomatedOffense) ? p.AutomatedOffense : p.Offense, -#else - Offense = (User.Identity.IsAuthenticated && !string.IsNullOrEmpty(p.AutomatedOffense)) ? - $"{showEvadeString(p)}{p.AutomatedOffense}" : - $"{showEvadeString(p)}{p.Offense}", -#endif - PenaltyType = p.Type.ToString(), - TimePunished = Utilities.GetTimePassed(p.When, false), - // show time passed if ban - TimeRemaining = DateTime.UtcNow > p.Expires ? "" : $"{((p.Expires ?? DateTime.MaxValue).Year == DateTime.MaxValue.Year ? Utilities.GetTimePassed(p.When, true) : Utilities.TimeSpanText((p.Expires ?? DateTime.MaxValue) - DateTime.UtcNow))}", - Sensitive = p.Type == Penalty.PenaltyType.Flag, - AutomatedOffense = p.AutomatedOffense - }); - -#if DEBUG - penaltiesDto = penaltiesDto.ToList(); -#else - penaltiesDto = User.Identity.IsAuthenticated ? penaltiesDto.ToList() : penaltiesDto.Where(p => !p.Sensitive).ToList(); -#endif - return View("_List", penaltiesDto); + return View("_List", penalties); } } } diff --git a/WebfrontCore/Views/Client/Find/Index.cshtml b/WebfrontCore/Views/Client/Find/Index.cshtml index 61aa6e16..dafd3fd3 100644 --- a/WebfrontCore/Views/Client/Find/Index.cshtml +++ b/WebfrontCore/Views/Client/Find/Index.cshtml @@ -1,24 +1,40 @@ @model List -@{ +@{ var loc = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex; } -
-

@ViewBag.Title

-
-
@loc["WEBFRONT_PENALTY_TEMPLATE_NAME"]
-
@loc["WEBFRONT_PROFILE_LEVEL"]
-
@loc["WEBFRONT_PROFILE_LSEEN"]
-
+
+

@ViewBag.Title

+
+
+
@loc["WEBFRONT_PENALTY_TEMPLATE_NAME"]
+
@loc["WEBFRONT_PROFILE_LEVEL"]
+
@loc["WEBFRONT_SEARCH_LAST_CONNECTED"]
+
- @{ - foreach (var client in Model) + @foreach (var client in Model) {
@Html.ActionLink(client.Name, "ProfileAsync", "Client", new { id = client.ClientId })
@client.Level
- @*
@client.LastSeen @loc["WEBFRONT_PENALTY_TEMPLATE_AGO"]
*@ +
@client.LastConnectionText
} +
+
+
+
@ViewBag.Title
+ @foreach (var client in Model) + { +
+
@loc["WEBFRONT_PENALTY_TEMPLATE_NAME"]
+
@loc["WEBFRONT_PROFILE_LEVEL"]
+
@loc["WEBFRONT_SEARCH_LAST_CONNECTED"]
+
+
+
@Html.ActionLink(client.Name, "ProfileAsync", "Client", new { id = client.ClientId },new { @class = "link-inverse" } )
+
@client.Level
+
@client.LastConnectionText
+
}
\ No newline at end of file diff --git a/WebfrontCore/Views/Client/_MessageContext.cshtml b/WebfrontCore/Views/Client/_MessageContext.cshtml deleted file mode 100644 index c40a9fba..00000000 --- a/WebfrontCore/Views/Client/_MessageContext.cshtml +++ /dev/null @@ -1,12 +0,0 @@ -@model IEnumerable -@{ - Layout = null; -} - -
-
@Model.First().Time.ToString()
- @foreach (var message in Model) - { - @message.Name — @message.Message
- } -
\ No newline at end of file diff --git a/WebfrontCore/Views/Penalty/List.cshtml b/WebfrontCore/Views/Penalty/List.cshtml index 9d97d39a..20cbabc9 100644 --- a/WebfrontCore/Views/Penalty/List.cshtml +++ b/WebfrontCore/Views/Penalty/List.cshtml @@ -2,7 +2,7 @@ @{ var loc = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex; } -

@ViewBag.Title

+

@ViewBag.Title