collect data when server offline

This commit is contained in:
RaidMax 2022-03-29 17:18:41 -05:00
parent 7dbdf87728
commit 1e67f6e86c
2 changed files with 34 additions and 27 deletions

View File

@ -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<ApplicationConfiguration>();
// 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<ApplicationConfiguration>();
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

View File

@ -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; }