mirror of
https://github.com/BubbaGumpShrump/AutoTrackR2.git
synced 2025-06-19 13:09:07 +00:00
Pass time using game.log
This commit is contained in:
parent
8e8ea81e20
commit
a27746c45e
4 changed files with 34 additions and 8 deletions
AutoTrackR2
|
@ -184,7 +184,7 @@ public partial class HomePage : UserControl
|
||||||
GameVersion = LocalPlayerData.GameVersion ?? "Unknown",
|
GameVersion = LocalPlayerData.GameVersion ?? "Unknown",
|
||||||
TrackRver = "2.10",
|
TrackRver = "2.10",
|
||||||
Enlisted = playerData?.JoinDate,
|
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"
|
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.SetResourceReference(TextElement.ForegroundProperty, "AltTextBrush");
|
||||||
titleRun.FontFamily = (FontFamily)Application.Current.Resources["Orbitron"];
|
titleRun.FontFamily = (FontFamily)Application.Current.Resources["Orbitron"];
|
||||||
killTextBlock.Inlines.Add(titleRun);
|
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
|
// Create a Border and apply the RoundedTextBlockWithBorder style
|
||||||
var killBorder = new Border
|
var killBorder = new Border
|
||||||
|
|
|
@ -93,6 +93,21 @@ public class KillHistoryManager
|
||||||
{
|
{
|
||||||
string currentMonth = DateTime.Now.ToString("MMM", CultureInfo.InvariantCulture);
|
string currentMonth = DateTime.Now.ToString("MMM", CultureInfo.InvariantCulture);
|
||||||
var kills = GetKills();
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -18,7 +18,7 @@ public class ActorDeathEvent : ILogEventHandler
|
||||||
public Regex Pattern { get; }
|
public Regex Pattern { get; }
|
||||||
public ActorDeathEvent()
|
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+$");
|
Regex cleanUpPattern = new Regex(@"^(.+?)_\d+$");
|
||||||
|
@ -29,15 +29,16 @@ public class ActorDeathEvent : ILogEventHandler
|
||||||
|
|
||||||
var match = Pattern.Match(entry.Message);
|
var match = Pattern.Match(entry.Message);
|
||||||
if (!match.Success) return;
|
if (!match.Success) return;
|
||||||
|
|
||||||
var data = new ActorDeathData {
|
var data = new ActorDeathData
|
||||||
|
{
|
||||||
VictimPilot = match.Groups["EnemyPilot"].Value,
|
VictimPilot = match.Groups["EnemyPilot"].Value,
|
||||||
VictimShip = match.Groups["EnemyShip"].Value,
|
VictimShip = match.Groups["EnemyShip"].Value,
|
||||||
Player = match.Groups["Player"].Value,
|
Player = match.Groups["Player"].Value,
|
||||||
Weapon = match.Groups["Weapon"].Value,
|
Weapon = match.Groups["Weapon"].Value,
|
||||||
Class = match.Groups["Class"].Value,
|
Class = match.Groups["Class"].Value,
|
||||||
DamageType = match.Groups["DamageType"].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))
|
if (cleanUpPattern.IsMatch(data.VictimShip))
|
||||||
|
|
|
@ -104,7 +104,7 @@ public static class WebHandler
|
||||||
|
|
||||||
public static async Task SubmitKill(KillData killData)
|
public static async Task SubmitKill(KillData killData)
|
||||||
{
|
{
|
||||||
var timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
|
var timestamp = long.Parse(killData.KillTime!);
|
||||||
var apiKillData = new APIKillData
|
var apiKillData = new APIKillData
|
||||||
{
|
{
|
||||||
victim_ship = killData.EnemyShip,
|
victim_ship = killData.EnemyShip,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue