diff --git a/Admin/Server.cs b/Admin/Server.cs index 96f6a83e1..3c15de05c 100644 --- a/Admin/Server.cs +++ b/Admin/Server.cs @@ -856,7 +856,7 @@ namespace IW4MAdmin Penalty newPenalty = new Penalty() { Type = Penalty.PenaltyType.Ban, - Expires = DateTime.MinValue, + Expires = DateTime.MaxValue, Offender = Target, Offense = Message, Punisher = Origin, @@ -868,8 +868,21 @@ namespace IW4MAdmin await Manager.GetPenaltyService().Create(newPenalty); } - override public async Task Unban(Player Target) + override public async Task Unban(string reason, Player Target, Player Origin) { + var unbanPenalty = new Penalty() + { + Type = Penalty.PenaltyType.Unban, + Expires = DateTime.UtcNow, + Offender = Target, + Offense = reason, + Punisher = Origin, + When = DateTime.UtcNow, + Active = true, + Link = Target.AliasLink + }; + + await Manager.GetPenaltyService().Create(unbanPenalty); await Manager.GetPenaltyService().RemoveActivePenalties(Target.AliasLink.AliasLinkId); } diff --git a/Admin/Webfront/profile.html b/Admin/Webfront/profile.html index 81ece0082..308a50c37 100644 --- a/Admin/Webfront/profile.html +++ b/Admin/Webfront/profile.html @@ -132,7 +132,8 @@ font-size: 1.5em; } - .penalties-color-kick { + .penalties-color-kick, + .penalties-color-unban { color: rgba(116, 147, 99, 1); } @@ -207,6 +208,8 @@ return "Kicked"; case "TempBan": return "Temp Banned"; + case "Unban": + return "Unbanned"; } } diff --git a/Admin/lib/SharedLibrary.dll b/Admin/lib/SharedLibrary.dll index 8b7ad2235..90eaa7e08 100644 Binary files a/Admin/lib/SharedLibrary.dll and b/Admin/lib/SharedLibrary.dll differ diff --git a/SharedLibrary/Commands/NativeCommands.cs b/SharedLibrary/Commands/NativeCommands.cs index 8675265e0..c0e65fa01 100644 --- a/SharedLibrary/Commands/NativeCommands.cs +++ b/SharedLibrary/Commands/NativeCommands.cs @@ -220,14 +220,27 @@ namespace SharedLibrary.Commands { Name = "databaseID", Required = true, + }, + new CommandArgument() + { + Name = "reason", + Required = true } }) { } public override async Task ExecuteAsync(Event E) { - await E.Owner.Unban(E.Target); - await E.Origin.Tell($"Successfully unbanned {E.Target}"); + var penalties = await E.Owner.Manager.GetPenaltyService().GetActivePenaltiesAsync(E.Target.AliasLinkId); + if (penalties.Where(p => p.Type == Penalty.PenaltyType.Ban).FirstOrDefault() != null) + { + await E.Owner.Unban(E.Data, E.Target, E.Origin); + await E.Origin.Tell($"Successfully unbanned {E.Target}"); + } + else + { + await E.Origin.Tell($"{E.Target} is not banned"); + } } } diff --git a/SharedLibrary/Objects/Penalty.cs b/SharedLibrary/Objects/Penalty.cs index d4b69a933..42343855f 100644 --- a/SharedLibrary/Objects/Penalty.cs +++ b/SharedLibrary/Objects/Penalty.cs @@ -13,6 +13,7 @@ namespace SharedLibrary.Objects Kick, TempBan, Ban, + Unban, Any, } diff --git a/SharedLibrary/Server.cs b/SharedLibrary/Server.cs index 97aa74a5e..6e72fdc47 100644 --- a/SharedLibrary/Server.cs +++ b/SharedLibrary/Server.cs @@ -226,7 +226,7 @@ namespace SharedLibrary /// npID of the player /// I don't remember what this is for /// - abstract public Task Unban(Player Target); + abstract public Task Unban(string reason, Player Target, Player Origin); /// /// Change the current searver map diff --git a/SharedLibrary/Services/ClientService.cs b/SharedLibrary/Services/ClientService.cs index 1b69faa4c..9d8cb8095 100644 --- a/SharedLibrary/Services/ClientService.cs +++ b/SharedLibrary/Services/ClientService.cs @@ -27,7 +27,7 @@ namespace SharedLibrary.Services .ToListAsync(); // see if they have a matching IP + Name but new NetworkId - var existingAlias = aliases.SingleOrDefault(a => a.Name == entity.Name); + var existingAlias = aliases.FirstOrDefault(a => a.Name == entity.Name); // if existing alias matches link them EFAliasLink aliasLink = existingAlias?.Link; // if no exact matches find the first IP that matches diff --git a/SharedLibrary/Services/PenaltyService.cs b/SharedLibrary/Services/PenaltyService.cs index 1a22cb3a5..8d35a1710 100644 --- a/SharedLibrary/Services/PenaltyService.cs +++ b/SharedLibrary/Services/PenaltyService.cs @@ -18,14 +18,16 @@ namespace SharedLibrary.Services { using (var context = new DatabaseContext()) { - entity.Offender = context.Clients.First(e => e.ClientId == entity.Offender.ClientId); - entity.Punisher = context.Clients.First(e => e.ClientId == entity.Punisher.ClientId); - entity.Link = context.AliasLinks.First(l => l.AliasLinkId == entity.Link.AliasLinkId); + entity.Offender = context.Clients.Single(e => e.ClientId == entity.Offender.ClientId); + entity.Punisher = context.Clients.Single(e => e.ClientId == entity.Punisher.ClientId); + entity.Link = context.AliasLinks.Single(l => l.AliasLinkId == entity.Link.AliasLinkId); + + if (entity.Expires == DateTime.MaxValue) + entity.Expires = DateTime.Parse(System.Data.SqlTypes.SqlDateTime.MaxValue.ToString()); // make bans propogate to all aliases if (entity.Type == Objects.Penalty.PenaltyType.Ban) { - entity.Expires = DateTime.Parse(System.Data.SqlTypes.SqlDateTime.MaxValue.ToString()); await context.Clients .Where(c => c.AliasLinkId == entity.Link.AliasLinkId) .ForEachAsync(c => c.Level = Objects.Player.Permission.Banned);