From e91d076b41621077fdc4194c086598323078c0a9 Mon Sep 17 00:00:00 2001 From: RaidMax Date: Wed, 10 Oct 2018 19:22:08 -0500 Subject: [PATCH] curtail lost connection messages from RCon verify still compatible with T6 fix potential null reference exception during configuration reading/setup --- Application/DefaultSettings.json | 10 ---------- Application/Localization/Configure.cs | 8 ++++---- Application/Logger.cs | 2 +- Application/Main.cs | 3 ++- Application/Server.cs | 2 +- Plugins/Stats/Helpers/StatManager.cs | 3 ++- SharedLibraryCore/Database/DatabaseContext.cs | 6 +++--- SharedLibraryCore/RCon/Connection.cs | 6 +++--- WebfrontCore/Startup.cs | 1 - 9 files changed, 16 insertions(+), 25 deletions(-) diff --git a/Application/DefaultSettings.json b/Application/DefaultSettings.json index 7a235b6b4..128d03493 100644 --- a/Application/DefaultSettings.json +++ b/Application/DefaultSettings.json @@ -40,16 +40,6 @@ "Name": "mp_crash" }, - { - "Alias": "Skidrow", - "Name": "mp_nightshift" - }, - - { - "Alias": "Quarry", - "Name": "mp_quarry" - }, - { "Alias": "Afghan", "Name": "mp_afghan" diff --git a/Application/Localization/Configure.cs b/Application/Localization/Configure.cs index 1329e01f9..2219e6142 100644 --- a/Application/Localization/Configure.cs +++ b/Application/Localization/Configure.cs @@ -15,7 +15,7 @@ namespace IW4MAdmin.Application.Localization public static void Initialize(string customLocale) { string currentLocale = string.IsNullOrEmpty(customLocale) ? CultureInfo.CurrentCulture.Name : customLocale; - string[] localizationFiles = Directory.GetFiles("Localization", $"*.{currentLocale}.json"); + string[] localizationFiles = Directory.GetFiles(Path.Join(Utilities.OperatingDirectory, "Localization"), $"*.{currentLocale}.json"); try { @@ -33,13 +33,13 @@ namespace IW4MAdmin.Application.Localization // culture doesn't exist so we just want language if (localizationFiles.Length == 0) { - localizationFiles = Directory.GetFiles("Localization", $"*.{currentLocale.Substring(0, 2)}*.json"); + localizationFiles = Directory.GetFiles(Path.Join(Utilities.OperatingDirectory, "Localization"), $"*.{currentLocale.Substring(0, 2)}*.json"); } // language doesn't exist either so defaulting to english if (localizationFiles.Length == 0) { - localizationFiles = Directory.GetFiles("Localization", "*.en-US.json"); + localizationFiles = Directory.GetFiles(Path.Join(Utilities.OperatingDirectory, "Localization"), "*.en-US.json"); } // this should never happen unless the localization folder is empty @@ -64,7 +64,7 @@ namespace IW4MAdmin.Application.Localization } } - string localizationFile = $"Localization{Path.DirectorySeparatorChar}IW4MAdmin.{currentLocale}-{currentLocale.ToUpper()}.json"; + string localizationFile = $"{Path.Join(Utilities.OperatingDirectory, "Localization")}{Path.DirectorySeparatorChar}IW4MAdmin.{currentLocale}-{currentLocale.ToUpper()}.json"; Utilities.CurrentLocalization = new SharedLibraryCore.Localization.Layout(localizationDict) { diff --git a/Application/Logger.cs b/Application/Logger.cs index ab8b2c647..13ae7d3d7 100644 --- a/Application/Logger.cs +++ b/Application/Logger.cs @@ -24,7 +24,7 @@ namespace IW4MAdmin.Application public Logger(string fn) { - FileName = Path.Join("Log", $"{fn}.log"); + FileName = Path.Join(Utilities.OperatingDirectory, "Log", $"{fn}.log"); OnLogWriting = new SemaphoreSlim(1, 1); RotateLogs(); } diff --git a/Application/Main.cs b/Application/Main.cs index 316764197..a86541408 100644 --- a/Application/Main.cs +++ b/Application/Main.cs @@ -38,10 +38,11 @@ namespace IW4MAdmin.Application try { + Console.CancelKeyPress += new ConsoleCancelEventHandler(OnCancelKey); + CheckDirectories(); ServerManager = ApplicationManager.GetInstance(); - Console.CancelKeyPress += new ConsoleCancelEventHandler(OnCancelKey); Localization.Configure.Initialize(ServerManager.GetApplicationSettings().Configuration()?.CustomLocale); loc = Utilities.CurrentLocalization.LocalizationIndex; diff --git a/Application/Server.cs b/Application/Server.cs index 42419989b..cde4904a2 100644 --- a/Application/Server.cs +++ b/Application/Server.cs @@ -874,7 +874,7 @@ namespace IW4MAdmin Logger.WriteError($"{logPath} {loc["SERVER_ERROR_DNE"]}"); #if !DEBUG throw new ServerException($"{loc["SERVER_ERROR_LOG"]} {logPath}"); - //#else +#else LogEvent = new GameLogEventDetection(this, logPath, logfile.Value); #endif } diff --git a/Plugins/Stats/Helpers/StatManager.cs b/Plugins/Stats/Helpers/StatManager.cs index 285a6e985..5d8adf5f5 100644 --- a/Plugins/Stats/Helpers/StatManager.cs +++ b/Plugins/Stats/Helpers/StatManager.cs @@ -356,7 +356,8 @@ namespace IW4MAdmin.Plugins.Stats.Helpers catch (Exception ex) { - + Log.WriteWarning("Could not add client to stats"); + Log.WriteDebug(ex.GetExceptionInfo()); } finally diff --git a/SharedLibraryCore/Database/DatabaseContext.cs b/SharedLibraryCore/Database/DatabaseContext.cs index 8739bb525..010a76281 100644 --- a/SharedLibraryCore/Database/DatabaseContext.cs +++ b/SharedLibraryCore/Database/DatabaseContext.cs @@ -125,15 +125,15 @@ namespace SharedLibraryCore.Database // https://aleemkhan.wordpress.com/2013/02/28/dynamically-adding-dbset-properties-in-dbcontext-for-entity-framework-code-first/ IEnumerable directoryFiles; - string pluginDir = $@"{Environment.CurrentDirectory}{Path.DirectorySeparatorChar}bin{Path.DirectorySeparatorChar}Debug{Path.DirectorySeparatorChar}netcoreapp2.0{Path.DirectorySeparatorChar}Plugins"; + string pluginDir = $@"{Environment.CurrentDirectory}{Path.DirectorySeparatorChar}bin{Path.DirectorySeparatorChar}Debug{Path.DirectorySeparatorChar}netcoreapp2.1{Path.DirectorySeparatorChar}Plugins"; if (!Directory.Exists(pluginDir)) { - pluginDir = $@"{Environment.CurrentDirectory}{Path.DirectorySeparatorChar}Plugins"; + pluginDir = Path.Join(Environment.CurrentDirectory, "Plugins"); if (!Directory.Exists(pluginDir)) { - pluginDir = Utilities.OperatingDirectory; + pluginDir = Path.Join(Utilities.OperatingDirectory, "Plugins"); } } diff --git a/SharedLibraryCore/RCon/Connection.cs b/SharedLibraryCore/RCon/Connection.cs index 90f4f991f..ab311fa89 100644 --- a/SharedLibraryCore/RCon/Connection.cs +++ b/SharedLibraryCore/RCon/Connection.cs @@ -109,17 +109,17 @@ namespace SharedLibraryCore.RCon connectionState.ConnectionAttempts = 0; } - catch (Exception ex) + catch/* (Exception ex)*/ { if (connectionState.ConnectionAttempts < StaticHelpers.AllowedConnectionFails) { - Log.WriteWarning($"{Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_COMMUNICATION"]} [{this.Endpoint}] ({connectionState.ConnectionAttempts}/{StaticHelpers.AllowedConnectionFails})"); + // Log.WriteWarning($"{Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_COMMUNICATION"]} [{this.Endpoint}] ({connectionState.ConnectionAttempts}/{StaticHelpers.AllowedConnectionFails})"); await Task.Delay(StaticHelpers.FloodProtectionInterval); goto retrySend; } connectionState.OnComplete.Release(1); - Log.WriteDebug(ex.GetExceptionInfo()); + //Log.WriteDebug(ex.GetExceptionInfo()); throw new NetworkException($"{Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_COMMUNICATION"]} [{this.Endpoint}]"); } diff --git a/WebfrontCore/Startup.cs b/WebfrontCore/Startup.cs index ab88f0277..17b826ddd 100644 --- a/WebfrontCore/Startup.cs +++ b/WebfrontCore/Startup.cs @@ -20,7 +20,6 @@ namespace WebfrontCore public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() - // .SetBasePath(SharedLibraryCore.Utilities.OperatingDirectory) .AddEnvironmentVariables(); Configuration = builder.Build();