From 044991272f8b137712c0f5b1dd81cfe581c9aef7 Mon Sep 17 00:00:00 2001 From: RaidMax Date: Tue, 5 Feb 2019 18:02:45 -0600 Subject: [PATCH] update parsers to include game name prompt to enter log path if game doesn't generate --- Application/ApplicationManager.cs | 1 + Application/DefaultSettings.json | 2 +- Application/EventParsers/BaseEventParser.cs | 3 + Application/IW4MServer.cs | 11 +++- Application/RconParsers/BaseRConParser.cs | 4 +- .../DynamicRConParserConfiguration.cs | 1 - Application/SharedGUIDKick.js | 31 ---------- Application/VPNDetection.js | 62 ------------------- Plugins/ScriptPlugins/ParserCoD4x.js | 2 + Plugins/ScriptPlugins/ParserIW4x.js | 4 +- Plugins/ScriptPlugins/ParserPT6.js | 7 ++- Plugins/ScriptPlugins/ParserTeknoMW3.js | 5 +- .../Configuration/ServerConfiguration.cs | 7 ++- SharedLibraryCore/Interfaces/IEventParser.cs | 13 +++- SharedLibraryCore/Interfaces/IRConParser.cs | 11 ++++ .../Interfaces/IRConParserConfiguration.cs | 4 -- SharedLibraryCore/Server.cs | 24 +++---- SharedLibraryCore/Utilities.cs | 9 +-- 18 files changed, 70 insertions(+), 131 deletions(-) delete mode 100644 Application/SharedGUIDKick.js delete mode 100644 Application/VPNDetection.js diff --git a/Application/ApplicationManager.cs b/Application/ApplicationManager.cs index 0430c2def..b8dcbe301 100644 --- a/Application/ApplicationManager.cs +++ b/Application/ApplicationManager.cs @@ -299,6 +299,7 @@ namespace IW4MAdmin.Application } serverConfig.ModifyParsers(); + await ConfigHandler.Save(); } } } diff --git a/Application/DefaultSettings.json b/Application/DefaultSettings.json index 121fde6ff..90599fbdf 100644 --- a/Application/DefaultSettings.json +++ b/Application/DefaultSettings.json @@ -247,7 +247,7 @@ ] }, { - "Game": "T6M", + "Game": "T6", "Maps": [ { "Alias": "Aftermath", diff --git a/Application/EventParsers/BaseEventParser.cs b/Application/EventParsers/BaseEventParser.cs index a41faa640..642018210 100644 --- a/Application/EventParsers/BaseEventParser.cs +++ b/Application/EventParsers/BaseEventParser.cs @@ -4,6 +4,7 @@ using SharedLibraryCore.Interfaces; using System; using System.Linq; using System.Text.RegularExpressions; +using static SharedLibraryCore.Server; namespace IW4MAdmin.Application.EventParsers { @@ -70,6 +71,8 @@ namespace IW4MAdmin.Application.EventParsers public string Version { get; set; } = "CoD"; + public Game GameName { get; set; } = Game.COD; + public virtual GameEvent GetEvent(Server server, string logLine) { logLine = Regex.Replace(logLine, @"([0-9]+:[0-9]+ |^[0-9]+ )", "").Trim(); diff --git a/Application/IW4MServer.cs b/Application/IW4MServer.cs index 363c27467..405abeb56 100644 --- a/Application/IW4MServer.cs +++ b/Application/IW4MServer.cs @@ -679,7 +679,12 @@ namespace IW4MAdmin var version = await this.GetDvarAsync("version"); Version = version.Value; - GameName = Utilities.GetGame(version?.Value); + GameName = Utilities.GetGame(version?.Value ?? RconParser.Version); + + if (GameName == Game.UKN) + { + GameName = RconParser.GameName; + } if (version?.Value?.Length != 0) { @@ -733,12 +738,12 @@ namespace IW4MAdmin this.Gametype = gametype; this.IP = ip.Value == "localhost" ? ServerConfig.IPAddress : ip.Value ?? ServerConfig.IPAddress; - if (logsync.Value == 0 || logfile.Value == string.Empty) + if ((logsync.Value == 0 || logfile.Value == string.Empty) && RconParser.CanGenerateLogPath) { // this DVAR isn't set until the a map is loaded await this.SetDvarAsync("logfile", 2); await this.SetDvarAsync("g_logsync", 2); // set to 2 for continous in other games, clamps to 1 for IW4 - await this.SetDvarAsync("g_log", "games_mp.log"); + //await this.SetDvarAsync("g_log", "games_mp.log"); Logger.WriteWarning("Game log file not properly initialized, restarting map..."); await this.ExecuteCommandAsync("map_restart"); logfile = await this.GetDvarAsync("g_log"); diff --git a/Application/RconParsers/BaseRConParser.cs b/Application/RconParsers/BaseRConParser.cs index 71e96cf7e..a9644bb01 100644 --- a/Application/RconParsers/BaseRConParser.cs +++ b/Application/RconParsers/BaseRConParser.cs @@ -8,6 +8,7 @@ using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; +using static SharedLibraryCore.Server; namespace IW4MAdmin.Application.RconParsers { @@ -31,7 +32,6 @@ namespace IW4MAdmin.Application.RconParsers RConGetInfo = "ÿÿÿÿgetinfo", RConResponse = "ÿÿÿÿprint", }, - GameName = Server.Game.IW4 }; Configuration.Status.Pattern = @"^ *([0-9]+) +-?([0-9]+) +((?:[A-Z]+|[0-9]+)) +((?:[a-z]|[0-9]){16}|(?:[a-z]|[0-9]){32}|bot[0-9]+|(?:[0-9]+)) *(.{0,32}) +([0-9]+) +(\d+\.\d+\.\d+.\d+\:-*\d{1,5}|0+.0+:-*\d{1,5}|loopback) +(-*[0-9]+) +([0-9]+) *$"; @@ -53,6 +53,8 @@ namespace IW4MAdmin.Application.RconParsers public IRConParserConfiguration Configuration { get; set; } public string Version { get; set; } = "CoD"; + public Game GameName { get; set; } = Game.COD; + public bool CanGenerateLogPath { get; set; } = true; public async Task ExecuteCommandAsync(Connection connection, string command) { diff --git a/Application/RconParsers/DynamicRConParserConfiguration.cs b/Application/RconParsers/DynamicRConParserConfiguration.cs index 8641aca75..447b4ded7 100644 --- a/Application/RconParsers/DynamicRConParserConfiguration.cs +++ b/Application/RconParsers/DynamicRConParserConfiguration.cs @@ -11,7 +11,6 @@ namespace IW4MAdmin.Application.RconParsers sealed internal class DynamicRConParserConfiguration : IRConParserConfiguration { public CommandPrefix CommandPrefixes { get; set; } - public Server.Game GameName { get; set; } public ParserRegex Status { get; set; } = new ParserRegex(); public ParserRegex Dvar { get; set; } = new ParserRegex(); public bool WaitForResponse { get; set; } = true; diff --git a/Application/SharedGUIDKick.js b/Application/SharedGUIDKick.js deleted file mode 100644 index 8de2311d9..000000000 --- a/Application/SharedGUIDKick.js +++ /dev/null @@ -1,31 +0,0 @@ -var plugin = { - author: 'RaidMax', - version: 1.1, - name: 'Shared GUID Kicker Plugin', - - onEventAsync: function (gameEvent, server) { - // make sure we only check for IW4(x) - if (server.GameName !== 2) { - return false; - - - } - - // connect or join event - if (gameEvent.Type === 3) { - // this GUID seems to have been packed in a IW4 torrent and results in an unreasonable amount of people using the same GUID - if (gameEvent.Origin.NetworkId === -805366929435212061) { - gameEvent.Origin.Kick('Your GUID is generic. Delete players/guids.dat and rejoin', _IW4MAdminClient); - } - } - }, - - onLoadAsync: function (manager) { - }, - - onUnloadAsync: function () { - }, - - onTickAsync: function (server) { - } -}; \ No newline at end of file diff --git a/Application/VPNDetection.js b/Application/VPNDetection.js deleted file mode 100644 index 32dc4e6c8..000000000 --- a/Application/VPNDetection.js +++ /dev/null @@ -1,62 +0,0 @@ -var plugin = { - author: 'RaidMax', - version: 1.0, - name: 'VPN Detection Plugin', - - manager: null, - logger: null, - vpnExceptionIds: [], - - checkForVpn: function (origin) { - var exempt = false; - // prevent players that are exempt from being kicked - this.vpnExceptionIds.forEach(function (id) { - if (id === origin.ClientId) { - exempt = true; - return false; - } - }); - - if (exempt) { - return; - } - - var usingVPN = false; - - try { - var cl = new System.Net.Http.HttpClient(); - var re = cl.GetAsync('https://api.xdefcon.com/proxy/check/?ip=' + origin.IPAddressString).Result; - var co = re.Content; - var parsedJSON = JSON.parse(co.ReadAsStringAsync().Result); - co.Dispose(); - re.Dispose(); - cl.Dispose(); - usingVPN = parsedJSON.success && parsedJSON.proxy; - } catch (e) { - this.logger.WriteError(e.message); - } - - if (usingVPN) { - this.logger.WriteInfo(origin + ' is using a VPN (' + origin.IPAddressString + ')'); - origin.Kick(_localization.LocalizationIndex["SERVER_KICK_VPNS_NOTALLOWED"], _IW4MAdminClient); - } - }, - - onEventAsync: function (gameEvent, server) { - // connect event - if (gameEvent.Type === 3) { - this.checkForVpn(gameEvent.Origin); - } - }, - - onLoadAsync: function (manager) { - this.manager = manager; - this.logger = manager.GetLogger(0); - }, - - onUnloadAsync: function () { - }, - - onTickAsync: function (server) { - } -}; \ No newline at end of file diff --git a/Plugins/ScriptPlugins/ParserCoD4x.js b/Plugins/ScriptPlugins/ParserCoD4x.js index 5e29675be..b1c83ca53 100644 --- a/Plugins/ScriptPlugins/ParserCoD4x.js +++ b/Plugins/ScriptPlugins/ParserCoD4x.js @@ -17,9 +17,11 @@ var plugin = { rconParser.Configuration.Dvar.Pattern = '^"(.+)" is: "(.+)?" default: "(.+)?" info: "(.+)?"$'; rconParser.Configuration.Dvar.AddMapping(110, 4); rconParser.Version = 'CoD4 X 1.8 win_mingw-x86 build 2055 May 2 2017'; + rconParser.GameName = 1; // IW3 eventParser.Configuration.GameDirectory = 'main'; eventParser.Version = 'CoD4 X 1.8 win_mingw-x86 build 2055 May 2 2017'; + eventParser.GameName = 1; // IW3 }, onUnloadAsync: function () { diff --git a/Plugins/ScriptPlugins/ParserIW4x.js b/Plugins/ScriptPlugins/ParserIW4x.js index 5fd8af502..e6275fd7a 100644 --- a/Plugins/ScriptPlugins/ParserIW4x.js +++ b/Plugins/ScriptPlugins/ParserIW4x.js @@ -3,7 +3,7 @@ var eventParser; var plugin = { author: 'RaidMax', - version: 0.1, + version: 0.2, name: 'IW3 Parser', isParser: true, @@ -22,7 +22,9 @@ var plugin = { eventParser.Configuration.GameDirectory = 'userraw'; rconParser.Version = 'IW4x (v0.6.0)'; + rconParser.GameName = 2; // IW4x eventParser.Version = 'IW4x (v0.6.0)'; + eventParser.GameName = 2; // IW4x }, onUnloadAsync: function () { diff --git a/Plugins/ScriptPlugins/ParserPT6.js b/Plugins/ScriptPlugins/ParserPT6.js index 1476bea41..d4fdad62a 100644 --- a/Plugins/ScriptPlugins/ParserPT6.js +++ b/Plugins/ScriptPlugins/ParserPT6.js @@ -3,7 +3,7 @@ var eventParser; var plugin = { author: 'RaidMax', - version: 0.1, + version: 0.2, name: 'Plutoniun T6 Parser', isParser: true, @@ -34,11 +34,12 @@ var plugin = { rconParser.Configuration.Status.AddMapping(104, 6); rconParser.Configuration.Status.AddMapping(105, 8); - - eventParser.Configuration.GameDirectory = 't6r\\\\data'; + eventParser.Configuration.GameDirectory = 't6r\\data'; rconParser.Version = 'Call of Duty Multiplayer - Ship COD_T6_S MP build 1.0.44 CL(1759941) CODPCAB2 CEG Fri May 9 19:19:19 2014 win-x86 813e66d5'; + rconParser.GameName = 7; // T6 eventParser.Version = 'Call of Duty Multiplayer - Ship COD_T6_S MP build 1.0.44 CL(1759941) CODPCAB2 CEG Fri May 9 19:19:19 2014 win-x86 813e66d5'; + eventParser.GameName = 7; // T6 }, onUnloadAsync: function () { diff --git a/Plugins/ScriptPlugins/ParserTeknoMW3.js b/Plugins/ScriptPlugins/ParserTeknoMW3.js index db74bba28..f78e97f54 100644 --- a/Plugins/ScriptPlugins/ParserTeknoMW3.js +++ b/Plugins/ScriptPlugins/ParserTeknoMW3.js @@ -3,7 +3,7 @@ var eventParser; var plugin = { author: 'RaidMax', - version: 0.1, + version: 0.2, name: 'Tekno MW3 Parser', isParser: true, @@ -27,9 +27,12 @@ var plugin = { rconParser.Configuration.Dvar.AddMapping(107, 1); // RCon DvarValue rconParser.Configuration.Dvar.Pattern = '^(.*)$'; rconParser.Version = 'IW5 MP 1.4 build 382 latest Thu Jan 19 2012 11:09:49AM win-x86'; + rconParser.GameName = 3; // IW5 + rconParser.CanGenerateLogPath = false; eventParser.Configuration.GameDirectory = 'scripts'; eventParser.Version = 'IW5 MP 1.4 build 382 latest Thu Jan 19 2012 11:09:49AM win-x86'; + eventParser.GameName = 3; // IW5 }, onUnloadAsync: function () { diff --git a/SharedLibraryCore/Configuration/ServerConfiguration.cs b/SharedLibraryCore/Configuration/ServerConfiguration.cs index 8e98b9ef0..c91fa5f26 100644 --- a/SharedLibraryCore/Configuration/ServerConfiguration.cs +++ b/SharedLibraryCore/Configuration/ServerConfiguration.cs @@ -38,10 +38,15 @@ namespace SharedLibraryCore.Configuration if (selection.Item1 > 0) { RConParserVersion = selection.Item2; + + if (!rconParsers[selection.Item1 - 1].CanGenerateLogPath) + { + Console.WriteLine(loc["SETUP_SERVER_NO_LOG"]); + ManualLogPath = Utilities.PromptString(loc["SETUP_SERVER_LOG_PATH"]); + } } parserVersions = eventParsers.Select(_parser => _parser.Version).ToArray(); - Console.WriteLine($"{IPAddress}:{Port}"); selection = Utilities.PromptSelection($"{loc["SETUP_SERVER_EVENT_PARSER_VERSION"]} ({IPAddress}:{Port})", $"{loc["SETUP_PROMPT_DEFAULT"]} (Call of Duty)", null, parserVersions); if (selection.Item1 > 0) diff --git a/SharedLibraryCore/Interfaces/IEventParser.cs b/SharedLibraryCore/Interfaces/IEventParser.cs index d21a489d6..6b097e8d1 100644 --- a/SharedLibraryCore/Interfaces/IEventParser.cs +++ b/SharedLibraryCore/Interfaces/IEventParser.cs @@ -1,4 +1,6 @@ -namespace SharedLibraryCore.Interfaces +using static SharedLibraryCore.Server; + +namespace SharedLibraryCore.Interfaces { public interface IEventParser { @@ -15,6 +17,15 @@ /// /// Game directory prefix IEventParserConfiguration Configuration { get; set; } + + /// + /// stores the game/client specific version (usually the value of the "version" DVAR) + /// string Version { get; set; } + + /// + /// specifies the game name (usually the internal studio iteration ie: IW4, T5 etc...) + /// + Game GameName { get; set; } } } diff --git a/SharedLibraryCore/Interfaces/IRConParser.cs b/SharedLibraryCore/Interfaces/IRConParser.cs index 4a982cc86..dcaed8e9f 100644 --- a/SharedLibraryCore/Interfaces/IRConParser.cs +++ b/SharedLibraryCore/Interfaces/IRConParser.cs @@ -51,5 +51,16 @@ namespace SharedLibraryCore.Interfaces /// stores the game/client specific version (usually the value of the "version" DVAR) /// string Version { get; set; } + + /// + /// specifies the game name (usually the internal studio iteration ie: IW4, T5 etc...) + /// + Game GameName { get; set; } + + /// + /// indicates if the game supports generating a log path from DVAR retrieval + /// of fs_game, fs_basepath, g_log + /// + bool CanGenerateLogPath { get; set; } } } diff --git a/SharedLibraryCore/Interfaces/IRConParserConfiguration.cs b/SharedLibraryCore/Interfaces/IRConParserConfiguration.cs index 5e8f85379..774afea40 100644 --- a/SharedLibraryCore/Interfaces/IRConParserConfiguration.cs +++ b/SharedLibraryCore/Interfaces/IRConParserConfiguration.cs @@ -9,10 +9,6 @@ namespace SharedLibraryCore.Interfaces /// CommandPrefix CommandPrefixes { get; set; } /// - /// optionally stores the game name type - /// - Server.Game GameName { get; set; } - /// /// stores the regex info for parsing get status response /// ParserRegex Status { get; set; } diff --git a/SharedLibraryCore/Server.cs b/SharedLibraryCore/Server.cs index 27bb7530b..18f80281d 100644 --- a/SharedLibraryCore/Server.cs +++ b/SharedLibraryCore/Server.cs @@ -17,14 +17,16 @@ namespace SharedLibraryCore { public enum Game { - UKN, - IW3, - IW4, - IW5, - T4, - T5, - T5M, - T6M, + COD = -1, + UKN = 0, + IW3 = 1, + IW4 = 2, + IW5 = 3, + IW6 = 4, + T4 = 5, + T5 = 6, + T6 = 7, + T7 = 8 } public Server(IManager mgr, ServerConfiguration config) @@ -51,12 +53,6 @@ namespace SharedLibraryCore public long EndPoint => Convert.ToInt64($"{IP.Replace(".", "")}{Port}"); - //Returns current server IP set by `net_ip` -- *STRING* - public String GetIP() - { - return IP; - } - //Returns current server port set by `net_port` -- *INT* public int GetPort() { diff --git a/SharedLibraryCore/Utilities.cs b/SharedLibraryCore/Utilities.cs index 08cb7052a..9de8dadc5 100644 --- a/SharedLibraryCore/Utilities.cs +++ b/SharedLibraryCore/Utilities.cs @@ -367,16 +367,11 @@ namespace SharedLibraryCore return Game.T4; } - if (gameName.Contains("COD_T5_S")) + if (gameName.Contains("T5")) { return Game.T5; } - if (gameName.Contains("T5M")) - { - return Game.T5M; - } - if (gameName.Contains("IW5")) { return Game.IW5; @@ -384,7 +379,7 @@ namespace SharedLibraryCore if (gameName.Contains("COD_T6_S")) { - return Game.T6M; + return Game.T6; } return Game.UKN;