diff --git a/Application/IW4MServer.cs b/Application/IW4MServer.cs index b9551a5be..cf5b24b47 100644 --- a/Application/IW4MServer.cs +++ b/Application/IW4MServer.cs @@ -1003,7 +1003,7 @@ namespace IW4MAdmin { if (!Throttled) { - var _event = new GameEvent() + var gameEvent = new GameEvent { Type = GameEvent.EventType.ConnectionLost, Owner = this, @@ -1013,36 +1013,18 @@ namespace IW4MAdmin Data = ConnectionErrors.ToString() }; - Manager.AddEvent(_event); + Manager.AddEvent(gameEvent); } + RunServerCollection(); + return true; } LastMessage = DateTime.Now - start; lastCount = DateTime.Now; - var appConfig = _serviceProvider.GetService(); - // update the player history - if (lastCount - playerCountStart >= appConfig.ServerDataCollectionInterval) - { - var maxItems = Math.Ceiling(appConfig.MaxClientHistoryTime.TotalMinutes / - appConfig.ServerDataCollectionInterval.TotalMinutes); - - while (ClientHistory.ClientCounts.Count > maxItems) - { - ClientHistory.ClientCounts.RemoveAt(0); - } - - ClientHistory.ClientCounts.Add(new ClientCountSnapshot - { - ClientCount = ClientNum, - ConnectionInterrupted = Throttled, - Time = DateTime.UtcNow, - Map = CurrentMap.Name - }); - playerCountStart = DateTime.Now; - } + RunServerCollection(); // send out broadcast messages if (LastMessage.TotalSeconds > Manager.GetApplicationSettings().Configuration().AutoMessagePeriod @@ -1090,6 +1072,34 @@ namespace IW4MAdmin } } + private void RunServerCollection() + { + var appConfig = _serviceProvider.GetService(); + + if (lastCount - playerCountStart < appConfig?.ServerDataCollectionInterval) + { + return; + } + + var maxItems = Math.Ceiling(appConfig.MaxClientHistoryTime.TotalMinutes / + appConfig.ServerDataCollectionInterval.TotalMinutes); + + while (ClientHistory.ClientCounts.Count > maxItems) + { + ClientHistory.ClientCounts.RemoveAt(0); + } + + ClientHistory.ClientCounts.Add(new ClientCountSnapshot + { + ClientCount = ClientNum, + ConnectionInterrupted = Throttled, + Time = DateTime.UtcNow, + Map = CurrentMap.Name + }); + + playerCountStart = DateTime.Now; + } + public async Task Initialize() { try diff --git a/SharedLibraryCore/Dtos/ClientHistoryInfo.cs b/SharedLibraryCore/Dtos/ClientHistoryInfo.cs index 1d99a769f..876be62f5 100644 --- a/SharedLibraryCore/Dtos/ClientHistoryInfo.cs +++ b/SharedLibraryCore/Dtos/ClientHistoryInfo.cs @@ -11,11 +11,8 @@ namespace SharedLibraryCore.Dtos public class ClientCountSnapshot { - private const int UpdateInterval = 5; public DateTime Time { get; set; } - public string TimeString => new DateTime(Time.Year, Time.Month, Time.Day, Time.Hour, - Math.Min(59, UpdateInterval * (int)Math.Round(Time.Minute / (float)UpdateInterval)), 0) - .ToString("yyyy-MM-ddTHH:mm:ssZ"); + public string TimeString => Time.ToString("yyyy-MM-ddTHH:mm:ssZ"); public int ClientCount { get; set; } public bool ConnectionInterrupted { get;set; } public string Map { get; set; }