Make stats update after 10 kills so we don't wait quite as long

Gracefully disconnect clients on shutting down again
This commit is contained in:
RaidMax 2019-08-24 10:02:53 -05:00
parent 563c73221e
commit 6726217354
4 changed files with 55 additions and 15 deletions

View File

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

View File

@ -572,6 +572,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 playerCountStart = DateTime.Now;
DateTime lastCount = DateTime.Now;
@ -579,18 +603,12 @@ namespace IW4MAdmin
override public async Task<bool> ProcessUpdatesAsync(CancellationToken cts)
{
try
{
#region SHUTDOWN
if (Manager.CancellationToken.IsCancellationRequested)
{
if (cts.IsCancellationRequested)
{
foreach (var plugin in SharedLibraryCore.Plugins.PluginImporter.ActivePlugins)
{
await plugin.OnUnloadAsync();
}
await ShutdownInternal();
return true;
}
#endregion
try
{
@ -738,6 +756,12 @@ namespace IW4MAdmin
return true;
}
catch (TaskCanceledException)
{
await ShutdownInternal();
return true;
}
// this one is ok
catch (ServerException e)
{

View File

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

View File

@ -436,15 +436,19 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
// sync their stats before they leave
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))
{
ctx.Update(clientStats);
await ctx.SaveChangesAsync();
}
// increment the total play time
serverStats.TotalPlayTime += pl.ConnectionLength;
}
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;
}
if (clientStats.SessionKills % Detection.MAX_TRACKED_HIT_COUNT == 0)
{
await SaveClientStats(clientStats);
}
try
{
if (Plugin.Config.Configuration().StoreClientKills)