diff --git a/AutoTrackR2/HomePage.xaml.cs b/AutoTrackR2/HomePage.xaml.cs index 66baa77..359b02d 100644 --- a/AutoTrackR2/HomePage.xaml.cs +++ b/AutoTrackR2/HomePage.xaml.cs @@ -131,13 +131,15 @@ public partial class HomePage : UserControl }; // Ship - TrackREventDispatcher.JumpDriveStateChangedEvent += (shipName) => + TrackREventDispatcher.JumpDriveStateChangedEvent += (data) => { Dispatcher.Invoke(() => { - PlayerShipTextBox.Text = LocalPlayerData.CurrentGameMode == GameMode.PersistentUniverse ? shipName : "Unknown"; + PlayerShipTextBox.Text = data.ShipName; + Console.WriteLine(data.ShipName); AdjustFontSize(PlayerShipTextBox); - LocalPlayerData.PlayerShip = shipName; + LocalPlayerData.PlayerShip = data.ShipName; + LocalPlayerData.LastSeenVehicleLocation = data.Location; }); }; @@ -170,6 +172,7 @@ public partial class HomePage : UserControl { EnemyPilot = actorDeathData.VictimPilot, EnemyShip = actorDeathData.VictimShip, + Location = LocalPlayerData.LastSeenVehicleLocation, OrgAffiliation = playerData?.OrgName, Weapon = actorDeathData.Weapon, Ship = LocalPlayerData.PlayerShip ?? "Unknown", diff --git a/AutoTrackR2/LocalPlayerData.cs b/AutoTrackR2/LocalPlayerData.cs index 87d8911..5412de3 100644 --- a/AutoTrackR2/LocalPlayerData.cs +++ b/AutoTrackR2/LocalPlayerData.cs @@ -14,5 +14,5 @@ public static class LocalPlayerData public static string? PlayerShip; public static string? GameVersion; public static GameMode CurrentGameMode; - public static string? LastSeenVehicleLocation; + public static string? LastSeenVehicleLocation = "Unknown"; } \ No newline at end of file diff --git a/AutoTrackR2/LogEventHandlers/JumpDriveStateChangedEvent.cs b/AutoTrackR2/LogEventHandlers/JumpDriveStateChangedEvent.cs index 9955f7f..2adf26f 100644 --- a/AutoTrackR2/LogEventHandlers/JumpDriveStateChangedEvent.cs +++ b/AutoTrackR2/LogEventHandlers/JumpDriveStateChangedEvent.cs @@ -2,6 +2,12 @@ namespace AutoTrackR2.LogEventHandlers; +public struct JumpDriveStateChangedData +{ + public string ShipName { get; set; } + public string Location { get; set; } +} + public class JumpDriveStateChangedEvent : ILogEventHandler { public Regex Pattern { get; } @@ -9,7 +15,7 @@ public class JumpDriveStateChangedEvent : ILogEventHandler public JumpDriveStateChangedEvent() { - Pattern = new Regex(@"<Jump Drive State Changed>.*.adam: (?<ShipName>.*.) in"); + Pattern = new Regex(@"<Jump Drive State Changed>.*.adam: (?<ShipName>.*.) in zone (?<Location>.*.)\)"); } public void Handle(LogEntry entry) @@ -17,11 +23,20 @@ public class JumpDriveStateChangedEvent : ILogEventHandler if (entry.Message is null) return; var match = Pattern.Match(entry.Message); if (!match.Success) return; - + + var data = new JumpDriveStateChangedData + { + Location = match.Groups["Location"].Value + }; + match = _cleanUpPattern.Match(match.Groups["ShipName"].Value); if (match.Success) { - TrackREventDispatcher.OnJumpDriveStateChangedEvent(match.Groups[1].Value);; + data.ShipName = match.Groups[1].Value; + } + if (!string.IsNullOrEmpty(data.ShipName) && !string.IsNullOrEmpty(data.Location)) + { + TrackREventDispatcher.OnJumpDriveStateChangedEvent(data); } } } \ No newline at end of file diff --git a/AutoTrackR2/LogEventHandlers/RequestJumpFailedEvent.cs b/AutoTrackR2/LogEventHandlers/RequestJumpFailedEvent.cs index c998685..aaef3e3 100644 --- a/AutoTrackR2/LogEventHandlers/RequestJumpFailedEvent.cs +++ b/AutoTrackR2/LogEventHandlers/RequestJumpFailedEvent.cs @@ -9,7 +9,7 @@ public class RequestJumpFailedEvent : ILogEventHandler public RequestJumpFailedEvent() { - Pattern = new Regex(@"<Request Jump Failed>.*.adam: (?<ShipName>.*.) in"); + Pattern = new Regex(@"<Request Jump Failed>.*.adam: (?<ShipName>.*.) in zone (?<Location>.*.)\)"); } public void Handle(LogEntry entry) @@ -18,10 +18,20 @@ public class RequestJumpFailedEvent : ILogEventHandler var match = Pattern.Match(entry.Message); if (!match.Success) return; + var data = new JumpDriveStateChangedData + { + Location = match.Groups["Location"].Value + }; + match = _cleanUpPattern.Match(match.Groups["ShipName"].Value); if (match.Success) { - TrackREventDispatcher.OnJumpDriveStateChangedEvent(match.Groups[1].Value);; + data.ShipName = match.Groups[1].Value; + } + + if (!string.IsNullOrEmpty(data.ShipName) && !string.IsNullOrEmpty(data.Location)) + { + TrackREventDispatcher.OnJumpDriveStateChangedEvent(data); } } } \ No newline at end of file diff --git a/AutoTrackR2/LogEventHandlers/VehicleDestructionEvent.cs b/AutoTrackR2/LogEventHandlers/VehicleDestructionEvent.cs index 5f2a20b..47b808a 100644 --- a/AutoTrackR2/LogEventHandlers/VehicleDestructionEvent.cs +++ b/AutoTrackR2/LogEventHandlers/VehicleDestructionEvent.cs @@ -21,14 +21,16 @@ public class VehicleDestructionEvent : ILogEventHandler public Regex Pattern { get; } public VehicleDestructionEvent() { - Pattern = new Regex(""" - "<(?<timestamp>[^>]+)> \[Notice\] <Vehicle Destruction> CVehicle::OnAdvanceDestroyLevel: " + - "Vehicle '(?<vehicle>[^']+)' \[\d+\] in zone '(?<vehicle_zone>[^']+)' " + - "\[pos x: (?<pos_x>[-\d\.]+), y: (?<pos_y>[-\d\.]+), z: (?<pos_z>[-\d\.]+) " + - "vel x: [^,]+, y: [^,]+, z: [^\]]+\] driven by '(?<driver>[^']+)' \[\d+\] " + - "advanced from destroy level (?<destroy_level_from>\d+) to (?<destroy_level_to>\d+) " + - "caused by '(?<caused_by>[^']+)' \[\d+\] with '(?<damage_type>[^']+)'" - """); + const string patternStr = """ + <(?<timestamp>[^>]+)> \[Notice\] <Vehicle Destruction> CVehicle::OnAdvanceDestroyLevel: + Vehicle '(?<vehicle>[^']+)' \[\d+\] in zone '(?<vehicle_zone>[^']+)' + \[pos x: (?<pos_x>[-\d\.]+), y: (?<pos_y>[-\d\.]+), z: (?<pos_z>[-\d\.]+) + vel x: [^,]+, y: [^,]+, z: [^\]]+\] driven by '(?<driver>[^']+)' \[\d+\] + advanced from destroy level (?<destroy_level_from>\d+) to (?<destroy_level_to>\d+) + caused by '(?<caused_by>[^']+)' \[\d+\] with '(?<damage_type>[^']+)' + """; + + Pattern = new Regex(Regex.Replace(patternStr, @"\t|\n|\r", "")); } public void Handle(LogEntry entry) diff --git a/AutoTrackR2/LogHandler.cs b/AutoTrackR2/LogHandler.cs index 9941419..2e2ab91 100644 --- a/AutoTrackR2/LogHandler.cs +++ b/AutoTrackR2/LogHandler.cs @@ -42,7 +42,8 @@ public class LogHandler new InPersistentUniverseEvent(), new GameVersionEvent(), new JumpDriveStateChangedEvent(), - new RequestJumpFailedEvent() + new RequestJumpFailedEvent(), + new VehicleDestructionEvent() ]; public LogHandler(string? logPath) diff --git a/AutoTrackR2/TrackREventDispatcher.cs b/AutoTrackR2/TrackREventDispatcher.cs index 9aaab03..d5dc3ae 100644 --- a/AutoTrackR2/TrackREventDispatcher.cs +++ b/AutoTrackR2/TrackREventDispatcher.cs @@ -49,9 +49,9 @@ public static class TrackREventDispatcher // Jump Drive state has changed // Todo: Add proper data for this event. Right now only ship name is used. - public static event Action<string>? JumpDriveStateChangedEvent; - public static void OnJumpDriveStateChangedEvent(string shipName) + public static event Action<JumpDriveStateChangedData>? JumpDriveStateChangedEvent; + public static void OnJumpDriveStateChangedEvent(JumpDriveStateChangedData data) { - JumpDriveStateChangedEvent?.Invoke(shipName); + JumpDriveStateChangedEvent?.Invoke(data); } } \ No newline at end of file diff --git a/AutoTrackR2/Util.cs b/AutoTrackR2/Util.cs index b5931de..f783330 100644 --- a/AutoTrackR2/Util.cs +++ b/AutoTrackR2/Util.cs @@ -19,6 +19,7 @@ public struct KillData public string? Enlisted; public string? RecordNumber; public string? OrgAffiliation; + public string? Location; public string? Player; public string? Weapon; public string? Ship; diff --git a/AutoTrackR2/WebHandler.cs b/AutoTrackR2/WebHandler.cs index d199ccd..1532255 100644 --- a/AutoTrackR2/WebHandler.cs +++ b/AutoTrackR2/WebHandler.cs @@ -94,7 +94,7 @@ public static class WebHandler loadout_ship = killData.Ship, game_version = killData.GameVersion, trackr_version = killData.TrackRver, - location = "Unknown", + location = killData.Location, time = DateTimeOffset.UtcNow.ToUnixTimeSeconds() }; @@ -123,6 +123,7 @@ public static class WebHandler Console.WriteLine($"API URL: {ConfigManager.ApiUrl}register-kill"); Console.WriteLine($"Victim: {apiKillData.victim}"); Console.WriteLine($"Victim Ship: {apiKillData.victim_ship}"); + Console.WriteLine($"Location: {apiKillData.location}"); Console.WriteLine($"Weapon: {apiKillData.weapon}"); Console.WriteLine($"Method: {apiKillData.method}"); Console.WriteLine($"Game Mode: {apiKillData.gamemode}");