1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-06-10 15:20:48 -05:00

fix remote commands

user clientkick_for_reason for T6 parsers
small bug fixes
This commit is contained in:
RaidMax
2018-12-01 12:17:53 -06:00
parent 08d497153a
commit 6d79c8210e
10 changed files with 85 additions and 73 deletions

View File

@ -75,11 +75,11 @@ namespace SharedLibraryCore.Database.Models
{
ConnectionTime = DateTime.UtcNow;
ClientNumber = -1;
DelayedEvents = new Queue<GameEvent>();
_additionalProperties = new Dictionary<string, object>
{
{ "_reportCount", 0 }
};
CurrentAlias = new EFAlias();
}
public override string ToString()
@ -481,6 +481,7 @@ namespace SharedLibraryCore.Database.Models
if (Level != Permission.Banned &&
currentBan.Type == Penalty.PenaltyType.Ban)
{
CurrentServer.Logger.WriteInfo($"Banned client {this} connected using a new GUID");
// hack: re apply the automated offense to the reban
if (currentBan.AutomatedOffense != null)
{
@ -557,8 +558,7 @@ namespace SharedLibraryCore.Database.Models
[NotMapped]
public ClientState State { get; set; }
[NotMapped]
public Queue<GameEvent> DelayedEvents { get; set; }
[NotMapped]
// this is kinda dirty, but I need localizable level names
public ClientPermission ClientPermission => new ClientPermission()

View File

@ -79,6 +79,8 @@ namespace SharedLibraryCore.Services
if (hasExistingAlias && !entity.AliasLink.Active)
{
entity.CurrentServer.Logger.WriteDebug($"Removing temporary alias for ${entity}");
// we want to delete the temporary alias
context.Entry(entity.CurrentAlias).State = EntityState.Deleted;
entity.CurrentAlias = null;
@ -97,6 +99,8 @@ namespace SharedLibraryCore.Services
// update the temporary alias to permanent one
else if (!entity.AliasLink.Active)
{
entity.CurrentServer.Logger.WriteDebug($"Linking permanent alias for ${entity}");
// we want to track the current alias and link
var alias = context.Update(entity.CurrentAlias).Entity;
var _aliasLink = context.Update(entity.AliasLink).Entity;
@ -119,16 +123,15 @@ namespace SharedLibraryCore.Services
Name = name,
};
var iqExistingPermission = context.Clients.Where(c => c.AliasLinkId == existingAlias.LinkId)
.OrderByDescending(client => client.Level)
.Select(c => new EFClient() { Level = c.Level });
if (!hasExistingAlias)
{
entity.CurrentServer.Logger.WriteDebug($"Connecting player does not have an existing alias {entity}");
}
entity.Level = hasExistingAlias ?
(await iqExistingPermission.FirstOrDefaultAsync())?.Level ?? Permission.User :
await context.Clients.Where(c => c.AliasLinkId == existingAlias.LinkId)
.MaxAsync(c => c.Level) :
Permission.User;
#if DEBUG
string sql = iqExistingPermission.AsQueryable().ToSql();
#endif
if (entity.CurrentAlias != existingAlias ||
entity.AliasLink != aliasLink)

View File

@ -1,13 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using SharedLibraryCore.Database;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Dtos;
using Microsoft.EntityFrameworkCore;
using SharedLibraryCore.Objects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using static SharedLibraryCore.Database.Models.EFClient;
namespace SharedLibraryCore.Services
@ -87,6 +87,7 @@ namespace SharedLibraryCore.Services
public async Task<IList<EFPenalty>> 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)
@ -96,17 +97,20 @@ namespace SharedLibraryCore.Services
.Skip(offset)
.Take(count)
.ToListAsync();
}
}
public async Task<IList<EFPenalty>> GetClientPenaltiesAsync(int clientId)
{
using (var context = new DatabaseContext(true))
{
return await context.Penalties
.Where(p => p.OffenderId == clientId)
.Where(p => p.Active)
.Include(p => p.Offender.CurrentAlias)
.Include(p => p.Punisher.CurrentAlias)
.ToListAsync();
}
}
/// <summary>
@ -146,7 +150,7 @@ namespace SharedLibraryCore.Services
PunisherId = penalty.PunisherId,
Offense = penalty.Offense,
Type = penalty.Type.ToString(),
TimeRemaining = penalty.Expires.HasValue ? (now > penalty.Expires ? "" : penalty.Expires.ToString()) : DateTime.MaxValue.ToString(),
TimeRemaining = penalty.Expires.HasValue ? (now > penalty.Expires ? "" : penalty.Expires.ToString()) : DateTime.MaxValue.ToString(),
AutomatedOffense = penalty.AutomatedOffense
},
When = penalty.When,
@ -158,12 +162,15 @@ namespace SharedLibraryCore.Services
{
// todo: why does this have to be done?
if (((PenaltyInfo)p.Value).Type.Length < 2)
{
((PenaltyInfo)p.Value).Type = ((Penalty.PenaltyType)Convert.ToInt32(((PenaltyInfo)p.Value).Type)).ToString();
}
var pi = ((PenaltyInfo)p.Value);
if (pi.TimeRemaining?.Length > 0)
{
pi.TimeRemaining = (DateTime.Parse(((PenaltyInfo)p.Value).TimeRemaining) - now).TimeSpanText();
}
});
return list;
}
@ -205,7 +212,9 @@ namespace SharedLibraryCore.Services
{
// todo: why does this have to be done?
if (((PenaltyInfo)p.Value).Type.Length < 2)
{
((PenaltyInfo)p.Value).Type = ((Penalty.PenaltyType)Convert.ToInt32(((PenaltyInfo)p.Value).Type)).ToString();
}
});
return list;
@ -217,24 +226,33 @@ namespace SharedLibraryCore.Services
{
var now = DateTime.UtcNow;
Expression<Func<EFPenalty, bool>> filter = (p) => new Penalty.PenaltyType[]
{
Penalty.PenaltyType.TempBan,
Penalty.PenaltyType.Ban, Penalty.PenaltyType.Flag
}.Contains(p.Type) &&
p.Active &&
(p.Expires == null || p.Expires > now);
using (var context = new DatabaseContext(true))
{
var iqPenalties = context.Penalties
.Where(p => p.LinkId == linkId ||
ip.HasValue ? p.Link.Children.Any(a => a.IPAddress == ip) : false)
.Where(p => p.Type == Penalty.PenaltyType.TempBan ||
p.Type == Penalty.PenaltyType.Ban ||
p.Type == Penalty.PenaltyType.Flag)
.Where(p => p.Active)
.Where(p => p.Expires == null || p.Expires > now);
var iqLinkPenalties = context.Penalties
.Where(p => p.LinkId == linkId)
.Where(filter);
var iqIPPenalties = context.Aliases
.Where(a => a.IPAddress == ip)
.SelectMany(a => a.Link.ReceivedPenalties)
.Where(filter);
#if DEBUG == true
var penaltiesSql = iqPenalties.ToSql();
var penaltiesSql = iqLinkPenalties.ToSql();
var ipPenaltiesSql = iqIPPenalties.ToSql();
#endif
var activePenalties = await iqPenalties.ToListAsync();
var activePenalties = (await iqLinkPenalties.ToListAsync()).Union(await iqIPPenalties.ToListAsync());
// this is a bit more performant in memory (ordering)
return activePenalties.OrderByDescending(p =>p.When).ToList();
return activePenalties.OrderByDescending(p => p.When).ToList();
}
}