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:
parent
563c73221e
commit
6726217354
@ -220,8 +220,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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 start = DateTime.Now;
|
||||||
DateTime playerCountStart = DateTime.Now;
|
DateTime playerCountStart = DateTime.Now;
|
||||||
DateTime lastCount = DateTime.Now;
|
DateTime lastCount = DateTime.Now;
|
||||||
@ -580,17 +604,11 @@ namespace IW4MAdmin
|
|||||||
{
|
{
|
||||||
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
|
||||||
{
|
{
|
||||||
@ -738,6 +756,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)
|
||||||
{
|
{
|
||||||
|
@ -79,7 +79,7 @@ namespace AutomessageFeed
|
|||||||
|
|
||||||
public Task OnUnloadAsync()
|
public Task OnUnloadAsync()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -436,15 +436,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)
|
||||||
|
Loading…
Reference in New Issue
Block a user