Compare commits

...

3 commits

Author SHA1 Message Date
Heavy Bob
281f714ec4 Added basic detection for Player and Passenger Kills
This will override the victim ship to be a Passenger or a Player. I've also moved the ship manufactures to constants because we'll need to reference them elsewhere.
2025-04-11 03:52:38 +10:00
Heavy Bob
b34e7d0165 Fixed displaying time on the kill feed. 2025-04-11 02:24:53 +10:00
Heavy Bob
a27746c45e Pass time using game.log 2025-04-11 01:17:34 +10:00
6 changed files with 131 additions and 47 deletions

View file

@ -0,0 +1,28 @@
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"
};
}

View file

@ -23,6 +23,8 @@ 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()
{
@ -45,6 +47,11 @@ 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())
{
@ -184,7 +191,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.ParseExact(actorDeathData.Timestamp, "yyyy-MM-ddTHH:mm:ss.fffZ", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal)).ToUnixTimeSeconds().ToString(),
PFP = playerData?.PFPURL ?? "https://cdn.robertsspaceindustries.com/static/images/account/avatar_default_big.jpg"
};
@ -213,6 +220,13 @@ public partial class HomePage : UserControl
_killHistoryManager.AddKill(killData);
VisorWipe();
VideoRecord();
// Update kill tally
Dispatcher.Invoke(() =>
{
KillTallyTextBox.Text = _killHistoryManager.GetKillsInCurrentMonth().Count.ToString();
AdjustFontSize(KillTallyTextBox);
});
}
}
};
@ -278,7 +292,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
@ -436,7 +460,7 @@ public partial class HomePage : UserControl
_isLogHandlerRunning = true;
}
}
public void Cleanup()
{
@ -452,4 +476,13 @@ 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
});
}
}

View file

@ -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();
}
}

View file

@ -1,4 +1,5 @@
using System.Text.RegularExpressions;
using AutoTrackR2.Constants;
namespace AutoTrackR2.LogEventHandlers;
@ -16,44 +17,71 @@ 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(@"<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>[^']+)");
_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);
}
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 = entry.Timestamp.ToString("yyyy-MM-dd HH:mm:ss")
Timestamp = match.Groups["Timestamp"].Value
};
if (cleanUpPattern.IsMatch(data.VictimShip))
// Clean up weapon name
if (_cleanUpPattern.IsMatch(data.Weapon))
{
data.VictimShip = cleanUpPattern.Match(data.VictimShip).Groups[1].Value;
data.Weapon = _cleanUpPattern.Match(data.Weapon).Groups[1].Value;
}
if (cleanUpPattern.IsMatch(data.Weapon))
// First check if this is a valid ship
if (!IsValidShip(data.VictimShip))
{
data.Weapon = cleanUpPattern.Match(data.Weapon).Groups[1].Value;
data.VictimShip = "Player";
}
else
{
// For valid ships, check for passenger flag
if (data.VictimShip == _lastKillShip)
{
data.VictimShip = "Passenger";
}
else
{
_lastKillShip = data.VictimShip;
}
}
TrackREventDispatcher.OnActorDeathEvent(data);
}
}

View file

@ -1,4 +1,5 @@
using System.Text.RegularExpressions;
using AutoTrackR2.Constants;
namespace AutoTrackR2.LogEventHandlers;
@ -18,33 +19,11 @@ 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)})");
_shipManufacturerPattern = new Regex($"^({string.Join("|", ShipManufacturers.List)})");
}
public void Handle(LogEntry entry)
@ -52,8 +31,9 @@ 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,

View file

@ -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,