From 2964fd71b2db82d723b3bd3902a076179eeb1e42 Mon Sep 17 00:00:00 2001 From: RaidMax Date: Sat, 14 Apr 2018 23:26:27 -0500 Subject: [PATCH] fixed ping bug showing origin ping instead of target event parser has GetGameDir made parsers choosen more dynamically profile shows online/offline status of client --- Application/EventParsers/IW4EventParser.cs | 3 ++ Application/EventParsers/IW5EventParser.cs | 12 ++++++++ Application/EventParsers/T6MEventParser.cs | 3 ++ Application/RconParsers/IW4RConParser.cs | 3 -- Application/Server.cs | 30 ++++++++++++------- SharedLibraryCore/Commands/NativeCommands.cs | 4 +-- SharedLibraryCore/Dtos/PlayerInfo.cs | 2 ++ SharedLibraryCore/Interfaces/IEventParser.cs | 11 +++++++ WebfrontCore/Controllers/ClientController.cs | 2 ++ .../Views/Client/Profile/Index.cshtml | 13 ++++++-- 10 files changed, 66 insertions(+), 17 deletions(-) create mode 100644 Application/EventParsers/IW5EventParser.cs diff --git a/Application/EventParsers/IW4EventParser.cs b/Application/EventParsers/IW4EventParser.cs index 347b7cc78..f5dfafd8b 100644 --- a/Application/EventParsers/IW4EventParser.cs +++ b/Application/EventParsers/IW4EventParser.cs @@ -104,5 +104,8 @@ namespace Application.EventParsers Owner = server }; } + + // other parsers can derive from this parser so we make it virtual + public virtual string GetGameDir() => "userraw"; } } diff --git a/Application/EventParsers/IW5EventParser.cs b/Application/EventParsers/IW5EventParser.cs new file mode 100644 index 000000000..da25779ba --- /dev/null +++ b/Application/EventParsers/IW5EventParser.cs @@ -0,0 +1,12 @@ +using SharedLibraryCore.Interfaces; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Application.EventParsers +{ + class IW5EventParser : IW4EventParser + { + public override string GetGameDir() => "rzodemo"; + } +} diff --git a/Application/EventParsers/T6MEventParser.cs b/Application/EventParsers/T6MEventParser.cs index 7267c687b..98e1ad544 100644 --- a/Application/EventParsers/T6MEventParser.cs +++ b/Application/EventParsers/T6MEventParser.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Linq; using System.Text.RegularExpressions; using SharedLibraryCore; @@ -88,5 +89,7 @@ namespace Application.EventParsers Owner = server }; } + + public string GetGameDir() => $"t6r{Path.DirectorySeparatorChar}data"; } } diff --git a/Application/RconParsers/IW4RConParser.cs b/Application/RconParsers/IW4RConParser.cs index 31d5947f6..0184f4aad 100644 --- a/Application/RconParsers/IW4RConParser.cs +++ b/Application/RconParsers/IW4RConParser.cs @@ -89,9 +89,6 @@ namespace Application.RconParsers long npID = Regex.Match(responseLine, @"([a-z]|[0-9]){16}", RegexOptions.IgnoreCase).Value.ConvertLong(); int.TryParse(playerInfo[0], out cID); var regex = Regex.Match(responseLine, @"\d+\.\d+\.\d+.\d+\:\d{1,5}"); -#if DEBUG - Ping = 1; -#endif int cIP = regex.Value.Split(':')[0].ConvertToIP(); regex = Regex.Match(responseLine, @"[0-9]{1,2}\s+[0-9]+\s+"); int score = Int32.Parse(regex.Value.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[1]); diff --git a/Application/Server.cs b/Application/Server.cs index da4a006c4..687b78149 100644 --- a/Application/Server.cs +++ b/Application/Server.cs @@ -17,6 +17,7 @@ using IW4MAdmin.Application.Misc; using Application.RconParsers; using Application.EventParsers; using SharedLibraryCore.Exceptions; +using System.Runtime.InteropServices; namespace IW4MAdmin { @@ -573,13 +574,20 @@ namespace IW4MAdmin public async Task Initialize() { RconParser = ServerConfig.UseT6MParser ? (IRConParser)new T6MRConParser() : new IW4RConParser(); - EventParser = ServerConfig.UseT6MParser ? (IEventParser)new T6MEventParser() : new IW4EventParser(); var version = await this.GetDvarAsync("version"); GameName = Utilities.GetGame(version.Value); - if (GameName == Game.UKN) + if (GameName == Game.IW4) + EventParser = new IW4EventParser(); + else if (GameName == Game.IW5) + EventParser = new IW5EventParser(); + else if (GameName == Game.T6M) + EventParser = new T6MEventParser(); + else if (GameName == Game.UKN) Logger.WriteWarning($"Game name not recognized: {version}"); + else + EventParser = new IW4EventParser(); var shortversion = await this.GetDvarAsync("shortversion"); var hostname = await this.GetDvarAsync("sv_hostname"); @@ -617,7 +625,7 @@ namespace IW4MAdmin Website = website.Value; } - catch (SharedLibraryCore.Exceptions.DvarException) + catch (DvarException) { Website = "this server's website"; } @@ -643,19 +651,21 @@ namespace IW4MAdmin } CustomCallback = await ScriptLoaded(); - - string mainPath = (GameName == Game.IW4 && onelog.Value >= 0) ? "userraw" : "main"; - // patch for T5M:V2 log path - mainPath = (GameName == Game.T5M) ? "rzodemo" : mainPath; - // patch for T6M:PLUTONIUM - mainPath = (GameName == Game.T6M) ? $"t6r{Path.DirectorySeparatorChar}data" : mainPath; + string mainPath = EventParser.GetGameDir(); + mainPath = (GameName == Game.IW4 && onelog.Value > 0) ? "main" : mainPath; #if DEBUG // basepath.Value = @"\\192.168.88.253\Call of Duty Black Ops II"; #endif - string logPath = (game.Value == "" || onelog?.Value == 1) ? + string logPath = game.Value == string.Empty ? $"{basepath.Value.Replace('\\', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{mainPath}{Path.DirectorySeparatorChar}{logfile.Value}" : $"{basepath.Value.Replace('\\', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{game.Value.Replace('/', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{logfile.Value}"; + // hopefully fix wine drive name mangling + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + logPath = Regex.Replace(logPath, @"[A-Z]:", ""); + } + if (!File.Exists(logPath)) { Logger.WriteError($"Gamelog {logPath} does not exist!"); diff --git a/SharedLibraryCore/Commands/NativeCommands.cs b/SharedLibraryCore/Commands/NativeCommands.cs index 093a9a493..9f611f6ea 100644 --- a/SharedLibraryCore/Commands/NativeCommands.cs +++ b/SharedLibraryCore/Commands/NativeCommands.cs @@ -1090,14 +1090,14 @@ namespace SharedLibraryCore.Commands if (E.Target == null) await E.Owner.Broadcast($"{E.Origin.Name}'s ping is ^5{E.Origin.Ping}^7ms"); else - await E.Owner.Broadcast($"{E.Target.Name}'s ping is ^5{E.Origin.Ping}^7ms"); + await E.Owner.Broadcast($"{E.Target.Name}'s ping is ^5{E.Target.Ping}^7ms"); } else { if (E.Target == null) await E.Origin.Tell($"Your ping is ^5{E.Origin.Ping}^7ms"); else - await E.Origin.Tell($"{E.Target.Name}'s ping is ^5{E.Origin.Ping}^7ms"); + await E.Origin.Tell($"{E.Target.Name}'s ping is ^5{E.Target.Ping}^7ms"); } } } diff --git a/SharedLibraryCore/Dtos/PlayerInfo.cs b/SharedLibraryCore/Dtos/PlayerInfo.cs index 095bf9e80..2eb37d61c 100644 --- a/SharedLibraryCore/Dtos/PlayerInfo.cs +++ b/SharedLibraryCore/Dtos/PlayerInfo.cs @@ -22,5 +22,7 @@ namespace SharedLibraryCore.Dtos public string TimePlayed { get; set; } public bool Authenticated { get; set; } public List Meta { get; set; } + public bool Online { get; set; } + public string TimeOnline { get; set; } } } diff --git a/SharedLibraryCore/Interfaces/IEventParser.cs b/SharedLibraryCore/Interfaces/IEventParser.cs index 369f08990..968ad44a8 100644 --- a/SharedLibraryCore/Interfaces/IEventParser.cs +++ b/SharedLibraryCore/Interfaces/IEventParser.cs @@ -6,6 +6,17 @@ namespace SharedLibraryCore.Interfaces { public interface IEventParser { + /// + /// Generates a game event based on log line input + /// + /// server the event occurred on + /// single log line string + /// GameEvent GetEvent(Server server, string logLine); + /// + /// Get game specific folder prefix for log files + /// + /// Game directory prefix + string GetGameDir(); } } diff --git a/WebfrontCore/Controllers/ClientController.cs b/WebfrontCore/Controllers/ClientController.cs index 0168ed2c3..4528448b3 100644 --- a/WebfrontCore/Controllers/ClientController.cs +++ b/WebfrontCore/Controllers/ClientController.cs @@ -40,6 +40,8 @@ namespace WebfrontCore.Controllers .Distinct() .OrderBy(i => i) .ToList(), + Online = Manager.GetActiveClients().FirstOrDefault(c => c.ClientId == client.ClientId) != null, + TimeOnline = (DateTime.UtcNow - client.LastConnection).TimeSpanText() }; var meta = await MetaService.GetMeta(client.ClientId); diff --git a/WebfrontCore/Views/Client/Profile/Index.cshtml b/WebfrontCore/Views/Client/Profile/Index.cshtml index 956c7ada2..37d64a173 100644 --- a/WebfrontCore/Views/Client/Profile/Index.cshtml +++ b/WebfrontCore/Views/Client/Profile/Index.cshtml @@ -11,6 +11,15 @@
+ @if (Model.Online) + { + + } + + else + { + + }
@Model.Name
@@ -21,13 +30,13 @@
@if (Model.LevelInt < (int)ViewBag.User.Level && - (SharedLibraryCore.Objects.Player.Permission)Model.LevelInt != SharedLibraryCore.Objects.Player.Permission.Banned) + (SharedLibraryCore.Objects.Player.Permission)Model.LevelInt != SharedLibraryCore.Objects.Player.Permission.Banned) { } @if (Model.LevelInt < (int)ViewBag.User.Level && - (SharedLibraryCore.Objects.Player.Permission)Model.LevelInt == SharedLibraryCore.Objects.Player.Permission.Banned) + (SharedLibraryCore.Objects.Player.Permission)Model.LevelInt == SharedLibraryCore.Objects.Player.Permission.Banned) { }