more changes to the event management.
bots ip adjusted
This commit is contained in:
parent
af6361144e
commit
87541c4a5a
@ -51,22 +51,6 @@ namespace IW4MAdmin.Application
|
||||
|
||||
public GameEvent GetNextEvent()
|
||||
{
|
||||
if (EventQueue.Count > 0)
|
||||
{
|
||||
#if DEBUG
|
||||
Manager.GetLogger().WriteDebug("Getting next event to be processed");
|
||||
#endif
|
||||
if (!EventQueue.TryDequeue(out GameEvent newEvent))
|
||||
{
|
||||
Manager.GetLogger().WriteWarning("Could not dequeue event for processing");
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
return newEvent;
|
||||
}
|
||||
}
|
||||
|
||||
if (DelayedEventQueue.Count > 0 &&
|
||||
(DateTime.Now - LastDelayedEvent).TotalMilliseconds > DelayAmount)
|
||||
{
|
||||
@ -85,6 +69,22 @@ namespace IW4MAdmin.Application
|
||||
}
|
||||
}
|
||||
|
||||
if (EventQueue.Count > 0)
|
||||
{
|
||||
#if DEBUG
|
||||
Manager.GetLogger().WriteDebug("Getting next event to be processed");
|
||||
#endif
|
||||
if (!EventQueue.TryDequeue(out GameEvent newEvent))
|
||||
{
|
||||
Manager.GetLogger().WriteWarning("Could not dequeue event for processing");
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
return newEvent;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -79,16 +79,29 @@ namespace IW4MAdmin.Application
|
||||
return Instance ?? (Instance = new ApplicationManager());
|
||||
}
|
||||
|
||||
public async Task UpdateStatus(object state)
|
||||
public async Task UpdateServerStates()
|
||||
{
|
||||
var taskList = new List<Task>();
|
||||
// store the server hash code and task for it
|
||||
var runningUpdateTasks = new Dictionary<int, Task>();
|
||||
|
||||
while (Running)
|
||||
{
|
||||
taskList.Clear();
|
||||
foreach (var server in Servers)
|
||||
// select the server ids that have completed the update task
|
||||
var serverTasksToRemove = runningUpdateTasks
|
||||
.Where(ut => ut.Value.Status != TaskStatus.Running)
|
||||
.Select(ut => ut.Key)
|
||||
.ToList();
|
||||
|
||||
// remove the update tasks as they have completd
|
||||
foreach (int serverId in serverTasksToRemove)
|
||||
{
|
||||
taskList.Add(Task.Run(async () =>
|
||||
runningUpdateTasks.Remove(serverId);
|
||||
}
|
||||
|
||||
// select the servers where the tasks have completed
|
||||
foreach (var server in Servers.Where(s => serverTasksToRemove.Count == 0 ? true : serverTasksToRemove.Contains(GetHashCode())))
|
||||
{
|
||||
runningUpdateTasks.Add(server.GetHashCode(), Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -104,13 +117,11 @@ namespace IW4MAdmin.Application
|
||||
}));
|
||||
}
|
||||
#if DEBUG
|
||||
Logger.WriteDebug($"{taskList.Count} servers queued for stats updates");
|
||||
Logger.WriteDebug($"{runningUpdateTasks.Count} servers queued for stats updates");
|
||||
ThreadPool.GetMaxThreads(out int workerThreads, out int n);
|
||||
ThreadPool.GetAvailableThreads(out int availableThreads, out int m);
|
||||
Logger.WriteDebug($"There are {workerThreads - availableThreads} active threading tasks");
|
||||
#endif
|
||||
|
||||
await Task.WhenAny(taskList);
|
||||
await Task.Delay(ConfigHandler.Configuration().RConPollRate);
|
||||
}
|
||||
}
|
||||
@ -380,7 +391,7 @@ namespace IW4MAdmin.Application
|
||||
// start heartbeat
|
||||
Task.Run(() => SendHeartbeat(new HeartbeatState()));
|
||||
#endif
|
||||
Task.Run(() => UpdateStatus(null));
|
||||
Task.Run(() => UpdateServerStates());
|
||||
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
||||
|
||||
var eventList = new List<Task>();
|
||||
@ -446,12 +457,6 @@ namespace IW4MAdmin.Application
|
||||
await processEvent(queuedEvent);
|
||||
}
|
||||
|
||||
if (taskList.Count > 0)
|
||||
{
|
||||
// this should allow parallel processing of events
|
||||
await Task.WhenAny(taskList);
|
||||
}
|
||||
|
||||
// signal that all events have been processed
|
||||
OnEvent.Reset();
|
||||
}
|
||||
@ -462,7 +467,6 @@ namespace IW4MAdmin.Application
|
||||
_servers.Clear();
|
||||
}
|
||||
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
Running = false;
|
||||
|
@ -119,7 +119,8 @@ namespace Application.RconParsers
|
||||
|
||||
if (P.IsBot)
|
||||
{
|
||||
P.IPAddress = P.ClientNumber + 1;
|
||||
// set it to 127.0.0.2
|
||||
P.IPAddress = 33554559;
|
||||
}
|
||||
|
||||
StatusPlayers.Add(P);
|
||||
|
@ -56,9 +56,11 @@ namespace IW4MAdmin
|
||||
|
||||
public async Task OnPlayerJoined(Player logClient)
|
||||
{
|
||||
Logger.WriteDebug($"Log detected {logClient} joining");
|
||||
if (Players[logClient.ClientNumber] == null || Players[logClient.ClientNumber].NetworkId != logClient.NetworkId)
|
||||
|
||||
if (Players[logClient.ClientNumber] == null ||
|
||||
Players[logClient.ClientNumber].NetworkId != logClient.NetworkId)
|
||||
{
|
||||
Logger.WriteDebug($"Log detected {logClient} joining");
|
||||
Players[logClient.ClientNumber] = logClient;
|
||||
}
|
||||
|
||||
@ -78,13 +80,27 @@ namespace IW4MAdmin
|
||||
if (Players[polledPlayer.ClientNumber] != null &&
|
||||
Players[polledPlayer.ClientNumber].NetworkId == polledPlayer.NetworkId &&
|
||||
// only update if they're unauthenticated
|
||||
Players[polledPlayer.ClientNumber].IsAuthenticated)
|
||||
Players[polledPlayer.ClientNumber].IsAuthenticated &&
|
||||
Players[polledPlayer.ClientNumber].State == Player.ClientState.Connected)
|
||||
{
|
||||
// update their ping & score
|
||||
Players[polledPlayer.ClientNumber].Ping = polledPlayer.Ping;
|
||||
Players[polledPlayer.ClientNumber].Score = polledPlayer.Score;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Players[polledPlayer.ClientNumber] != null &&
|
||||
Players[polledPlayer.ClientNumber].State == Player.ClientState.Connected)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Players[polledPlayer.ClientNumber] == null)
|
||||
{
|
||||
//prevent duplicates from being added
|
||||
polledPlayer.State = Player.ClientState.Connecting;
|
||||
Players[polledPlayer.ClientNumber] = polledPlayer;
|
||||
}
|
||||
#if !DEBUG
|
||||
if (polledPlayer.Name.Length < 3)
|
||||
{
|
||||
@ -260,7 +276,7 @@ namespace IW4MAdmin
|
||||
Leaving.TotalConnectionTime += (int)(DateTime.UtcNow - Leaving.ConnectionTime).TotalSeconds;
|
||||
Leaving.LastConnection = DateTime.UtcNow;
|
||||
await Manager.GetClientService().Update(Leaving);
|
||||
Players.RemoveAt(cNum);
|
||||
Players[cNum] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -372,7 +388,10 @@ namespace IW4MAdmin
|
||||
Owner = this
|
||||
};
|
||||
|
||||
if (e.Origin != null)
|
||||
{
|
||||
e.Origin.State = Player.ClientState.Disconnecting;
|
||||
}
|
||||
|
||||
Manager.GetEventHandler().AddEvent(e);
|
||||
}
|
||||
@ -529,9 +548,12 @@ namespace IW4MAdmin
|
||||
|
||||
// all polled players should be authenticated
|
||||
foreach (var client in AuthQueue.GetAuthenticatedClients())
|
||||
{
|
||||
if (Players[client.ClientNumber] == null || Players[client.ClientNumber].State == Player.ClientState.Connecting)
|
||||
{
|
||||
await AddPlayer(client);
|
||||
}
|
||||
}
|
||||
|
||||
return CurrentPlayers.Count;
|
||||
}
|
||||
|
@ -187,7 +187,7 @@ namespace SharedLibraryCore
|
||||
return id;
|
||||
var bot = Regex.Match(str, @"bot[0-9]+").Value;
|
||||
if (!string.IsNullOrEmpty(bot))
|
||||
return -Convert.ToInt64(bot.Substring(3)) + 1;
|
||||
return -1;//Convert.ToInt64(bot.Substring(3)) + 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user