add a check to make sure we're not breaking EFClient entries when updating

make sure the alias is updated before banning the player as we want to link them together
update CoD4x parser to fix their breaking change
This commit is contained in:
RaidMax 2019-06-11 08:00:14 -05:00
parent 82390340c9
commit e86904b11e
7 changed files with 46 additions and 56 deletions

View File

@ -6,7 +6,7 @@
<RuntimeFrameworkVersion>2.2.2</RuntimeFrameworkVersion> <RuntimeFrameworkVersion>2.2.2</RuntimeFrameworkVersion>
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish> <MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
<PackageId>RaidMax.IW4MAdmin.Application</PackageId> <PackageId>RaidMax.IW4MAdmin.Application</PackageId>
<Version>2.2.7.5</Version> <Version>2.2.7.6</Version>
<Authors>RaidMax</Authors> <Authors>RaidMax</Authors>
<Company>Forever None</Company> <Company>Forever None</Company>
<Product>IW4MAdmin</Product> <Product>IW4MAdmin</Product>
@ -32,8 +32,8 @@
<PropertyGroup> <PropertyGroup>
<ServerGarbageCollection>true</ServerGarbageCollection> <ServerGarbageCollection>true</ServerGarbageCollection>
<TieredCompilation>true</TieredCompilation> <TieredCompilation>true</TieredCompilation>
<AssemblyVersion>2.2.7.5</AssemblyVersion> <AssemblyVersion>2.2.7.6</AssemblyVersion>
<FileVersion>2.2.7.5</FileVersion> <FileVersion>2.2.7.6</FileVersion>
<LangVersion>7.1</LangVersion> <LangVersion>7.1</LangVersion>
</PropertyGroup> </PropertyGroup>

View File

@ -84,18 +84,18 @@ namespace IW4MAdmin
if (client.ClientNumber >= 0) if (client.ClientNumber >= 0)
{ {
#endif #endif
Logger.WriteInfo($"Client {client} [{client.State.ToString().ToLower()}] disconnecting..."); Logger.WriteInfo($"Client {client} [{client.State.ToString().ToLower()}] disconnecting...");
Clients[client.ClientNumber] = null; Clients[client.ClientNumber] = null;
await client.OnDisconnect(); await client.OnDisconnect();
var e = new GameEvent() var e = new GameEvent()
{ {
Origin = client, Origin = client,
Owner = this, Owner = this,
Type = GameEvent.EventType.Disconnect Type = GameEvent.EventType.Disconnect
}; };
Manager.GetEventHandler().AddEvent(e); Manager.GetEventHandler().AddEvent(e);
#if DEBUG == true #if DEBUG == true
} }
#endif #endif
@ -571,22 +571,9 @@ namespace IW4MAdmin
{ {
try try
{ {
#region SHUTDOWN #region SHUTDOWN
if (Manager.CancellationToken.IsCancellationRequested) if (Manager.CancellationToken.IsCancellationRequested)
{ {
foreach (var client in GetClientsAsList())
{
var e = new GameEvent()
{
Type = GameEvent.EventType.PreDisconnect,
Origin = client,
Owner = this,
};
Manager.GetEventHandler().AddEvent(e);
await e.WaitAsync(Utilities.DefaultCommandTimeout, Manager.CancellationToken);
}
foreach (var plugin in SharedLibraryCore.Plugins.PluginImporter.ActivePlugins) foreach (var plugin in SharedLibraryCore.Plugins.PluginImporter.ActivePlugins)
{ {
await plugin.OnUnloadAsync(); await plugin.OnUnloadAsync();
@ -594,7 +581,7 @@ namespace IW4MAdmin
return true; return true;
} }
#endregion #endregion
try try
{ {
@ -705,14 +692,14 @@ namespace IW4MAdmin
lastCount = DateTime.Now; lastCount = DateTime.Now;
// update the player history // update the player history
if ((lastCount - playerCountStart).TotalMinutes >= SharedLibraryCore.Helpers.PlayerHistory.UpdateInterval) if ((lastCount - playerCountStart).TotalMinutes >= PlayerHistory.UpdateInterval)
{ {
while (ClientHistory.Count > ((60 / SharedLibraryCore.Helpers.PlayerHistory.UpdateInterval) * 12)) // 12 times a hour for 12 hours while (ClientHistory.Count > ((60 / PlayerHistory.UpdateInterval) * 12)) // 12 times a hour for 12 hours
{ {
ClientHistory.Dequeue(); ClientHistory.Dequeue();
} }
ClientHistory.Enqueue(new SharedLibraryCore.Helpers.PlayerHistory(ClientNum)); ClientHistory.Enqueue(new PlayerHistory(ClientNum));
playerCountStart = DateTime.Now; playerCountStart = DateTime.Now;
} }
@ -1017,13 +1004,20 @@ namespace IW4MAdmin
else else
{ {
#if !DEBUG #if !DEBUG
string formattedString = String.Format(RconParser.Configuration.CommandPrefixes.Kick, targetClient.ClientNumber, $"{loc["SERVER_BAN_TEXT"]} - ^5{reason} ^7{loc["SERVER_BAN_APPEAL"].FormatExt(Website)}^7"); string formattedString = string.Format(RconParser.Configuration.CommandPrefixes.Kick, targetClient.ClientNumber, $"{loc["SERVER_BAN_TEXT"]} - ^5{reason} ^7{loc["SERVER_BAN_APPEAL"].FormatExt(Website)}^7");
await targetClient.CurrentServer.ExecuteCommandAsync(formattedString); await targetClient.CurrentServer.ExecuteCommandAsync(formattedString);
#else #else
await targetClient.CurrentServer.OnClientDisconnected(targetClient); await targetClient.CurrentServer.OnClientDisconnected(targetClient);
#endif #endif
} }
// this should link evading clients
if (isEvade)
{
Logger.WriteInfo($"updating alias for banned client {targetClient}");
await Manager.GetClientService().UpdateAlias(targetClient);
}
EFPenalty newPenalty = new EFPenalty() EFPenalty newPenalty = new EFPenalty()
{ {
Type = EFPenalty.PenaltyType.Ban, Type = EFPenalty.PenaltyType.Ban,
@ -1061,10 +1055,10 @@ namespace IW4MAdmin
override public void InitializeTokens() override public void InitializeTokens()
{ {
Manager.GetMessageTokens().Add(new SharedLibraryCore.Helpers.MessageToken("TOTALPLAYERS", (Server s) => Task.Run(async () => (await Manager.GetClientService().GetTotalClientsAsync()).ToString()))); Manager.GetMessageTokens().Add(new MessageToken("TOTALPLAYERS", (Server s) => Task.Run(async () => (await Manager.GetClientService().GetTotalClientsAsync()).ToString())));
Manager.GetMessageTokens().Add(new SharedLibraryCore.Helpers.MessageToken("VERSION", (Server s) => Task.FromResult(Application.Program.Version.ToString()))); Manager.GetMessageTokens().Add(new MessageToken("VERSION", (Server s) => Task.FromResult(Application.Program.Version.ToString())));
Manager.GetMessageTokens().Add(new SharedLibraryCore.Helpers.MessageToken("NEXTMAP", (Server s) => SharedLibraryCore.Commands.CNextMap.GetNextMap(s))); Manager.GetMessageTokens().Add(new MessageToken("NEXTMAP", (Server s) => SharedLibraryCore.Commands.CNextMap.GetNextMap(s)));
Manager.GetMessageTokens().Add(new SharedLibraryCore.Helpers.MessageToken("ADMINS", (Server s) => Task.FromResult(SharedLibraryCore.Commands.CListAdmins.OnlineAdmins(s)))); Manager.GetMessageTokens().Add(new MessageToken("ADMINS", (Server s) => Task.FromResult(SharedLibraryCore.Commands.CListAdmins.OnlineAdmins(s))));
} }
} }
} }

View File

@ -3,7 +3,7 @@ var eventParser;
var plugin = { var plugin = {
author: 'FrenchFry, RaidMax', author: 'FrenchFry, RaidMax',
version: 0.3, version: 0.4,
name: 'CoD4x Parser', name: 'CoD4x Parser',
isParser: true, isParser: true,
@ -14,7 +14,7 @@ var plugin = {
rconParser = manager.GenerateDynamicRConParser(); rconParser = manager.GenerateDynamicRConParser();
eventParser = manager.GenerateDynamicEventParser(); eventParser = manager.GenerateDynamicEventParser();
rconParser.Configuration.Status.Pattern = '^ *([0-9]+) +-?([0-9]+) +((?:[A-Z]+|[0-9]+)) +((?:[a-z]|[0-9]){16}|(?:[a-z]|[0-9]){32}|bot[0-9]+|(?:[0-9]+)) *(.{0,32}) +([0-9]+) +(\\d+\\.\\d+\\.\\d+.\\d+\\:-*\\d{1,5}|0+.0+:-*\\d{1,5}|loopback) +(-*[0-9]+) +([0-9]+) *$' rconParser.Configuration.Status.Pattern = '^ *([0-9]+) +-?([0-9]+) +((?:[A-Z]+|[0-9]+)) +((?:[a-z]|[0-9]){16,32}|(?:[a-z]|[0-9]){32}|bot[0-9]+) ([0-9+]) *(.{0,32}) +([0-9]+) +(\\d+\\.\\d+\\.\\d+.\\d+\\:-*\\d{1,5}|0+.0+:-*\\d{1,5}|loopback) +(-*[0-9]+) +([0-9]+) *$'
rconParser.Configuration.Status.AddMapping(104, 6); // RConName rconParser.Configuration.Status.AddMapping(104, 6); // RConName
rconParser.Configuration.Status.AddMapping(105, 8); // RConIPAddress rconParser.Configuration.Status.AddMapping(105, 8); // RConIPAddress

View File

@ -23,7 +23,7 @@ namespace IW4MAdmin.Plugins.Stats.Commands
$"^5--{Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_COMMANDS_MOSTPLAYED_TEXT"]}--" $"^5--{Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_COMMANDS_MOSTPLAYED_TEXT"]}--"
}; };
using (var db = new DatabaseContext()) using (var db = new DatabaseContext(true))
{ {
db.ChangeTracker.AutoDetectChangesEnabled = false; db.ChangeTracker.AutoDetectChangesEnabled = false;
db.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; db.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;

View File

@ -249,7 +249,7 @@ namespace Tests
unbanCommand.ExecuteAsync(new GameEvent() unbanCommand.ExecuteAsync(new GameEvent()
{ {
Origin = new EFClient() { ClientId = 1, Level = EFClient.Permission.Console, CurrentServer = client.CurrentServer }, Origin = new EFClient() { ClientId = 1, Level = EFClient.Permission.Console, CurrentServer = client.CurrentServer },
Target = Manager.GetClientService().Find(c => c.NetworkId == client.NetworkId).Result.First(), //Target = Manager.GetClientService().Find(c => c.NetworkId == client.NetworkId).Result.First(),
Data = "test unban", Data = "test unban",
Type = GameEvent.EventType.Command, Type = GameEvent.EventType.Command,
Owner = client.CurrentServer Owner = client.CurrentServer

View File

@ -1115,7 +1115,7 @@ namespace SharedLibraryCore.Commands
.Where(c => c.Level > EFClient.Permission.Flagged && c.Level <= EFClient.Permission.Moderator) .Where(c => c.Level > EFClient.Permission.Flagged && c.Level <= EFClient.Permission.Moderator)
.Where(c => c.LastConnection < lastActive) .Where(c => c.LastConnection < lastActive)
.ToListAsync(); .ToListAsync();
inactiveUsers.ForEach(c => c.SetLevel(EFClient.Permission.User, E.Origin)); inactiveUsers.ForEach(c => c.SetLevel(Permission.User, E.Origin));
await context.SaveChangesAsync(); await context.SaveChangesAsync();
} }
E.Origin.Tell(Utilities.CurrentLocalization.LocalizationIndex["COMMANDS_PRUNE_SUCCESS"].FormatExt(inactiveUsers.Count)); E.Origin.Tell(Utilities.CurrentLocalization.LocalizationIndex["COMMANDS_PRUNE_SUCCESS"].FormatExt(inactiveUsers.Count));

View File

@ -48,7 +48,7 @@ namespace SharedLibraryCore.Services
}; };
context.Clients.Add(client); context.Clients.Add(client);
// they're just using a new GUID // they're just using a new GUID
if (aliasId.HasValue) if (aliasId.HasValue)
{ {
@ -272,18 +272,9 @@ namespace SharedLibraryCore.Services
} }
} }
public async Task<IList<EFClient>> Find(Func<EFClient, bool> e) public Task<IList<EFClient>> Find(Func<EFClient, bool> e)
{ {
return await Task.Run(() => throw new NotImplementedException();
{
using (var context = new DatabaseContext(true))
{
return context.Clients
.Include(c => c.CurrentAlias)
.Include(c => c.AliasLink.Children)
.Where(e).ToList();
}
});
} }
public async Task<EFClient> Get(int entityID) public async Task<EFClient> Get(int entityID)
@ -369,6 +360,11 @@ namespace SharedLibraryCore.Services
{ {
using (var context = new DatabaseContext()) using (var context = new DatabaseContext())
{ {
if (temporalClient.LastConnection == DateTime.MinValue || temporalClient.Connections == 0 || temporalClient.TotalConnectionTime == 0)
{
throw new InvalidOperationException($"client {temporalClient} trying to update but parameters are invalid");
}
// grab the context version of the entity // grab the context version of the entity
var entity = context.Clients var entity = context.Clients
.First(client => client.ClientId == temporalClient.ClientId); .First(client => client.ClientId == temporalClient.ClientId);
@ -407,7 +403,7 @@ namespace SharedLibraryCore.Services
{ {
using (var ctx = new DatabaseContext(true)) using (var ctx = new DatabaseContext(true))
{ {
return await ctx.Clients.AsNoTracking() return await ctx.Clients
.CountAsync(_client => _client.Level == Permission.Owner); .CountAsync(_client => _client.Level == Permission.Owner);
} }
} }
@ -489,7 +485,7 @@ namespace SharedLibraryCore.Services
{ {
iqClients = iqClients.Where(_client => linkIds.Contains(_client.AliasLinkId)); iqClients = iqClients.Where(_client => linkIds.Contains(_client.AliasLinkId));
} }
// we want to project our results // we want to project our results
var iqClientProjection = iqClients.OrderByDescending(_client => _client.LastConnection) var iqClientProjection = iqClients.OrderByDescending(_client => _client.LastConnection)
.Select(_client => new PlayerInfo() .Select(_client => new PlayerInfo()
@ -503,7 +499,7 @@ namespace SharedLibraryCore.Services
var iqClientsSql = iqClients.ToSql(); var iqClientsSql = iqClients.ToSql();
#endif #endif
var clients = await iqClientProjection.ToListAsync(); var clients = await iqClientProjection.ToListAsync();
// this is so we don't try to evaluate this in the linq to entities query // this is so we don't try to evaluate this in the linq to entities query
foreach (var client in clients) foreach (var client in clients)
{ {