Pass time using game.log

This commit is contained in:
Heavy Bob 2025-04-11 01:17:34 +10:00
parent 8e8ea81e20
commit a27746c45e
4 changed files with 34 additions and 8 deletions

View file

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

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

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

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,