more changes to the event management.
bots ip adjusted
This commit is contained in:
parent
af6361144e
commit
87541c4a5a
@ -51,24 +51,8 @@ namespace IW4MAdmin.Application
|
|||||||
|
|
||||||
public GameEvent GetNextEvent()
|
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 &&
|
if (DelayedEventQueue.Count > 0 &&
|
||||||
(DateTime.Now - LastDelayedEvent).TotalMilliseconds > DelayAmount)
|
(DateTime.Now - LastDelayedEvent).TotalMilliseconds > DelayAmount)
|
||||||
{
|
{
|
||||||
LastDelayedEvent = DateTime.Now;
|
LastDelayedEvent = DateTime.Now;
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
@ -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;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,16 +79,29 @@ namespace IW4MAdmin.Application
|
|||||||
return Instance ?? (Instance = new ApplicationManager());
|
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)
|
while (Running)
|
||||||
{
|
{
|
||||||
taskList.Clear();
|
// select the server ids that have completed the update task
|
||||||
foreach (var server in Servers)
|
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
|
try
|
||||||
{
|
{
|
||||||
@ -104,13 +117,11 @@ namespace IW4MAdmin.Application
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
#if DEBUG
|
#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.GetMaxThreads(out int workerThreads, out int n);
|
||||||
ThreadPool.GetAvailableThreads(out int availableThreads, out int m);
|
ThreadPool.GetAvailableThreads(out int availableThreads, out int m);
|
||||||
Logger.WriteDebug($"There are {workerThreads - availableThreads} active threading tasks");
|
Logger.WriteDebug($"There are {workerThreads - availableThreads} active threading tasks");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
await Task.WhenAny(taskList);
|
|
||||||
await Task.Delay(ConfigHandler.Configuration().RConPollRate);
|
await Task.Delay(ConfigHandler.Configuration().RConPollRate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -380,7 +391,7 @@ namespace IW4MAdmin.Application
|
|||||||
// start heartbeat
|
// start heartbeat
|
||||||
Task.Run(() => SendHeartbeat(new HeartbeatState()));
|
Task.Run(() => SendHeartbeat(new HeartbeatState()));
|
||||||
#endif
|
#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
|
#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>();
|
var eventList = new List<Task>();
|
||||||
@ -446,12 +457,6 @@ namespace IW4MAdmin.Application
|
|||||||
await processEvent(queuedEvent);
|
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
|
// signal that all events have been processed
|
||||||
OnEvent.Reset();
|
OnEvent.Reset();
|
||||||
}
|
}
|
||||||
@ -462,7 +467,6 @@ namespace IW4MAdmin.Application
|
|||||||
_servers.Clear();
|
_servers.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void Stop()
|
public void Stop()
|
||||||
{
|
{
|
||||||
Running = false;
|
Running = false;
|
||||||
|
@ -119,7 +119,8 @@ namespace Application.RconParsers
|
|||||||
|
|
||||||
if (P.IsBot)
|
if (P.IsBot)
|
||||||
{
|
{
|
||||||
P.IPAddress = P.ClientNumber + 1;
|
// set it to 127.0.0.2
|
||||||
|
P.IPAddress = 33554559;
|
||||||
}
|
}
|
||||||
|
|
||||||
StatusPlayers.Add(P);
|
StatusPlayers.Add(P);
|
||||||
|
@ -56,9 +56,11 @@ namespace IW4MAdmin
|
|||||||
|
|
||||||
public async Task OnPlayerJoined(Player logClient)
|
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;
|
Players[logClient.ClientNumber] = logClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,13 +80,27 @@ namespace IW4MAdmin
|
|||||||
if (Players[polledPlayer.ClientNumber] != null &&
|
if (Players[polledPlayer.ClientNumber] != null &&
|
||||||
Players[polledPlayer.ClientNumber].NetworkId == polledPlayer.NetworkId &&
|
Players[polledPlayer.ClientNumber].NetworkId == polledPlayer.NetworkId &&
|
||||||
// only update if they're unauthenticated
|
// 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
|
// update their ping & score
|
||||||
Players[polledPlayer.ClientNumber].Ping = polledPlayer.Ping;
|
Players[polledPlayer.ClientNumber].Ping = polledPlayer.Ping;
|
||||||
Players[polledPlayer.ClientNumber].Score = polledPlayer.Score;
|
Players[polledPlayer.ClientNumber].Score = polledPlayer.Score;
|
||||||
return true;
|
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 !DEBUG
|
||||||
if (polledPlayer.Name.Length < 3)
|
if (polledPlayer.Name.Length < 3)
|
||||||
{
|
{
|
||||||
@ -260,7 +276,7 @@ namespace IW4MAdmin
|
|||||||
Leaving.TotalConnectionTime += (int)(DateTime.UtcNow - Leaving.ConnectionTime).TotalSeconds;
|
Leaving.TotalConnectionTime += (int)(DateTime.UtcNow - Leaving.ConnectionTime).TotalSeconds;
|
||||||
Leaving.LastConnection = DateTime.UtcNow;
|
Leaving.LastConnection = DateTime.UtcNow;
|
||||||
await Manager.GetClientService().Update(Leaving);
|
await Manager.GetClientService().Update(Leaving);
|
||||||
Players.RemoveAt(cNum);
|
Players[cNum] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -372,7 +388,10 @@ namespace IW4MAdmin
|
|||||||
Owner = this
|
Owner = this
|
||||||
};
|
};
|
||||||
|
|
||||||
e.Origin.State = Player.ClientState.Disconnecting;
|
if (e.Origin != null)
|
||||||
|
{
|
||||||
|
e.Origin.State = Player.ClientState.Disconnecting;
|
||||||
|
}
|
||||||
|
|
||||||
Manager.GetEventHandler().AddEvent(e);
|
Manager.GetEventHandler().AddEvent(e);
|
||||||
}
|
}
|
||||||
@ -530,7 +549,10 @@ namespace IW4MAdmin
|
|||||||
// all polled players should be authenticated
|
// all polled players should be authenticated
|
||||||
foreach (var client in AuthQueue.GetAuthenticatedClients())
|
foreach (var client in AuthQueue.GetAuthenticatedClients())
|
||||||
{
|
{
|
||||||
await AddPlayer(client);
|
if (Players[client.ClientNumber] == null || Players[client.ClientNumber].State == Player.ClientState.Connecting)
|
||||||
|
{
|
||||||
|
await AddPlayer(client);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return CurrentPlayers.Count;
|
return CurrentPlayers.Count;
|
||||||
@ -549,7 +571,7 @@ namespace IW4MAdmin
|
|||||||
{
|
{
|
||||||
// todo: fix up disconnect
|
// todo: fix up disconnect
|
||||||
//for (int i = 0; i < Players.Count; i++)
|
//for (int i = 0; i < Players.Count; i++)
|
||||||
// await RemovePlayer(i);
|
// await RemovePlayer(i);
|
||||||
|
|
||||||
foreach (var plugin in SharedLibraryCore.Plugins.PluginImporter.ActivePlugins)
|
foreach (var plugin in SharedLibraryCore.Plugins.PluginImporter.ActivePlugins)
|
||||||
await plugin.OnUnloadAsync();
|
await plugin.OnUnloadAsync();
|
||||||
|
@ -187,7 +187,7 @@ namespace SharedLibraryCore
|
|||||||
return id;
|
return id;
|
||||||
var bot = Regex.Match(str, @"bot[0-9]+").Value;
|
var bot = Regex.Match(str, @"bot[0-9]+").Value;
|
||||||
if (!string.IsNullOrEmpty(bot))
|
if (!string.IsNullOrEmpty(bot))
|
||||||
return -Convert.ToInt64(bot.Substring(3)) + 1;
|
return -1;//Convert.ToInt64(bot.Substring(3)) + 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user