diff --git a/AutoTrackR2/Constants/ShipManufacturers.cs b/AutoTrackR2/Constants/ShipManufacturers.cs deleted file mode 100644 index 0e3cac9..0000000 --- a/AutoTrackR2/Constants/ShipManufacturers.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System.Collections.Generic; - -namespace AutoTrackR2.Constants; - -public static class ShipManufacturers -{ - public static readonly List<string> List = new List<string> - { - "ORIG", - "CRUS", - "RSI", - "AEGS", - "VNCL", - "DRAK", - "ANVL", - "BANU", - "MISC", - "CNOU", - "XIAN", - "GAMA", - "TMBL", - "ESPR", - "KRIG", - "GRIN", - "XNAA", - "MRAI" - }; -} \ No newline at end of file diff --git a/AutoTrackR2/HomePage.xaml.cs b/AutoTrackR2/HomePage.xaml.cs index 84ee0f7..f727a62 100644 --- a/AutoTrackR2/HomePage.xaml.cs +++ b/AutoTrackR2/HomePage.xaml.cs @@ -23,8 +23,6 @@ public partial class HomePage : UserControl private bool _UIEventsRegistered = false; private System.Timers.Timer _statusCheckTimer; private bool _isLogHandlerRunning = false; - private int _counter = 1; - private System.Timers.Timer _counterTimer; public HomePage() { @@ -47,11 +45,6 @@ public partial class HomePage : UserControl _statusCheckTimer.Elapsed += CheckStarCitizenStatus; _statusCheckTimer.Start(); - // Initialize and start the counter timer - _counterTimer = new System.Timers.Timer(1000); // Update every second - _counterTimer.Elapsed += UpdateCounter; - _counterTimer.Start(); - // Check if Star Citizen is already running and initialize accordingly if (IsStarCitizenRunning()) { @@ -191,7 +184,7 @@ public partial class HomePage : UserControl GameVersion = LocalPlayerData.GameVersion ?? "Unknown", TrackRver = "2.10", Enlisted = playerData?.JoinDate, - KillTime = ((DateTimeOffset)DateTime.ParseExact(actorDeathData.Timestamp, "yyyy-MM-ddTHH:mm:ss.fffZ", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal)).ToUnixTimeSeconds().ToString(), + KillTime = DateTime.UtcNow.ToString("dd MMM yyyy HH:mm"), PFP = playerData?.PFPURL ?? "https://cdn.robertsspaceindustries.com/static/images/account/avatar_default_big.jpg" }; @@ -220,13 +213,6 @@ public partial class HomePage : UserControl _killHistoryManager.AddKill(killData); VisorWipe(); VideoRecord(); - - // Update kill tally - Dispatcher.Invoke(() => - { - KillTallyTextBox.Text = _killHistoryManager.GetKillsInCurrentMonth().Count.ToString(); - AdjustFontSize(KillTallyTextBox); - }); } } }; @@ -292,17 +278,7 @@ public partial class HomePage : UserControl titleRun.SetResourceReference(TextElement.ForegroundProperty, "AltTextBrush"); titleRun.FontFamily = (FontFamily)Application.Current.Resources["Orbitron"]; killTextBlock.Inlines.Add(titleRun); - - 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)); + killTextBlock.Inlines.Add(new Run($"{killData.KillTime}")); // Create a Border and apply the RoundedTextBlockWithBorder style var killBorder = new Border @@ -460,7 +436,7 @@ public partial class HomePage : UserControl _isLogHandlerRunning = true; } } - + public void Cleanup() { @@ -476,13 +452,4 @@ public partial class HomePage : UserControl { return Process.GetProcessesByName("StarCitizen").Length > 0; } - - private void UpdateCounter(object? sender, ElapsedEventArgs e) - { - Dispatcher.Invoke(() => - { - DebugPanel.Text = _counter.ToString(); - _counter = (_counter % 10) + 1; // Count from 1 to 10 and loop - }); - } } diff --git a/AutoTrackR2/KillHistoryManager.cs b/AutoTrackR2/KillHistoryManager.cs index 98cb0fd..5c87a17 100644 --- a/AutoTrackR2/KillHistoryManager.cs +++ b/AutoTrackR2/KillHistoryManager.cs @@ -93,21 +93,6 @@ public class KillHistoryManager { string currentMonth = DateTime.Now.ToString("MMM", CultureInfo.InvariantCulture); var kills = GetKills(); - - // 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(); + return kills.Where(kill => kill.KillTime?.Contains(currentMonth) == true).ToList(); } } \ No newline at end of file diff --git a/AutoTrackR2/LogEventHandlers/ActorDeathEvent.cs b/AutoTrackR2/LogEventHandlers/ActorDeathEvent.cs index 56741f5..5dee7f3 100644 --- a/AutoTrackR2/LogEventHandlers/ActorDeathEvent.cs +++ b/AutoTrackR2/LogEventHandlers/ActorDeathEvent.cs @@ -1,5 +1,4 @@ using System.Text.RegularExpressions; -using AutoTrackR2.Constants; namespace AutoTrackR2.LogEventHandlers; @@ -17,71 +16,44 @@ public struct ActorDeathData public class ActorDeathEvent : ILogEventHandler { public Regex Pattern { get; } - private Regex _cleanUpPattern = new Regex(@"^(.+?)_\d+$"); - private Regex _shipManufacturerPattern; - private string _lastKillShip = string.Empty; - public ActorDeathEvent() { - 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>[^']+)"); - _shipManufacturerPattern = new Regex($"^({string.Join("|", ShipManufacturers.List)})"); - } - - private bool IsValidShip(string shipName) - { - // Clean up the ship name first - if (_cleanUpPattern.IsMatch(shipName)) - { - shipName = _cleanUpPattern.Match(shipName).Groups[1].Value; - } - - // A valid ship must start with a known manufacturer - return _shipManufacturerPattern.IsMatch(shipName); + Pattern = new Regex(@"<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+$"); public void Handle(LogEntry entry) { if (entry.Message is null) return; - + 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 = match.Groups["Timestamp"].Value + Timestamp = entry.Timestamp.ToString("yyyy-MM-dd HH:mm:ss") }; - - // Clean up weapon name - if (_cleanUpPattern.IsMatch(data.Weapon)) + + if (cleanUpPattern.IsMatch(data.VictimShip)) { - data.Weapon = _cleanUpPattern.Match(data.Weapon).Groups[1].Value; + data.VictimShip = cleanUpPattern.Match(data.VictimShip).Groups[1].Value; } - - // First check if this is a valid ship - if (!IsValidShip(data.VictimShip)) + + if (cleanUpPattern.IsMatch(data.Weapon)) { - data.VictimShip = "Player"; - } - else - { - // For valid ships, check for passenger flag - if (data.VictimShip == _lastKillShip) - { - data.VictimShip = "Passenger"; - } - else - { - _lastKillShip = data.VictimShip; - } + data.Weapon = cleanUpPattern.Match(data.Weapon).Groups[1].Value; } TrackREventDispatcher.OnActorDeathEvent(data); + } + + } \ No newline at end of file diff --git a/AutoTrackR2/LogEventHandlers/InstancedInteriorEvent.cs b/AutoTrackR2/LogEventHandlers/InstancedInteriorEvent.cs index a6759eb..62ab732 100644 --- a/AutoTrackR2/LogEventHandlers/InstancedInteriorEvent.cs +++ b/AutoTrackR2/LogEventHandlers/InstancedInteriorEvent.cs @@ -1,5 +1,4 @@ using System.Text.RegularExpressions; -using AutoTrackR2.Constants; namespace AutoTrackR2.LogEventHandlers; @@ -19,11 +18,33 @@ public class InstancedInteriorEvent : ILogEventHandler private Regex _shipManufacturerPattern; private Regex _cleanUpPattern = new Regex(@"(.+?)_\d+$"); - + + private List<string> _shipManufacturers = new List<string> + { + "ORIG", + "CRUS", + "RSI", + "AEGS", + "VNCL", + "DRAK", + "ANVL", + "BANU", + "MISC", + "CNOU", + "XIAN", + "GAMA", + "TMBL", + "ESPR", + "KRIG", + "GRIN", + "XNAA", + "MRAI" + }; + public InstancedInteriorEvent() { Pattern = new Regex(@"\[InstancedInterior\] OnEntityLeaveZone - InstancedInterior \[(?<InstancedInterior>[^\]]+)\] \[\d+\] -> Entity \[(?<Entity>[^\]]+)\] \[\d+\] -- m_openDoors\[\d+\], m_managerGEID\[(?<ManagerGEID>\d+)\], m_ownerGEID\[(?<OwnerGEID>[^\[]+)\]"); - _shipManufacturerPattern = new Regex($"^({string.Join("|", ShipManufacturers.List)})"); + _shipManufacturerPattern = new Regex($"^({string.Join("|", _shipManufacturers)})"); } public void Handle(LogEntry entry) @@ -31,9 +52,8 @@ public class InstancedInteriorEvent : ILogEventHandler if (entry.Message is null) return; var match = Pattern.Match(entry.Message); if (!match.Success) return; - - var data = new InstancedInteriorData - { + + var data = new InstancedInteriorData { Entity = match.Groups["Entity"].Value, OwnerGEID = match.Groups["OwnerGEID"].Value, ManagerGEID = match.Groups["ManagerGEID"].Value, diff --git a/AutoTrackR2/WebHandler.cs b/AutoTrackR2/WebHandler.cs index 0d93b48..7015282 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 = long.Parse(killData.KillTime!); + var timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); var apiKillData = new APIKillData { victim_ship = killData.EnemyShip,