Fix locations

This commit is contained in:
Dork Normalize 2025-04-06 20:46:25 -07:00
parent 90d24b4d9b
commit 39409d4ea3
9 changed files with 55 additions and 22 deletions

View file

@ -131,13 +131,15 @@ public partial class HomePage : UserControl
};
// Ship
TrackREventDispatcher.JumpDriveStateChangedEvent += (shipName) =>
TrackREventDispatcher.JumpDriveStateChangedEvent += (data) =>
{
Dispatcher.Invoke(() =>
{
PlayerShipTextBox.Text = LocalPlayerData.CurrentGameMode == GameMode.PersistentUniverse ? shipName : "Unknown";
PlayerShipTextBox.Text = data.ShipName;
Console.WriteLine(data.ShipName);
AdjustFontSize(PlayerShipTextBox);
LocalPlayerData.PlayerShip = shipName;
LocalPlayerData.PlayerShip = data.ShipName;
LocalPlayerData.LastSeenVehicleLocation = data.Location;
});
};
@ -170,6 +172,7 @@ public partial class HomePage : UserControl
{
EnemyPilot = actorDeathData.VictimPilot,
EnemyShip = actorDeathData.VictimShip,
Location = LocalPlayerData.LastSeenVehicleLocation,
OrgAffiliation = playerData?.OrgName,
Weapon = actorDeathData.Weapon,
Ship = LocalPlayerData.PlayerShip ?? "Unknown",

View file

@ -14,5 +14,5 @@ public static class LocalPlayerData
public static string? PlayerShip;
public static string? GameVersion;
public static GameMode CurrentGameMode;
public static string? LastSeenVehicleLocation;
public static string? LastSeenVehicleLocation = "Unknown";
}

View file

@ -2,6 +2,12 @@
namespace AutoTrackR2.LogEventHandlers;
public struct JumpDriveStateChangedData
{
public string ShipName { get; set; }
public string Location { get; set; }
}
public class JumpDriveStateChangedEvent : ILogEventHandler
{
public Regex Pattern { get; }
@ -9,7 +15,7 @@ public class JumpDriveStateChangedEvent : ILogEventHandler
public JumpDriveStateChangedEvent()
{
Pattern = new Regex(@"<Jump Drive State Changed>.*.adam: (?<ShipName>.*.) in");
Pattern = new Regex(@"<Jump Drive State Changed>.*.adam: (?<ShipName>.*.) in zone (?<Location>.*.)\)");
}
public void Handle(LogEntry entry)
@ -17,11 +23,20 @@ public class JumpDriveStateChangedEvent : ILogEventHandler
if (entry.Message is null) return;
var match = Pattern.Match(entry.Message);
if (!match.Success) return;
var data = new JumpDriveStateChangedData
{
Location = match.Groups["Location"].Value
};
match = _cleanUpPattern.Match(match.Groups["ShipName"].Value);
if (match.Success)
{
TrackREventDispatcher.OnJumpDriveStateChangedEvent(match.Groups[1].Value);;
data.ShipName = match.Groups[1].Value;
}
if (!string.IsNullOrEmpty(data.ShipName) && !string.IsNullOrEmpty(data.Location))
{
TrackREventDispatcher.OnJumpDriveStateChangedEvent(data);
}
}
}

View file

@ -9,7 +9,7 @@ public class RequestJumpFailedEvent : ILogEventHandler
public RequestJumpFailedEvent()
{
Pattern = new Regex(@"<Request Jump Failed>.*.adam: (?<ShipName>.*.) in");
Pattern = new Regex(@"<Request Jump Failed>.*.adam: (?<ShipName>.*.) in zone (?<Location>.*.)\)");
}
public void Handle(LogEntry entry)
@ -18,10 +18,20 @@ public class RequestJumpFailedEvent : ILogEventHandler
var match = Pattern.Match(entry.Message);
if (!match.Success) return;
var data = new JumpDriveStateChangedData
{
Location = match.Groups["Location"].Value
};
match = _cleanUpPattern.Match(match.Groups["ShipName"].Value);
if (match.Success)
{
TrackREventDispatcher.OnJumpDriveStateChangedEvent(match.Groups[1].Value);;
data.ShipName = match.Groups[1].Value;
}
if (!string.IsNullOrEmpty(data.ShipName) && !string.IsNullOrEmpty(data.Location))
{
TrackREventDispatcher.OnJumpDriveStateChangedEvent(data);
}
}
}

View file

@ -21,14 +21,16 @@ public class VehicleDestructionEvent : ILogEventHandler
public Regex Pattern { get; }
public VehicleDestructionEvent()
{
Pattern = new Regex("""
"<(?<timestamp>[^>]+)> \[Notice\] <Vehicle Destruction> CVehicle::OnAdvanceDestroyLevel: " +
"Vehicle '(?<vehicle>[^']+)' \[\d+\] in zone '(?<vehicle_zone>[^']+)' " +
"\[pos x: (?<pos_x>[-\d\.]+), y: (?<pos_y>[-\d\.]+), z: (?<pos_z>[-\d\.]+) " +
"vel x: [^,]+, y: [^,]+, z: [^\]]+\] driven by '(?<driver>[^']+)' \[\d+\] " +
"advanced from destroy level (?<destroy_level_from>\d+) to (?<destroy_level_to>\d+) " +
"caused by '(?<caused_by>[^']+)' \[\d+\] with '(?<damage_type>[^']+)'"
""");
const string patternStr = """
<(?<timestamp>[^>]+)> \[Notice\] <Vehicle Destruction> CVehicle::OnAdvanceDestroyLevel:
Vehicle '(?<vehicle>[^']+)' \[\d+\] in zone '(?<vehicle_zone>[^']+)'
\[pos x: (?<pos_x>[-\d\.]+), y: (?<pos_y>[-\d\.]+), z: (?<pos_z>[-\d\.]+)
vel x: [^,]+, y: [^,]+, z: [^\]]+\] driven by '(?<driver>[^']+)' \[\d+\]
advanced from destroy level (?<destroy_level_from>\d+) to (?<destroy_level_to>\d+)
caused by '(?<caused_by>[^']+)' \[\d+\] with '(?<damage_type>[^']+)'
""";
Pattern = new Regex(Regex.Replace(patternStr, @"\t|\n|\r", ""));
}
public void Handle(LogEntry entry)

View file

@ -42,7 +42,8 @@ public class LogHandler
new InPersistentUniverseEvent(),
new GameVersionEvent(),
new JumpDriveStateChangedEvent(),
new RequestJumpFailedEvent()
new RequestJumpFailedEvent(),
new VehicleDestructionEvent()
];
public LogHandler(string? logPath)

View file

@ -49,9 +49,9 @@ public static class TrackREventDispatcher
// Jump Drive state has changed
// Todo: Add proper data for this event. Right now only ship name is used.
public static event Action<string>? JumpDriveStateChangedEvent;
public static void OnJumpDriveStateChangedEvent(string shipName)
public static event Action<JumpDriveStateChangedData>? JumpDriveStateChangedEvent;
public static void OnJumpDriveStateChangedEvent(JumpDriveStateChangedData data)
{
JumpDriveStateChangedEvent?.Invoke(shipName);
JumpDriveStateChangedEvent?.Invoke(data);
}
}

View file

@ -19,6 +19,7 @@ public struct KillData
public string? Enlisted;
public string? RecordNumber;
public string? OrgAffiliation;
public string? Location;
public string? Player;
public string? Weapon;
public string? Ship;

View file

@ -94,7 +94,7 @@ public static class WebHandler
loadout_ship = killData.Ship,
game_version = killData.GameVersion,
trackr_version = killData.TrackRver,
location = "Unknown",
location = killData.Location,
time = DateTimeOffset.UtcNow.ToUnixTimeSeconds()
};
@ -123,6 +123,7 @@ public static class WebHandler
Console.WriteLine($"API URL: {ConfigManager.ApiUrl}register-kill");
Console.WriteLine($"Victim: {apiKillData.victim}");
Console.WriteLine($"Victim Ship: {apiKillData.victim_ship}");
Console.WriteLine($"Location: {apiKillData.location}");
Console.WriteLine($"Weapon: {apiKillData.weapon}");
Console.WriteLine($"Method: {apiKillData.method}");
Console.WriteLine($"Game Mode: {apiKillData.gamemode}");