Merge branch '2.3' into 2.4-pr

This commit is contained in:
RaidMax 2019-08-24 11:10:43 -05:00
commit dcd1c97d37
4 changed files with 55 additions and 15 deletions

View File

@ -222,8 +222,15 @@ namespace IW4MAdmin.Application
{ {
await Task.Delay(ConfigHandler.Configuration().RConPollRate, _tokenSource.Token); await Task.Delay(ConfigHandler.Configuration().RConPollRate, _tokenSource.Token);
} }
// if a cancellation is received, we want to return immediately // if a cancellation is received, we want to return immediately after shutting down
catch { break; } catch
{
foreach (var server in Servers.Where(s => serverIds.Contains(s.EndPoint)))
{
await server.ProcessUpdatesAsync(_tokenSource.Token);
}
break;
}
} }
} }

View File

@ -579,6 +579,30 @@ namespace IW4MAdmin
}; };
} }
private async Task ShutdownInternal()
{
foreach (var client in GetClientsAsList())
{
await client.OnDisconnect();
var e = new GameEvent()
{
Type = GameEvent.EventType.Disconnect,
Owner = this,
Origin = client
};
Manager.GetEventHandler().AddEvent(e);
await e.WaitAsync(Utilities.DefaultCommandTimeout, new CancellationTokenRegistration().Token);
}
foreach (var plugin in SharedLibraryCore.Plugins.PluginImporter.ActivePlugins)
{
await plugin.OnUnloadAsync();
}
}
DateTime start = DateTime.Now; DateTime start = DateTime.Now;
DateTime playerCountStart = DateTime.Now; DateTime playerCountStart = DateTime.Now;
DateTime lastCount = DateTime.Now; DateTime lastCount = DateTime.Now;
@ -586,18 +610,12 @@ namespace IW4MAdmin
override public async Task<bool> ProcessUpdatesAsync(CancellationToken cts) override public async Task<bool> ProcessUpdatesAsync(CancellationToken cts)
{ {
try try
{ {
#region SHUTDOWN if (cts.IsCancellationRequested)
if (Manager.CancellationToken.IsCancellationRequested)
{ {
foreach (var plugin in SharedLibraryCore.Plugins.PluginImporter.ActivePlugins) await ShutdownInternal();
{
await plugin.OnUnloadAsync();
}
return true; return true;
} }
#endregion
try try
{ {
@ -745,6 +763,12 @@ namespace IW4MAdmin
return true; return true;
} }
catch (TaskCanceledException)
{
await ShutdownInternal();
return true;
}
// this one is ok // this one is ok
catch (ServerException e) catch (ServerException e)
{ {

View File

@ -79,7 +79,7 @@ namespace AutomessageFeed
public Task OnUnloadAsync() public Task OnUnloadAsync()
{ {
throw new NotImplementedException(); return Task.CompletedTask;
} }
} }
} }

View File

@ -437,15 +437,19 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
// sync their stats before they leave // sync their stats before they leave
clientStats = UpdateStats(clientStats); clientStats = UpdateStats(clientStats);
await SaveClientStats(clientStats);
// increment the total play time
serverStats.TotalPlayTime += pl.ConnectionLength;
}
private static async Task SaveClientStats(EFClientStatistics clientStats)
{
using (var ctx = new DatabaseContext(disableTracking: true)) using (var ctx = new DatabaseContext(disableTracking: true))
{ {
ctx.Update(clientStats); ctx.Update(clientStats);
await ctx.SaveChangesAsync(); await ctx.SaveChangesAsync();
} }
// increment the total play time
serverStats.TotalPlayTime += pl.ConnectionLength;
} }
public void AddDamageEvent(string eventLine, int attackerClientId, int victimClientId, long serverId) public void AddDamageEvent(string eventLine, int attackerClientId, int victimClientId, long serverId)
@ -551,6 +555,11 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
clientStats.HitLocations.Single(hl => hl.Location == hit.HitLoc).HitCount += 1; clientStats.HitLocations.Single(hl => hl.Location == hit.HitLoc).HitCount += 1;
} }
if (clientStats.SessionKills % Detection.MAX_TRACKED_HIT_COUNT == 0)
{
await SaveClientStats(clientStats);
}
try try
{ {
if (Plugin.Config.Configuration().StoreClientKills) if (Plugin.Config.Configuration().StoreClientKills)