From 3f892c6a3749b0d3d843ea8b580294e32da5e13c Mon Sep 17 00:00:00 2001 From: Dork Normalize <nope> Date: Sun, 30 Mar 2025 19:01:50 -0700 Subject: [PATCH] Fix CSV parsing dates with commas. Fix UEE record scraping --- AutoTrackR2/HomePage.xaml.cs | 27 ++++++++++++++++++++-- AutoTrackR2/KillHistoryManager.cs | 3 +++ AutoTrackR2/WebHandler.cs | 38 ++++++++++++------------------- 3 files changed, 42 insertions(+), 26 deletions(-) diff --git a/AutoTrackR2/HomePage.xaml.cs b/AutoTrackR2/HomePage.xaml.cs index 318a63d..2227fd0 100644 --- a/AutoTrackR2/HomePage.xaml.cs +++ b/AutoTrackR2/HomePage.xaml.cs @@ -146,11 +146,27 @@ public partial class HomePage : UserControl EnemyPilot = actorDeathData.VictimPilot, EnemyShip = actorDeathData.VictimShip, OrgAffiliation = playerData?.OrgName, + Weapon = actorDeathData.Weapon, + Ship = LocalPlayerData.PlayerShip ?? "Unknown", + Method = actorDeathData.DamageType, + RecordNumber = playerData?.UEERecord, + GameVersion = LocalPlayerData.GameVersion ?? "Unknown", + TrackRver = UpdatePage.currentVersion.Replace("v", "") ?? "Unknown", Enlisted = playerData?.JoinDate, KillTime = DateTime.UtcNow.ToString("dd MMM yyyy HH:mm"), - PFP = playerData?.PFPURL + PFP = playerData?.PFPURL ?? "https://cdn.robertsspaceindustries.com/static/images/account/avatar_default_big.jpg" }; + switch (LocalPlayerData.CurrentGameMode) + { + case GameMode.PersistentUniverse: + killData.Mode = "pu"; + break; + case GameMode.ArenaCommander: + killData.Mode = "ac"; + break; + } + // Add kill to UI Dispatcher.Invoke(() => { @@ -160,7 +176,7 @@ public partial class HomePage : UserControl // Only submit kill data if not in offline mode if (ConfigManager.OfflineMode == 0) { - await WebHandler.SubmitKill(actorDeathData, playerData); + await WebHandler.SubmitKill(killData); } _killHistoryManager.AddKill(killData); @@ -234,6 +250,8 @@ public partial class HomePage : UserControl FontFamily = orbitronFontFamily, }); + killTextBlock.Inlines.Add(new Run($"{killData.RecordNumber}\n")); + killTextBlock.Inlines.Add(new Run("Kill Time: ") { Foreground = altTextColorBrush, @@ -261,6 +279,11 @@ public partial class HomePage : UserControl // Add the TextBlock to the first column of the Grid Grid.SetColumn(killTextBlock, 0); killGrid.Children.Add(killTextBlock); + + if (killData.PFP == "") + { + killData.PFP = "https://cdn.robertsspaceindustries.com/static/images/account/avatar_default_big.jpg"; + } // Create the Image for the profile var profileImage = new Image diff --git a/AutoTrackR2/KillHistoryManager.cs b/AutoTrackR2/KillHistoryManager.cs index fd07f2e..831a6ae 100644 --- a/AutoTrackR2/KillHistoryManager.cs +++ b/AutoTrackR2/KillHistoryManager.cs @@ -28,6 +28,9 @@ public class KillHistoryManager File.WriteAllText(_killHistoryPath, _headers); } + // Remove comma from Enlisted + killData.Enlisted = killData.Enlisted?.Replace(",", string.Empty); + // Append the new kill data to the CSV file var csv = new StringBuilder(); csv.AppendLine($"\"{killData.KillTime}\",\"{killData.EnemyPilot}\",\"{killData.EnemyShip}\",\"{killData.Enlisted}\",\"{killData.RecordNumber}\",\"{killData.OrgAffiliation}\",\"{killData.Player}\",\"{killData.Weapon}\",\"{killData.Ship}\",\"{killData.Method}\",\"{killData.Mode}\",\"{killData.GameVersion}\",\"{killData.TrackRver}\",\"{killData.Logged}\",\"{killData.PFP}\""); diff --git a/AutoTrackR2/WebHandler.cs b/AutoTrackR2/WebHandler.cs index c46d192..af2ebc7 100644 --- a/AutoTrackR2/WebHandler.cs +++ b/AutoTrackR2/WebHandler.cs @@ -27,7 +27,7 @@ public static class WebHandler public static async Task<PlayerData?> GetPlayerData(string enemyPilot) { var joinDataPattern = new Regex("<span class=\"label\">Enlisted</span>\\s*<strong class=\"value\">([^<]+)</strong>"); - var ueePattern = new Regex("<p class=\"entry citizen-record\">\\s*<span class=\"label\">UEE Citizen Record<\\/span>\\s*<strong class=\"value\">#?(n\\/a|\\d+)<\\/strong>\\s*<\\/p>"); + var ueePattern = new Regex("<p class=\"entry citizen-record\">\\n.*.<span class=\"label\">UEE Citizen Record<\\/span>\\n.*.<strong class=\"value\">#(?<UEERecord>\\d+)<\\/strong>"); var orgPattern = new Regex("\\/orgs\\/(?<OrgURL>[A-z0-9]+)\" .*\\>(?<OrgName>.*)<"); var pfpPattern = new Regex("/media/(.*)\""); @@ -51,7 +51,7 @@ public static class WebHandler var ueeMatch = ueePattern.Match(content); if (ueeMatch.Success) { - playerData.UEERecord = ueeMatch.Groups[1].Value == "n/a" ? "-1" : ueeMatch.Groups[1].Value; + playerData.UEERecord = ueeMatch.Groups["UEERecord"].Value == "n/a" ? "-1" : ueeMatch.Groups[1].Value; } var orgMatch = orgPattern.Match(content); @@ -78,33 +78,23 @@ public static class WebHandler return playerData; } - public static async Task SubmitKill(ActorDeathData deathData, PlayerData? enemyPlayerData) + public static async Task SubmitKill(KillData killData) { - var killData = new APIKillData + var apiKillData = new APIKillData { - victim_ship = deathData.VictimShip, - victim = deathData.VictimPilot, - enlisted = enemyPlayerData?.JoinDate, - rsi = enemyPlayerData?.UEERecord, - weapon = deathData.Weapon, - method = deathData.DamageType, + victim_ship = killData.EnemyShip, + victim = killData.EnemyPilot, + enlisted = killData.Enlisted, + rsi = killData.RecordNumber, + weapon = killData.Weapon, + method = killData.Method, // loadout_ship = LocalPlayerData.PlayerShip ?? "Unknown", - loadout_ship = LocalPlayerData.PlayerShip ?? "Unknown", - game_version = LocalPlayerData.GameVersion ?? "Unknown", - trackr_version = UpdatePage.currentVersion.Replace("v", "") ?? "Unknown", - location = LocalPlayerData.LastSeenVehicleLocation ?? "Unknown" + loadout_ship = killData.Ship, + game_version = killData.GameVersion, + trackr_version = killData.TrackRver, + location = "Unknown" }; - switch (LocalPlayerData.CurrentGameMode) - { - case GameMode.PersistentUniverse: - killData.gamemode = "pu"; - break; - case GameMode.ArenaCommander: - killData.gamemode = "ac"; - break; - } - var httpClient = new HttpClient(); string jsonData = JsonSerializer.Serialize(killData); httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + ConfigManager.ApiKey);