diff --git a/Application/API/Master/Heartbeat.cs b/Application/API/Master/Heartbeat.cs index 7fbb1843c..16e34a076 100644 --- a/Application/API/Master/Heartbeat.cs +++ b/Application/API/Master/Heartbeat.cs @@ -47,7 +47,7 @@ namespace IW4MAdmin.Application.API.Master Map = s.CurrentMap.Name, MaxClientNum = s.MaxClients, Id = s.EndPoint, - Port = (short)s.GetPort(), + Port = (short)s.Port, IPAddress = s.IP }).ToList() }; diff --git a/Application/ApplicationManager.cs b/Application/ApplicationManager.cs index ec06da989..4566c96bc 100644 --- a/Application/ApplicationManager.cs +++ b/Application/ApplicationManager.cs @@ -45,7 +45,7 @@ namespace IW4MAdmin.Application public string ExternalIPAddress { get; private set; } public bool IsRestartRequested { get; private set; } static ApplicationManager Instance; - readonly List TaskStatuses; + private readonly List _taskStatuses; List Commands; readonly List MessageTokens; ClientService ClientSvc; @@ -64,7 +64,7 @@ namespace IW4MAdmin.Application { _servers = new ConcurrentBag(); Commands = new List(); - TaskStatuses = new List(); + _taskStatuses = new List(); MessageTokens = new List(); ClientSvc = new ClientService(); AliasSvc = new AliasService(); diff --git a/Application/GameEventHandler.cs b/Application/GameEventHandler.cs index c186ef975..a082e5881 100644 --- a/Application/GameEventHandler.cs +++ b/Application/GameEventHandler.cs @@ -9,15 +9,15 @@ namespace IW4MAdmin.Application { class GameEventHandler : IEventHandler { - readonly IManager Manager; + readonly ApplicationManager Manager; public GameEventHandler(IManager mgr) { - Manager = mgr; + Manager = (ApplicationManager)mgr; } public void AddEvent(GameEvent gameEvent) { - ((Manager as ApplicationManager).OnServerEvent)(this, new GameEventArgs(null, false, gameEvent)); + Manager.OnServerEvent?.Invoke(gameEvent.Owner, new GameEventArgs(null, false, gameEvent)); } } } diff --git a/Application/IW4MServer.cs b/Application/IW4MServer.cs index ec4c3ec5b..dfd6c0682 100644 --- a/Application/IW4MServer.cs +++ b/Application/IW4MServer.cs @@ -26,7 +26,6 @@ namespace IW4MAdmin { private static readonly Index loc = Utilities.CurrentLocalization.LocalizationIndex; private GameLogEventDetection LogEvent; - private DateTime SessionStart; public int Id { get; private set; } @@ -211,7 +210,7 @@ namespace IW4MAdmin return false; } - CONNECT: + //CONNECT: if (Clients[E.Origin.ClientNumber] == null) { #if DEBUG == true @@ -250,8 +249,8 @@ namespace IW4MAdmin else { Logger.WriteWarning($"{E.Origin} is connecting but {Clients[E.Origin.ClientNumber]} is currently in that client slot"); - await OnClientDisconnected(Clients[E.Origin.ClientNumber]); - goto CONNECT; + //await OnClientDisconnected(Clients[E.Origin.ClientNumber]); + //goto CONNECT; } } @@ -457,7 +456,6 @@ namespace IW4MAdmin if (E.Type == GameEvent.EventType.MapEnd) { Logger.WriteInfo("Game ending..."); - SessionStart = DateTime.UtcNow; } if (E.Type == GameEvent.EventType.Tell) diff --git a/Application/Main.cs b/Application/Main.cs index 1fa987613..f456fa7d9 100644 --- a/Application/Main.cs +++ b/Application/Main.cs @@ -202,28 +202,33 @@ namespace IW4MAdmin.Application string lastCommand; var Origin = Utilities.IW4MAdminClient(ServerManager.Servers[0]); - while (!ServerManager.CancellationToken.IsCancellationRequested) + try { - lastCommand = Console.ReadLine(); - - if (lastCommand?.Length > 0) + while (!ServerManager.CancellationToken.IsCancellationRequested) { + lastCommand = Console.ReadLine(); + if (lastCommand?.Length > 0) { - GameEvent E = new GameEvent() + if (lastCommand?.Length > 0) { - Type = GameEvent.EventType.Command, - Data = lastCommand, - Origin = Origin, - Owner = ServerManager.Servers[0] - }; + GameEvent E = new GameEvent() + { + Type = GameEvent.EventType.Command, + Data = lastCommand, + Origin = Origin, + Owner = ServerManager.Servers[0] + }; - ServerManager.GetEventHandler().AddEvent(E); - await E.WaitAsync(Utilities.DefaultCommandTimeout, ServerManager.CancellationToken); - Console.Write('>'); + ServerManager.GetEventHandler().AddEvent(E); + await E.WaitAsync(Utilities.DefaultCommandTimeout, ServerManager.CancellationToken); + Console.Write('>'); + } } } } + catch (OperationCanceledException) + { } } } } diff --git a/GameLogServer/GameLogServer/log_reader.py b/GameLogServer/GameLogServer/log_reader.py index d9d274acc..3ad9bbf8c 100644 --- a/GameLogServer/GameLogServer/log_reader.py +++ b/GameLogServer/GameLogServer/log_reader.py @@ -6,7 +6,7 @@ class LogReader(object): def __init__(self): self.log_file_sizes = {} # (if the time between checks is greater, ignore ) - in seconds - self.max_file_time_change = 30 + self.max_file_time_change = 60 def read_file(self, path): # this removes old entries that are no longer valid diff --git a/Plugins/Stats/Helpers/StatManager.cs b/Plugins/Stats/Helpers/StatManager.cs index 1089bb142..4b23f8eb7 100644 --- a/Plugins/Stats/Helpers/StatManager.cs +++ b/Plugins/Stats/Helpers/StatManager.cs @@ -216,7 +216,7 @@ namespace IW4MAdmin.Plugins.Stats.Helpers { server = new EFServer() { - Port = sv.GetPort(), + Port = sv.Port, EndPoint = sv.ToString(), ServerId = serverId, GameName = sv.GameName @@ -1230,12 +1230,12 @@ namespace IW4MAdmin.Plugins.Stats.Helpers public static async Task GetIdForServer(Server server) { - if ($"{server.IP}:{server.GetPort().ToString()}" == "66.150.121.184:28965") + if ($"{server.IP}:{server.Port.ToString()}" == "66.150.121.184:28965") { return 886229536; } - long id = HashCode.Combine(server.IP, server.GetPort()); + long id = HashCode.Combine(server.IP, server.Port); id = id < 0 ? Math.Abs(id) : id; long? serverId; diff --git a/SharedLibraryCore/Commands/NativeCommands.cs b/SharedLibraryCore/Commands/NativeCommands.cs index c84f9c11f..cc7caf9ab 100644 --- a/SharedLibraryCore/Commands/NativeCommands.cs +++ b/SharedLibraryCore/Commands/NativeCommands.cs @@ -1180,7 +1180,7 @@ namespace SharedLibraryCore.Commands var regex = Regex.Match(cmdLine, @".*((?:\+set|\+) net_port) +([0-9]+).*"); - if (regex.Success && Int32.Parse(regex.Groups[2].Value) == E.Owner.GetPort()) + if (regex.Success && Int32.Parse(regex.Groups[2].Value) == E.Owner.Port) { currentProcess = p; } diff --git a/SharedLibraryCore/Server.cs b/SharedLibraryCore/Server.cs index 6e95ace03..0c23ecb69 100644 --- a/SharedLibraryCore/Server.cs +++ b/SharedLibraryCore/Server.cs @@ -52,13 +52,10 @@ namespace SharedLibraryCore public long EndPoint => Convert.ToInt64($"{IP.Replace(".", "")}{Port}"); - //Returns current server port set by `net_port` -- *INT* - public int GetPort() - { - return Port; - } - - //Returns list of all current players + /// + /// Returns list of all current players + /// + /// public List GetClientsAsList() { return Clients.FindAll(x => x != null && x.NetworkId != 0); @@ -69,18 +66,18 @@ namespace SharedLibraryCore /// /// EFClient pulled from memory reading /// True if player added sucessfully, false otherwise - abstract public Task OnClientConnected(EFClient P); + public abstract Task OnClientConnected(EFClient P); /// /// Remove player by client number /// /// Client ID of player to be removed /// true if removal succeded, false otherwise - abstract public Task OnClientDisconnected(EFClient client); - + public abstract Task OnClientDisconnected(EFClient client); /// /// Get a player by name + /// todo: make this an extension /// /// EFClient name to search for /// Matching player if found @@ -113,8 +110,8 @@ namespace SharedLibraryCore /// /// Event /// True on sucess - abstract protected Task ProcessEvent(GameEvent E); - abstract public Task ExecuteEvent(GameEvent E); + protected abstract Task ProcessEvent(GameEvent E); + public abstract Task ExecuteEvent(GameEvent E); /// /// Send a message to all players @@ -233,11 +230,6 @@ namespace SharedLibraryCore await this.ExecuteCommandAsync($"map {mapName}"); } - public async Task LoadMap(Map newMap) - { - await this.ExecuteCommandAsync($"map {newMap.Name}"); - } - /// /// Initalize the macro variables /// @@ -323,7 +315,7 @@ namespace SharedLibraryCore public string Version { get; protected set; } public bool IsInitialized { get; set; } - protected int Port; + public int Port { get; private set; } protected string FSGame; protected int NextMessage; protected int ConnectionErrors; diff --git a/WebfrontCore/Controllers/API/APIController.cs b/WebfrontCore/Controllers/API/APIController.cs index 845243a26..e1ec8ddf6 100644 --- a/WebfrontCore/Controllers/API/APIController.cs +++ b/WebfrontCore/Controllers/API/APIController.cs @@ -31,7 +31,7 @@ namespace WebfrontCore.Controllers.API CurrentPlayers = server.GetClientsAsList().Count, Map = server.CurrentMap, GameMode = server.Gametype, - Port = server.GetPort(), + Port = server.Port, Game = server.GameName.ToString(), Players = server.GetClientsAsList() .Select(player => new @@ -67,7 +67,7 @@ namespace WebfrontCore.Controllers.API return serverToRestart != null ? (IActionResult)Json(new { - port = serverToRestart.GetPort() + port = serverToRestart.Port }) : Unauthorized(); } diff --git a/WebfrontCore/Controllers/ServerController.cs b/WebfrontCore/Controllers/ServerController.cs index 4b5601ce4..0b7749b75 100644 --- a/WebfrontCore/Controllers/ServerController.cs +++ b/WebfrontCore/Controllers/ServerController.cs @@ -22,7 +22,7 @@ namespace WebfrontCore.Controllers { Name = s.Hostname, ID = s.EndPoint, - Port = s.GetPort(), + Port = s.Port, Map = s.CurrentMap.Alias, ClientCount = s.ClientNum, MaxClients = s.MaxClients, diff --git a/WebfrontCore/ViewComponents/ServerListViewComponent.cs b/WebfrontCore/ViewComponents/ServerListViewComponent.cs index f009187dc..25d97d00f 100644 --- a/WebfrontCore/ViewComponents/ServerListViewComponent.cs +++ b/WebfrontCore/ViewComponents/ServerListViewComponent.cs @@ -16,7 +16,7 @@ namespace WebfrontCore.ViewComponents { Name = s.Hostname, ID = s.EndPoint, - Port = s.GetPort(), + Port = s.Port, Map = s.CurrentMap.Alias, ClientCount = s.ClientNum, MaxClients = s.MaxClients, @@ -32,8 +32,8 @@ namespace WebfrontCore.ViewComponents }).ToList(), ChatHistory = s.ChatHistory.ToList(), Online = !s.Throttled, - IPAddress = $"{(IPAddress.Parse(s.IP).IsInternal() ? Program.Manager.ExternalIPAddress : s.IP)}:{s.GetPort()}", - ConnectProtocolUrl = s.EventParser.URLProtocolFormat.FormatExt(IPAddress.Parse(s.IP).IsInternal() ? Program.Manager.ExternalIPAddress : s.IP, s.GetPort()) + IPAddress = $"{(IPAddress.Parse(s.IP).IsInternal() ? Program.Manager.ExternalIPAddress : s.IP)}:{s.Port}", + ConnectProtocolUrl = s.EventParser.URLProtocolFormat.FormatExt(IPAddress.Parse(s.IP).IsInternal() ? Program.Manager.ExternalIPAddress : s.IP, s.Port) }).ToList(); return View("_List", serverInfo); }