mirror of
https://github.com/BubbaGumpShrump/AutoTrackR2.git
synced 2025-06-19 13:09:07 +00:00
Varius bug fixes
This commit is contained in:
parent
e9f0e75d60
commit
666b5ce11f
4 changed files with 40 additions and 6 deletions
|
@ -28,9 +28,9 @@ public partial class HomePage : UserControl
|
||||||
// Set the TextBlock text
|
// Set the TextBlock text
|
||||||
KillTallyTitle.Text = $"Kill Tally - {_killHistoryManager.GetKillsInCurrentMonth().Count}";
|
KillTallyTitle.Text = $"Kill Tally - {_killHistoryManager.GetKillsInCurrentMonth().Count}";
|
||||||
AddKillHistoryKillsToUI();
|
AddKillHistoryKillsToUI();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//
|
||||||
// Update Start/Stop button states based on the isRunning flag
|
|
||||||
public void UpdateButtonState(bool isRunning)
|
public void UpdateButtonState(bool isRunning)
|
||||||
{
|
{
|
||||||
var accentColor = (Color)Application.Current.Resources["AccentColor"];
|
var accentColor = (Color)Application.Current.Resources["AccentColor"];
|
||||||
|
|
|
@ -34,7 +34,19 @@ public class KillHistoryManager
|
||||||
// Append the new kill data to the CSV file
|
// Append the new kill data to the CSV file
|
||||||
var csv = new StringBuilder();
|
var csv = new StringBuilder();
|
||||||
csv.AppendLine($"\"{killData.KillTime}\",\"{killData.EnemyPilot}\",\"{killData.EnemyShip}\",\"{killData.Enlisted}\",\"{killData.RecordNumber}\",\"{killData.OrgAffiliation}\",\"{killData.Player}\",\"{killData.Weapon}\",\"{killData.Ship}\",\"{killData.Method}\",\"{killData.Mode}\",\"{killData.GameVersion}\",\"{killData.TrackRver}\",\"{killData.Logged}\",\"{killData.PFP}\"");
|
csv.AppendLine($"\"{killData.KillTime}\",\"{killData.EnemyPilot}\",\"{killData.EnemyShip}\",\"{killData.Enlisted}\",\"{killData.RecordNumber}\",\"{killData.OrgAffiliation}\",\"{killData.Player}\",\"{killData.Weapon}\",\"{killData.Ship}\",\"{killData.Method}\",\"{killData.Mode}\",\"{killData.GameVersion}\",\"{killData.TrackRver}\",\"{killData.Logged}\",\"{killData.PFP}\"");
|
||||||
File.AppendAllText(_killHistoryPath, csv.ToString());
|
|
||||||
|
// Check file can be written to
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var fileStream = new FileStream(_killHistoryPath, FileMode.Append, FileAccess.Write, FileShare.None);
|
||||||
|
using var writer = new StreamWriter(fileStream);
|
||||||
|
writer.Write(csv.ToString());
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
// Handle the exception (e.g., log it)
|
||||||
|
Console.WriteLine($"Error writing to file: {ex.Message}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<KillData> GetKills()
|
public List<KillData> GetKills()
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class LogHandler(string logPath)
|
||||||
// Parse a single line of the log file and run matching handlers
|
// Parse a single line of the log file and run matching handlers
|
||||||
private void HandleLogEntry(string line)
|
private void HandleLogEntry(string line)
|
||||||
{
|
{
|
||||||
Console.WriteLine(line);
|
// Console.WriteLine(line);
|
||||||
foreach (var handler in _eventHandlers)
|
foreach (var handler in _eventHandlers)
|
||||||
{
|
{
|
||||||
var match = handler.Pattern.Match(line);
|
var match = handler.Pattern.Match(line);
|
||||||
|
@ -98,6 +98,11 @@ public class LogHandler(string logPath)
|
||||||
{
|
{
|
||||||
while (!token.IsCancellationRequested)
|
while (!token.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
|
if (_reader == null || _fileStream == null)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
CheckGameProcessState();
|
CheckGameProcessState();
|
||||||
|
|
||||||
List<string> lines = new List<string>();
|
List<string> lines = new List<string>();
|
||||||
|
|
|
@ -80,6 +80,8 @@ public static class WebHandler
|
||||||
|
|
||||||
public static async Task SubmitKill(KillData killData)
|
public static async Task SubmitKill(KillData killData)
|
||||||
{
|
{
|
||||||
|
// int secondSpaceIndex = killData.Enlisted.IndexOf(" ", killData.Enlisted.IndexOf(" ") + 1);
|
||||||
|
// killData.Enlisted = killData.Enlisted.Insert(secondSpaceIndex, ",");
|
||||||
var apiKillData = new APIKillData
|
var apiKillData = new APIKillData
|
||||||
{
|
{
|
||||||
victim_ship = killData.EnemyShip,
|
victim_ship = killData.EnemyShip,
|
||||||
|
@ -88,6 +90,7 @@ public static class WebHandler
|
||||||
rsi = killData.RecordNumber,
|
rsi = killData.RecordNumber,
|
||||||
weapon = killData.Weapon,
|
weapon = killData.Weapon,
|
||||||
method = killData.Method,
|
method = killData.Method,
|
||||||
|
gamemode = killData.Mode,
|
||||||
// loadout_ship = LocalPlayerData.PlayerShip ?? "Unknown",
|
// loadout_ship = LocalPlayerData.PlayerShip ?? "Unknown",
|
||||||
loadout_ship = killData.Ship,
|
loadout_ship = killData.Ship,
|
||||||
game_version = killData.GameVersion,
|
game_version = killData.GameVersion,
|
||||||
|
@ -95,11 +98,25 @@ public static class WebHandler
|
||||||
location = "Unknown"
|
location = "Unknown"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(apiKillData.rsi))
|
||||||
|
{
|
||||||
|
apiKillData.rsi = "-1";
|
||||||
|
}
|
||||||
|
|
||||||
var httpClient = new HttpClient();
|
var httpClient = new HttpClient();
|
||||||
string jsonData = JsonSerializer.Serialize(killData);
|
string jsonData = JsonSerializer.Serialize(apiKillData);
|
||||||
httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + ConfigManager.ApiKey);
|
httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + ConfigManager.ApiKey);
|
||||||
httpClient.DefaultRequestHeaders.Add("User-Agent", "AutoTrackR2");
|
httpClient.DefaultRequestHeaders.Add("User-Agent", "AutoTrackR2");
|
||||||
httpClient.DefaultRequestHeaders.Add("Accept", "application/json");
|
httpClient.DefaultRequestHeaders.Add("Accept", "application/json");
|
||||||
await httpClient.PostAsync(ConfigManager.ApiUrl + "register-kill", new StringContent(jsonData, Encoding.UTF8, "application/json"));
|
var response = await httpClient.PostAsync(ConfigManager.ApiUrl + "register-kill", new StringContent(jsonData, Encoding.UTF8, "application/json"));
|
||||||
|
if (response.StatusCode != HttpStatusCode.OK)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Failed to submit kill data: ");
|
||||||
|
Console.WriteLine(jsonData);
|
||||||
|
}
|
||||||
|
else if (response.StatusCode == HttpStatusCode.OK)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Successfully submitted kill data");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue