From 4623cc6e12be118bcb4ac196a6d21ec29bad0b4f Mon Sep 17 00:00:00 2001 From: RaidMax Date: Wed, 9 Oct 2019 15:51:02 -0500 Subject: [PATCH] fix small exit exceptions fix the live radar tab switching for .net core 3.0 change events to use "sequential" but still parallel update the publish scripts --- Application/ApplicationManager.cs | 23 ++++++++++++++++++ Application/BuildScripts/PostPublish.bat | 8 +++---- Application/GameEventHandler.cs | 24 ++++++++++++++++++- Application/IO/GameLogEventDetection.cs | 2 -- Application/IW4MServer.cs | 1 - .../LiveRadar/Controllers/RadarController.cs | 2 +- RunPublishPre.cmd | 6 ++--- RunPublishRelease.cmd | 6 ++--- SharedLibraryCore/Server.cs | 2 ++ 9 files changed, 59 insertions(+), 15 deletions(-) diff --git a/Application/ApplicationManager.cs b/Application/ApplicationManager.cs index 21e3b948..3f527b1f 100644 --- a/Application/ApplicationManager.cs +++ b/Application/ApplicationManager.cs @@ -96,6 +96,7 @@ namespace IW4MAdmin.Application try { + await newEvent.Owner.EventProcessing.WaitAsync(CancellationToken); await newEvent.Owner.ExecuteEvent(newEvent); // save the event info to the database @@ -107,6 +108,16 @@ namespace IW4MAdmin.Application #endif } + catch (TaskCanceledException) + { + Logger.WriteInfo($"Received quit signal for event id {newEvent.Id}, so we are aborting early"); + } + + catch (OperationCanceledException) + { + Logger.WriteInfo($"Received quit signal for event id {newEvent.Id}, so we are aborting early"); + } + // this happens if a plugin requires login catch (AuthorizationException ex) { @@ -134,6 +145,18 @@ namespace IW4MAdmin.Application Logger.WriteDebug(ex.GetExceptionInfo()); } + finally + { + if (newEvent.Owner.EventProcessing.CurrentCount == 0) + { + newEvent.Owner.EventProcessing.Release(1); + } + +#if DEBUG == true + Logger.WriteDebug($"Exiting event process for {args.Event.Id}"); +#endif + } + skip: // tell anyone waiting for the output that we're done diff --git a/Application/BuildScripts/PostPublish.bat b/Application/BuildScripts/PostPublish.bat index ccd533d4..31839a44 100644 --- a/Application/BuildScripts/PostPublish.bat +++ b/Application/BuildScripts/PostPublish.bat @@ -31,10 +31,10 @@ if exist "%SolutionDir%Publish\WindowsPrerelease\ko\" powershell Remove-Item -Fo if exist "%SolutionDir%Publish\WindowsPrerelease\ru\" powershell Remove-Item -Force -Recurse '%SolutionDir%Publish\WindowsPrerelease\ru' if exist "%SolutionDir%Publish\WindowsPrerelease\zh-Hans\" powershell Remove-Item -Force -Recurse '%SolutionDir%Publish\WindowsPrerelease\zh-Hans' if exist "%SolutionDir%Publish\WindowsPrerelease\zh-Hant\" powershell Remove-Item -Force -Recurse '%SolutionDir%Publish\WindowsPrerelease\zh-Hant' -if exist "%SolutionDir%Publish\WindowsPrerelease\cs\" powershell Remove-Item -Force -Recurse '%SolutionDir%Publish\Windows\cs' -if exist "%SolutionDir%Publish\WindowsPrerelease\pl\" powershell Remove-Item -Force -Recurse '%SolutionDir%Publish\Windows\pl' -if exist "%SolutionDir%Publish\WindowsPrerelease\tr\" powershell Remove-Item -Force -Recurse '%SolutionDir%Publish\Windows\tr' -if exist "%SolutionDir%Publish\WindowsPrerelease\pt-BR\" powershell Remove-Item -Force -Recurse '%SolutionDir%Publish\Windows\pt-BR' +if exist "%SolutionDir%Publish\WindowsPrerelease\cs\" powershell Remove-Item -Force -Recurse '%SolutionDir%Publish\WindowsPrerelease\cs' +if exist "%SolutionDir%Publish\WindowsPrerelease\pl\" powershell Remove-Item -Force -Recurse '%SolutionDir%Publish\WindowsPrerelease\pl' +if exist "%SolutionDir%Publish\WindowsPrerelease\tr\" powershell Remove-Item -Force -Recurse '%SolutionDir%Publish\WindowsPrerelease\tr' +if exist "%SolutionDir%Publish\WindowsPrerelease\pt-BR\" powershell Remove-Item -Force -Recurse '%SolutionDir%Publish\WindowsPrerelease\pt-BR' echo Deleting extra runtime files if exist "%SolutionDir%Publish\Windows\runtimes\linux-arm" powershell Remove-Item -Force -Recurse '%SolutionDir%Publish\Windows\runtimes\linux-arm' diff --git a/Application/GameEventHandler.cs b/Application/GameEventHandler.cs index 1023a94c..6b44d533 100644 --- a/Application/GameEventHandler.cs +++ b/Application/GameEventHandler.cs @@ -1,6 +1,7 @@ using SharedLibraryCore; using SharedLibraryCore.Events; using SharedLibraryCore.Interfaces; +using System.Linq; using System.Threading; namespace IW4MAdmin.Application @@ -8,6 +9,14 @@ namespace IW4MAdmin.Application class GameEventHandler : IEventHandler { readonly ApplicationManager Manager; + private static GameEvent.EventType[] overrideEvents = new[] + { + GameEvent.EventType.Connect, + GameEvent.EventType.Disconnect, + GameEvent.EventType.Quit, + GameEvent.EventType.Stop + }; + public GameEventHandler(IManager mgr) { Manager = (ApplicationManager)mgr; @@ -19,8 +28,21 @@ namespace IW4MAdmin.Application ThreadPool.GetMaxThreads(out int workerThreads, out int n); ThreadPool.GetAvailableThreads(out int availableThreads, out int m); gameEvent.Owner.Logger.WriteDebug($"There are {workerThreads - availableThreads} active threading tasks"); + +#endif + if (Manager.Running || overrideEvents.Contains(gameEvent.Type)) + { +#if DEBUG + gameEvent.Owner.Logger.WriteDebug($"Adding event with id {gameEvent.Id}"); +#endif + Manager.OnServerEvent?.Invoke(gameEvent.Owner, new GameEventArgs(null, false, gameEvent)); + } +#if DEBUG + else + { + gameEvent.Owner.Logger.WriteDebug($"Skipping event as we're shutting down {gameEvent.Id}"); + } #endif - Manager.OnServerEvent?.Invoke(gameEvent.Owner, new GameEventArgs(null, false, gameEvent)); } } } diff --git a/Application/IO/GameLogEventDetection.cs b/Application/IO/GameLogEventDetection.cs index 3b89ccfb..5f25e750 100644 --- a/Application/IO/GameLogEventDetection.cs +++ b/Application/IO/GameLogEventDetection.cs @@ -30,9 +30,7 @@ namespace IW4MAdmin.Application.IO { while (!_server.Manager.CancellationToken.IsCancellationRequested) { -#if !DEBUG if (_server.IsInitialized) -#endif { try { diff --git a/Application/IW4MServer.cs b/Application/IW4MServer.cs index 35415137..b424f7eb 100644 --- a/Application/IW4MServer.cs +++ b/Application/IW4MServer.cs @@ -8,7 +8,6 @@ using SharedLibraryCore.Dtos; using SharedLibraryCore.Exceptions; using SharedLibraryCore.Helpers; using SharedLibraryCore.Interfaces; -using SharedLibraryCore.Localization; using SharedLibraryCore.Services; using System; using System.Collections.Generic; diff --git a/Plugins/LiveRadar/Controllers/RadarController.cs b/Plugins/LiveRadar/Controllers/RadarController.cs index 939bdd2f..d10701e2 100644 --- a/Plugins/LiveRadar/Controllers/RadarController.cs +++ b/Plugins/LiveRadar/Controllers/RadarController.cs @@ -17,7 +17,7 @@ namespace LiveRadar.Web.Controllers [HttpGet] [Route("Radar/{serverId}")] - public IActionResult Index([FromQuery] long? serverId = null) + public IActionResult Index(long? serverId = null) { ViewBag.IsFluid = true; ViewBag.Title = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_RADAR_TITLE"]; diff --git a/RunPublishPre.cmd b/RunPublishPre.cmd index a6ee9f45..59f6de3f 100644 --- a/RunPublishPre.cmd +++ b/RunPublishPre.cmd @@ -1,6 +1,6 @@ -dotnet publish WebfrontCore/WebfrontCore.csproj -c Prerelease -f netcoreapp2.2 --force -o X:\IW4MAdmin\Publish\WindowsPrerelease /p:PublishProfile=Prerelease -dotnet publish Application/Application.csproj -c Prerelease -f netcoreapp2.2 --force -o X:\IW4MAdmin\Publish\WindowsPrerelease /p:PublishProfile=Prerelease -dotnet publish GameLogServer/GameLogServer.pyproj -c Release -f netcoreapp2.2 --force -o X:\IW4MAdmin\Publish\WindowsPrerelease\GameLogServer +dotnet publish WebfrontCore/WebfrontCore.csproj -c Prerelease -f netcoreapp3.0 --force -o X:\IW4MAdmin\Publish\WindowsPrerelease /p:PublishProfile=Prerelease +dotnet publish Application/Application.csproj -c Prerelease -f netcoreapp3.0 --force -o X:\IW4MAdmin\Publish\WindowsPrerelease /p:PublishProfile=Prerelease +dotnet publish GameLogServer/GameLogServer.pyproj -c Release -f netcoreapp3.0 --force -o X:\IW4MAdmin\Publish\WindowsPrerelease\GameLogServer call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\VsDevCmd.bat" msbuild GameLogServer/GameLogServer.pyproj /p:PublishProfile=PreRelease /p:DeployOnBuild=true /p:PublishProfileRootFolder=X:\IW4MAdmin\GameLogServer\ cd "X:\IW4MAdmin\DEPLOY\" diff --git a/RunPublishRelease.cmd b/RunPublishRelease.cmd index df02655d..6af19fd4 100644 --- a/RunPublishRelease.cmd +++ b/RunPublishRelease.cmd @@ -1,6 +1,6 @@ -dotnet publish WebfrontCore/WebfrontCore.csproj -c Release -o X:\IW4MAdmin\Publish\Windows -dotnet publish Application/Application.csproj -c Release -o X:\IW4MAdmin\Publish\Windows -dotnet publish GameLogServer/GameLogServer.pyproj -c Release -o X:\IW4MAdmin\Publish\Windows\GameLogServer +dotnet publish WebfrontCore/WebfrontCore.csproj -c Release -f netcoreapp3.0 --force -o X:\IW4MAdmin\Publish\Windows /p:PublishProfile=sTABLE +dotnet publish Application/Application.csproj -c Release -f netcoreapp3.0 --force -o X:\IW4MAdmin\Publish\Windows /p:PublishProfile=Stable +dotnet publish GameLogServer/GameLogServer.pyproj -c Release -f netcoreapp3.0 --force -o X:\IW4MAdmin\Publish\WindowsPrerelease\GameLogServer call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\VsDevCmd.bat" msbuild GameLogServer/GameLogServer.pyproj /p:PublishProfile=Stable /p:DeployOnBuild=true /p:PublishProfileRootFolder=X:\IW4MAdmin\GameLogServer\ cd "X:\IW4MAdmin\DEPLOY\" diff --git a/SharedLibraryCore/Server.cs b/SharedLibraryCore/Server.cs index 2e37c8c1..10ad0942 100644 --- a/SharedLibraryCore/Server.cs +++ b/SharedLibraryCore/Server.cs @@ -39,6 +39,7 @@ namespace SharedLibraryCore ServerConfig = config; RemoteConnection = new RCon.Connection(IP, Port, Password, Logger, null); + EventProcessing = new SemaphoreSlim(1, 1); Clients = new List(new EFClient[18]); Reports = new List(); ClientHistory = new Queue(); @@ -309,6 +310,7 @@ namespace SharedLibraryCore public IEventParser EventParser { get; set; } public string LogPath { get; protected set; } public bool RestartRequested { get; set; } + public SemaphoreSlim EventProcessing { get; private set; } // Internal public string IP { get; protected set; }