diff --git a/AutoTrackR2/HomePage.xaml.cs b/AutoTrackR2/HomePage.xaml.cs index f727a62..bf6681b 100644 --- a/AutoTrackR2/HomePage.xaml.cs +++ b/AutoTrackR2/HomePage.xaml.cs @@ -184,7 +184,7 @@ public partial class HomePage : UserControl GameVersion = LocalPlayerData.GameVersion ?? "Unknown", TrackRver = "2.10", Enlisted = playerData?.JoinDate, - KillTime = DateTime.UtcNow.ToString("dd MMM yyyy HH:mm"), + KillTime = ((DateTimeOffset)DateTime.Parse(actorDeathData.Timestamp)).ToUnixTimeSeconds().ToString(), PFP = playerData?.PFPURL ?? "https://cdn.robertsspaceindustries.com/static/images/account/avatar_default_big.jpg" }; @@ -278,7 +278,17 @@ public partial class HomePage : UserControl titleRun.SetResourceReference(TextElement.ForegroundProperty, "AltTextBrush"); titleRun.FontFamily = (FontFamily)Application.Current.Resources["Orbitron"]; killTextBlock.Inlines.Add(titleRun); - killTextBlock.Inlines.Add(new Run($"{killData.KillTime}")); + + string displayTime; + if (long.TryParse(killData.KillTime, out long unixTime)) + { + displayTime = DateTimeOffset.FromUnixTimeSeconds(unixTime).ToString("dd MMM yyyy HH:mm"); + } + else + { + displayTime = killData.KillTime ?? "Unknown"; + } + killTextBlock.Inlines.Add(new Run(displayTime)); // Create a Border and apply the RoundedTextBlockWithBorder style var killBorder = new Border diff --git a/AutoTrackR2/KillHistoryManager.cs b/AutoTrackR2/KillHistoryManager.cs index 5c87a17..98cb0fd 100644 --- a/AutoTrackR2/KillHistoryManager.cs +++ b/AutoTrackR2/KillHistoryManager.cs @@ -93,6 +93,21 @@ public class KillHistoryManager { string currentMonth = DateTime.Now.ToString("MMM", CultureInfo.InvariantCulture); var kills = GetKills(); - return kills.Where(kill => kill.KillTime?.Contains(currentMonth) == true).ToList(); + + // Because we are not using UTCNOW anymore and users already have kills saved, we need to make sure both formats are compatable. Otherwise people gonna delete their csv. + return kills.Where(kill => + { + if (string.IsNullOrEmpty(kill.KillTime)) return false; + + // Try to parse as Unix timestamp first + if (long.TryParse(kill.KillTime, out long unixTime)) + { + var date = DateTimeOffset.FromUnixTimeSeconds(unixTime); + return date.ToString("MMM", CultureInfo.InvariantCulture) == currentMonth; + } + + // Fall back to checking if it contains the month name (old format) + return kill.KillTime.Contains(currentMonth); + }).ToList(); } } \ No newline at end of file diff --git a/AutoTrackR2/LogEventHandlers/ActorDeathEvent.cs b/AutoTrackR2/LogEventHandlers/ActorDeathEvent.cs index 5dee7f3..7160648 100644 --- a/AutoTrackR2/LogEventHandlers/ActorDeathEvent.cs +++ b/AutoTrackR2/LogEventHandlers/ActorDeathEvent.cs @@ -18,7 +18,7 @@ public class ActorDeathEvent : ILogEventHandler public Regex Pattern { get; } public ActorDeathEvent() { - Pattern = new Regex(@"<Actor Death> CActor::Kill: '(?<EnemyPilot>[^']+)' \[\d+\] in zone '(?<EnemyShip>[^']+)' killed by '(?<Player>[^']+)' \[[^']+\] using '(?<Weapon>[^']+)' \[Class (?<Class>[^\]]+)\] with damage type '(?<DamageType>[^']+)"); + Pattern = new Regex(@"<(?<Timestamp>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z)> \[Notice\] <Actor Death> CActor::Kill: '(?<EnemyPilot>[^']+)' \[\d+\] in zone '(?<EnemyShip>[^']+)' killed by '(?<Player>[^']+)' \[[^']+\] using '(?<Weapon>[^']+)' \[Class (?<Class>[^\]]+)\] with damage type '(?<DamageType>[^']+)"); } Regex cleanUpPattern = new Regex(@"^(.+?)_\d+$"); @@ -29,15 +29,16 @@ public class ActorDeathEvent : ILogEventHandler var match = Pattern.Match(entry.Message); if (!match.Success) return; - - var data = new ActorDeathData { + + var data = new ActorDeathData + { VictimPilot = match.Groups["EnemyPilot"].Value, VictimShip = match.Groups["EnemyShip"].Value, Player = match.Groups["Player"].Value, Weapon = match.Groups["Weapon"].Value, Class = match.Groups["Class"].Value, DamageType = match.Groups["DamageType"].Value, - Timestamp = entry.Timestamp.ToString("yyyy-MM-dd HH:mm:ss") + Timestamp = match.Groups["Timestamp"].Value }; if (cleanUpPattern.IsMatch(data.VictimShip)) diff --git a/AutoTrackR2/WebHandler.cs b/AutoTrackR2/WebHandler.cs index 7015282..0d93b48 100644 --- a/AutoTrackR2/WebHandler.cs +++ b/AutoTrackR2/WebHandler.cs @@ -104,7 +104,7 @@ public static class WebHandler public static async Task SubmitKill(KillData killData) { - var timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); + var timestamp = long.Parse(killData.KillTime!); var apiKillData = new APIKillData { victim_ship = killData.EnemyShip,