Added unban "penalty"

permbans ->MaxValue for consistency
Existing alias needs to be FirstOrDefault
This commit is contained in:
RaidMax 2018-02-17 00:13:38 -06:00
parent c41949588c
commit 8afe5dbb3d
8 changed files with 43 additions and 11 deletions

View File

@ -856,7 +856,7 @@ namespace IW4MAdmin
Penalty newPenalty = new Penalty() Penalty newPenalty = new Penalty()
{ {
Type = Penalty.PenaltyType.Ban, Type = Penalty.PenaltyType.Ban,
Expires = DateTime.MinValue, Expires = DateTime.MaxValue,
Offender = Target, Offender = Target,
Offense = Message, Offense = Message,
Punisher = Origin, Punisher = Origin,
@ -868,8 +868,21 @@ namespace IW4MAdmin
await Manager.GetPenaltyService().Create(newPenalty); 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); await Manager.GetPenaltyService().RemoveActivePenalties(Target.AliasLink.AliasLinkId);
} }

View File

@ -132,7 +132,8 @@
font-size: 1.5em; font-size: 1.5em;
} }
.penalties-color-kick { .penalties-color-kick,
.penalties-color-unban {
color: rgba(116, 147, 99, 1); color: rgba(116, 147, 99, 1);
} }
@ -207,6 +208,8 @@
return "Kicked"; return "Kicked";
case "TempBan": case "TempBan":
return "Temp Banned"; return "Temp Banned";
case "Unban":
return "Unbanned";
} }
} }

Binary file not shown.

View File

@ -220,15 +220,28 @@ namespace SharedLibrary.Commands
{ {
Name = "databaseID", Name = "databaseID",
Required = true, Required = true,
},
new CommandArgument()
{
Name = "reason",
Required = true
} }
}) })
{ } { }
public override async Task ExecuteAsync(Event E) public override async Task ExecuteAsync(Event E)
{ {
await E.Owner.Unban(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}"); await E.Origin.Tell($"Successfully unbanned {E.Target}");
} }
else
{
await E.Origin.Tell($"{E.Target} is not banned");
}
}
} }
public class CWhoAmI : Command public class CWhoAmI : Command

View File

@ -13,6 +13,7 @@ namespace SharedLibrary.Objects
Kick, Kick,
TempBan, TempBan,
Ban, Ban,
Unban,
Any, Any,
} }

View File

@ -226,7 +226,7 @@ namespace SharedLibrary
/// <param name="npID">npID of the player</param> /// <param name="npID">npID of the player</param>
/// <param name="Target">I don't remember what this is for</param> /// <param name="Target">I don't remember what this is for</param>
/// <returns></returns> /// <returns></returns>
abstract public Task Unban(Player Target); abstract public Task Unban(string reason, Player Target, Player Origin);
/// <summary> /// <summary>
/// Change the current searver map /// Change the current searver map

View File

@ -27,7 +27,7 @@ namespace SharedLibrary.Services
.ToListAsync(); .ToListAsync();
// see if they have a matching IP + Name but new NetworkId // 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 // if existing alias matches link them
EFAliasLink aliasLink = existingAlias?.Link; EFAliasLink aliasLink = existingAlias?.Link;
// if no exact matches find the first IP that matches // if no exact matches find the first IP that matches

View File

@ -18,14 +18,16 @@ namespace SharedLibrary.Services
{ {
using (var context = new DatabaseContext()) using (var context = new DatabaseContext())
{ {
entity.Offender = context.Clients.First(e => e.ClientId == entity.Offender.ClientId); entity.Offender = context.Clients.Single(e => e.ClientId == entity.Offender.ClientId);
entity.Punisher = context.Clients.First(e => e.ClientId == entity.Punisher.ClientId); entity.Punisher = context.Clients.Single(e => e.ClientId == entity.Punisher.ClientId);
entity.Link = context.AliasLinks.First(l => l.AliasLinkId == entity.Link.AliasLinkId); 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 // make bans propogate to all aliases
if (entity.Type == Objects.Penalty.PenaltyType.Ban) if (entity.Type == Objects.Penalty.PenaltyType.Ban)
{ {
entity.Expires = DateTime.Parse(System.Data.SqlTypes.SqlDateTime.MaxValue.ToString());
await context.Clients await context.Clients
.Where(c => c.AliasLinkId == entity.Link.AliasLinkId) .Where(c => c.AliasLinkId == entity.Link.AliasLinkId)
.ForEachAsync(c => c.Level = Objects.Player.Permission.Banned); .ForEachAsync(c => c.Level = Objects.Player.Permission.Banned);