mirror of
https://github.com/BubbaGumpShrump/AutoTrackR2.git
synced 2025-05-23 17:15:29 +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
|
||||
KillTallyTitle.Text = $"Kill Tally - {_killHistoryManager.GetKillsInCurrentMonth().Count}";
|
||||
AddKillHistoryKillsToUI();
|
||||
|
||||
}
|
||||
|
||||
// Update Start/Stop button states based on the isRunning flag
|
||||
//
|
||||
public void UpdateButtonState(bool isRunning)
|
||||
{
|
||||
var accentColor = (Color)Application.Current.Resources["AccentColor"];
|
||||
|
|
|
@ -34,7 +34,19 @@ public class KillHistoryManager
|
|||
// Append the new kill data to the CSV file
|
||||
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}\"");
|
||||
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()
|
||||
|
|
|
@ -78,7 +78,7 @@ public class LogHandler(string logPath)
|
|||
// Parse a single line of the log file and run matching handlers
|
||||
private void HandleLogEntry(string line)
|
||||
{
|
||||
Console.WriteLine(line);
|
||||
// Console.WriteLine(line);
|
||||
foreach (var handler in _eventHandlers)
|
||||
{
|
||||
var match = handler.Pattern.Match(line);
|
||||
|
@ -98,6 +98,11 @@ public class LogHandler(string logPath)
|
|||
{
|
||||
while (!token.IsCancellationRequested)
|
||||
{
|
||||
if (_reader == null || _fileStream == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
CheckGameProcessState();
|
||||
|
||||
List<string> lines = new List<string>();
|
||||
|
|
|
@ -80,6 +80,8 @@ public static class WebHandler
|
|||
|
||||
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
|
||||
{
|
||||
victim_ship = killData.EnemyShip,
|
||||
|
@ -88,6 +90,7 @@ public static class WebHandler
|
|||
rsi = killData.RecordNumber,
|
||||
weapon = killData.Weapon,
|
||||
method = killData.Method,
|
||||
gamemode = killData.Mode,
|
||||
// loadout_ship = LocalPlayerData.PlayerShip ?? "Unknown",
|
||||
loadout_ship = killData.Ship,
|
||||
game_version = killData.GameVersion,
|
||||
|
@ -95,11 +98,25 @@ public static class WebHandler
|
|||
location = "Unknown"
|
||||
};
|
||||
|
||||
if (string.IsNullOrEmpty(apiKillData.rsi))
|
||||
{
|
||||
apiKillData.rsi = "-1";
|
||||
}
|
||||
|
||||
var httpClient = new HttpClient();
|
||||
string jsonData = JsonSerializer.Serialize(killData);
|
||||
string jsonData = JsonSerializer.Serialize(apiKillData);
|
||||
httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + ConfigManager.ApiKey);
|
||||
httpClient.DefaultRequestHeaders.Add("User-Agent", "AutoTrackR2");
|
||||
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