From c8366a22e59a96a96ab2b7ea2a24cff0dcc36f96 Mon Sep 17 00:00:00 2001 From: RaidMax Date: Sat, 6 Oct 2018 15:31:05 -0500 Subject: [PATCH] fixed the vpn detection plugin method signature call added some fixes for stats/ac --- Application/Application.csproj | 5 +++-- Application/BuildScripts/PostPublish.bat | 5 ++++- Application/Manager.cs | 5 ++--- Plugins/ScriptPlugins/VPNDetection.js | 3 ++- Plugins/Stats/Cheat/Detection.cs | 10 +++++----- Plugins/Stats/Helpers/StatManager.cs | 14 +++++++++++--- SharedLibraryCore/Commands/NativeCommands.cs | 6 +++--- .../Helpers/BaseConfigurationHandler.cs | 2 +- SharedLibraryCore/RCon/StaticHelpers.cs | 2 +- WebfrontCore/Program.cs | 2 +- WebfrontCore/Startup.cs | 6 +++--- 11 files changed, 36 insertions(+), 24 deletions(-) diff --git a/Application/Application.csproj b/Application/Application.csproj index 8ef18759a..1ea5f9cf7 100644 --- a/Application/Application.csproj +++ b/Application/Application.csproj @@ -5,7 +5,7 @@ netcoreapp2.1 false RaidMax.IW4MAdmin.Application - 2.1.9.2 + 2.1.9.4 RaidMax Forever None IW4MAdmin @@ -30,7 +30,8 @@ true true - 2.1.9.3 + 2.1.9.4 + 2.1.9.4 diff --git a/Application/BuildScripts/PostPublish.bat b/Application/BuildScripts/PostPublish.bat index 807ee448c..49d175a58 100644 --- a/Application/BuildScripts/PostPublish.bat +++ b/Application/BuildScripts/PostPublish.bat @@ -82,10 +82,13 @@ if "%CurrentConfiguration" == "Release" ( echo PR-RT move "%SolutionDir%Publish\WindowsPrerelease\runtimes" "%SolutionDir%Publish\WindowsPrerelease\Lib\runtimes" +if exist "%SolutionDir%Publish\WindowsPrerelease\refs" move "%SolutionDir%Publish\WindowsPrerelease\refs" "%SolutionDir%Publish\WindowsPrerelease\Lib\refs" + if "%CurrentConfiguration" == "Release" ( echo R-RT - rem move "%SolutionDir%Publish\Windows\runtimes" "%SolutionDir%Publish\Windows\Lib\runtimes" + move "%SolutionDir%Publish\Windows\runtimes" "%SolutionDir%Publish\Windows\Lib\runtimes" + if exist "%SolutionDir%Publish\Windows\refs" move "%SolutionDir%Publish\Windows\refs" "%SolutionDir%Publish\Windows\Lib\refs" ) echo making start scripts diff --git a/Application/Manager.cs b/Application/Manager.cs index 453ec4c3b..b34241aa5 100644 --- a/Application/Manager.cs +++ b/Application/Manager.cs @@ -383,11 +383,10 @@ namespace IW4MAdmin.Application await Plugin.OnLoadAsync(this); } - catch (Exception e) + catch (Exception ex) { Logger.WriteError($"{Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_PLUGIN"]} {Plugin.Name}"); - Logger.WriteDebug($"Exception: {e.Message}"); - Logger.WriteDebug($"Stack Trace: {e.StackTrace}"); + Logger.WriteDebug(ex.GetExceptionInfo()); } } #endregion diff --git a/Plugins/ScriptPlugins/VPNDetection.js b/Plugins/ScriptPlugins/VPNDetection.js index c55798b0c..ac2911284 100644 --- a/Plugins/ScriptPlugins/VPNDetection.js +++ b/Plugins/ScriptPlugins/VPNDetection.js @@ -42,6 +42,7 @@ var plugin = { var library = importNamespace('SharedLibraryCore'); var kickOrigin = new library.Objects.Player(); kickOrigin.ClientId = 1; + kickOrigin.CurrentServer = origin.CurrentServer; origin.Kick(_localization.LocalizationIndex["SERVER_KICK_VPNS_NOTALLOWED"], kickOrigin); } }, @@ -55,7 +56,7 @@ var plugin = { onLoadAsync: function (manager) { this.manager = manager; - this.logger = manager.GetLogger(); + this.logger = manager.GetLogger(0); }, onUnloadAsync: function () { diff --git a/Plugins/Stats/Cheat/Detection.cs b/Plugins/Stats/Cheat/Detection.cs index e51d75055..892e15c16 100644 --- a/Plugins/Stats/Cheat/Detection.cs +++ b/Plugins/Stats/Cheat/Detection.cs @@ -26,8 +26,8 @@ namespace IW4MAdmin.Plugins.Stats.Cheat Dictionary HitLocationCount; double AngleDifferenceAverage; EFClientStatistics ClientStats; - DateTime LastHit; long LastOffset; + IW4Info.WeaponName LastWeapon; ILogger Log; Strain Strain; readonly DateTime ConnectionTime = DateTime.UtcNow; @@ -53,16 +53,16 @@ namespace IW4MAdmin.Plugins.Stats.Cheat if ((kill.DeathType != IW4Info.MeansOfDeath.MOD_PISTOL_BULLET && kill.DeathType != IW4Info.MeansOfDeath.MOD_RIFLE_BULLET && kill.DeathType != IW4Info.MeansOfDeath.MOD_HEAD_SHOT) || - kill.HitLoc == IW4Info.HitLocation.none || kill.TimeOffset - LastOffset < 0) + kill.HitLoc == IW4Info.HitLocation.none || kill.TimeOffset - LastOffset < 0 || + // hack: prevents false positives + (LastWeapon != kill.Weapon && (kill.TimeOffset - LastOffset) == 50)) return new DetectionPenaltyResult() { ClientPenalty = Penalty.PenaltyType.Any, }; DetectionPenaltyResult result = null; - - if (LastHit == DateTime.MinValue) - LastHit = DateTime.UtcNow; + LastWeapon = kill.Weapon; HitLocationCount[kill.HitLoc]++; if (!isDamage) diff --git a/Plugins/Stats/Helpers/StatManager.cs b/Plugins/Stats/Helpers/StatManager.cs index fa12ca833..db276eba7 100644 --- a/Plugins/Stats/Helpers/StatManager.cs +++ b/Plugins/Stats/Helpers/StatManager.cs @@ -147,7 +147,7 @@ namespace IW4MAdmin.Plugins.Stats.Helpers }); #if DEBUG == true - var statsInfoSql = iqStatsInfo.ToSql(); + var statsInfoSql = iqStatsInfo.ToSql(); #endif var topPlayers = await iqStatsInfo.ToListAsync(); @@ -406,6 +406,14 @@ namespace IW4MAdmin.Plugins.Stats.Helpers string fraction, string visibilityPercentage, string snapAngles) { var statsSvc = ContextThreads[serverId]; + + // incase the add palyer event get delayed + if (!Servers[serverId].PlayerStats.ContainsKey(attacker.ClientId)) + { + await AddPlayer(attacker); + } + + Vector3 vDeathOrigin = null; Vector3 vKillOrigin = null; Vector3 vViewAngles = null; @@ -675,7 +683,7 @@ namespace IW4MAdmin.Plugins.Stats.Helpers } #if DEBUG - Log.WriteDebug("Calculating standard kill"); + Log.WriteDebug("Calculating standard kill"); #endif // update the total stats @@ -727,7 +735,7 @@ namespace IW4MAdmin.Plugins.Stats.Helpers #if !DEBUG if ((DateTime.UtcNow - attackerStats.LastStatHistoryUpdate).TotalMinutes >= 2.5) #else - if ((DateTime.UtcNow - attackerStats.LastStatHistoryUpdate).TotalMinutes >= 0.1) + if ((DateTime.UtcNow - attackerStats.LastStatHistoryUpdate).TotalMinutes >= 0.1) #endif { attackerStats.LastStatHistoryUpdate = DateTime.UtcNow; diff --git a/SharedLibraryCore/Commands/NativeCommands.cs b/SharedLibraryCore/Commands/NativeCommands.cs index 889e669ce..b3b81ff0a 100644 --- a/SharedLibraryCore/Commands/NativeCommands.cs +++ b/SharedLibraryCore/Commands/NativeCommands.cs @@ -1126,7 +1126,7 @@ namespace SharedLibraryCore.Commands { } - public override Task ExecuteAsync(GameEvent E) + public override async Task ExecuteAsync(GameEvent E) { var gameserverProcesses = System.Diagnostics.Process.GetProcessesByName("iw4x"); @@ -1180,12 +1180,12 @@ namespace SharedLibraryCore.Commands E.Origin.Tell("Could not kill server process"); E.Owner.Logger.WriteDebug("Unable to kill process"); E.Owner.Logger.WriteDebug($"Exception: {e.Message}"); - return Task.CompletedTask; + return; } } } - return Task.CompletedTask; + return; } } diff --git a/SharedLibraryCore/Helpers/BaseConfigurationHandler.cs b/SharedLibraryCore/Helpers/BaseConfigurationHandler.cs index 3780f1572..ac6289ae5 100644 --- a/SharedLibraryCore/Helpers/BaseConfigurationHandler.cs +++ b/SharedLibraryCore/Helpers/BaseConfigurationHandler.cs @@ -37,7 +37,7 @@ namespace SharedLibraryCore.Configuration public Task Save() { var appConfigJSON = JsonConvert.SerializeObject(_configuration, Formatting.Indented); - return File.WriteAllTextAsync(Path.Join(AppDomain.CurrentDomain.BaseDirectory, "Configuration", $"{Filename}.json"), appConfigJSON); + return File.WriteAllTextAsync(Path.Join(Utilities.OperatingDirectory, "Configuration", $"{Filename}.json"), appConfigJSON); } public T Configuration() => _configuration; diff --git a/SharedLibraryCore/RCon/StaticHelpers.cs b/SharedLibraryCore/RCon/StaticHelpers.cs index 2ac9cebd2..d09c62436 100644 --- a/SharedLibraryCore/RCon/StaticHelpers.cs +++ b/SharedLibraryCore/RCon/StaticHelpers.cs @@ -39,7 +39,7 @@ namespace SharedLibraryCore.RCon /// /// timeout in seconds to wait for a socket send or receive before giving up /// - public static readonly int SocketTimeout = 1000; + public static readonly int SocketTimeout = 7500; /// /// interval in milliseconds to wait before sending the next RCon request /// diff --git a/WebfrontCore/Program.cs b/WebfrontCore/Program.cs index 661538ba6..cb093725c 100644 --- a/WebfrontCore/Program.cs +++ b/WebfrontCore/Program.cs @@ -30,7 +30,7 @@ namespace WebfrontCore #if DEBUG .UseContentRoot(Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\..\..\", "WebfrontCore"))) #else - .UseContentRoot(Path.Join(Directory.GetCurrentDirectory(), "..\\")) + .UseContentRoot(SharedLibraryCore.Utilities.OperatingDirectory) #endif .UseUrls(Manager.GetApplicationSettings().Configuration().WebfrontBindUrl) .UseKestrel() diff --git a/WebfrontCore/Startup.cs b/WebfrontCore/Startup.cs index d18609147..ab88f0277 100644 --- a/WebfrontCore/Startup.cs +++ b/WebfrontCore/Startup.cs @@ -20,7 +20,7 @@ namespace WebfrontCore public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() - .SetBasePath(env.ContentRootPath) + // .SetBasePath(SharedLibraryCore.Utilities.OperatingDirectory) .AddEnvironmentVariables(); Configuration = builder.Build(); @@ -32,10 +32,10 @@ namespace WebfrontCore public void ConfigureServices(IServiceCollection services) { // Add framework services. - var mvcBulder = services.AddMvc(); + var mvcBuilder = services.AddMvc(); foreach (var asm in Program.Manager.GetPluginAssemblies()) - mvcBulder.AddApplicationPart(asm); + mvcBuilder.AddApplicationPart(asm); services.Configure(o => {