mirror of
https://github.com/BubbaGumpShrump/AutoTrackR2.git
synced 2025-06-18 20:59:05 +00:00
Added unix timestamp to webhandler and consonsole writes.
This commit is contained in:
parent
2dcf2e3571
commit
e28fc836e7
1 changed files with 40 additions and 24 deletions
|
@ -4,6 +4,7 @@ using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using AutoTrackR2.LogEventHandlers;
|
using AutoTrackR2.LogEventHandlers;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
namespace AutoTrackR2;
|
namespace AutoTrackR2;
|
||||||
|
|
||||||
|
@ -11,17 +12,18 @@ public static class WebHandler
|
||||||
{
|
{
|
||||||
class APIKillData
|
class APIKillData
|
||||||
{
|
{
|
||||||
public string? victim_ship { get; set; }
|
public string? victim_ship { get; set; }
|
||||||
public string? victim{ get; set; }
|
public string? victim { get; set; }
|
||||||
public string? enlisted{ get; set; }
|
public string? enlisted { get; set; }
|
||||||
public string? rsi{ get; set; }
|
public string? rsi { get; set; }
|
||||||
public string? weapon{ get; set; }
|
public string? weapon { get; set; }
|
||||||
public string? method{ get; set; }
|
public string? method { get; set; }
|
||||||
public string? loadout_ship{ get; set; }
|
public string? loadout_ship { get; set; }
|
||||||
public string? game_version{ get; set; }
|
public string? game_version { get; set; }
|
||||||
public string? gamemode{ get; set; }
|
public string? gamemode { get; set; }
|
||||||
public string? trackr_version{ get; set; }
|
public string? trackr_version { get; set; }
|
||||||
public string? location{ get; set; }
|
public string? location { get; set; }
|
||||||
|
public long time { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<PlayerData?> GetPlayerData(string enemyPilot)
|
public static async Task<PlayerData?> GetPlayerData(string enemyPilot)
|
||||||
|
@ -30,12 +32,12 @@ public static class WebHandler
|
||||||
var ueePattern = new Regex("<p class=\"entry citizen-record\">\\n.*.<span class=\"label\">UEE Citizen Record<\\/span>\\n.*.<strong class=\"value\">#(?<UEERecord>\\d+)<\\/strong>");
|
var ueePattern = new Regex("<p class=\"entry citizen-record\">\\n.*.<span class=\"label\">UEE Citizen Record<\\/span>\\n.*.<strong class=\"value\">#(?<UEERecord>\\d+)<\\/strong>");
|
||||||
var orgPattern = new Regex("\\/orgs\\/(?<OrgURL>[A-z0-9]+)\" .*\\>(?<OrgName>.*)<");
|
var orgPattern = new Regex("\\/orgs\\/(?<OrgURL>[A-z0-9]+)\" .*\\>(?<OrgName>.*)<");
|
||||||
var pfpPattern = new Regex("/media/(.*)\"");
|
var pfpPattern = new Regex("/media/(.*)\"");
|
||||||
|
|
||||||
// Make web request to check player data
|
// Make web request to check player data
|
||||||
var playerData = new PlayerData();
|
var playerData = new PlayerData();
|
||||||
var httpClient = new HttpClient();
|
var httpClient = new HttpClient();
|
||||||
var response = await httpClient.GetAsync($"https://robertsspaceindustries.com/en/citizens/{enemyPilot}");
|
var response = await httpClient.GetAsync($"https://robertsspaceindustries.com/en/citizens/{enemyPilot}");
|
||||||
|
|
||||||
if (response.StatusCode != HttpStatusCode.OK)
|
if (response.StatusCode != HttpStatusCode.OK)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
@ -47,20 +49,20 @@ public static class WebHandler
|
||||||
{
|
{
|
||||||
playerData.JoinDate = joinDataMatch.Groups[1].Value;
|
playerData.JoinDate = joinDataMatch.Groups[1].Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
var ueeMatch = ueePattern.Match(content);
|
var ueeMatch = ueePattern.Match(content);
|
||||||
if (ueeMatch.Success)
|
if (ueeMatch.Success)
|
||||||
{
|
{
|
||||||
playerData.UEERecord = ueeMatch.Groups["UEERecord"].Value == "n/a" ? "-1" : ueeMatch.Groups[1].Value;
|
playerData.UEERecord = ueeMatch.Groups["UEERecord"].Value == "n/a" ? "-1" : ueeMatch.Groups[1].Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
var orgMatch = orgPattern.Match(content);
|
var orgMatch = orgPattern.Match(content);
|
||||||
if (orgMatch.Success)
|
if (orgMatch.Success)
|
||||||
{
|
{
|
||||||
playerData.OrgName = orgMatch.Groups["OrgName"].Value;
|
playerData.OrgName = orgMatch.Groups["OrgName"].Value;
|
||||||
playerData.OrgURL = "https://robertsspaceindustries.com/en/orgs/" + orgMatch.Groups["OrgURL"].Value;
|
playerData.OrgURL = "https://robertsspaceindustries.com/en/orgs/" + orgMatch.Groups["OrgURL"].Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
var pfpMatch = pfpPattern.Match(content);
|
var pfpMatch = pfpPattern.Match(content);
|
||||||
if (pfpMatch.Success)
|
if (pfpMatch.Success)
|
||||||
{
|
{
|
||||||
|
@ -77,11 +79,9 @@ public static class WebHandler
|
||||||
|
|
||||||
return playerData;
|
return playerData;
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
||||||
|
@ -91,32 +91,48 @@ public static class WebHandler
|
||||||
weapon = killData.Weapon,
|
weapon = killData.Weapon,
|
||||||
method = killData.Method,
|
method = killData.Method,
|
||||||
gamemode = killData.Mode,
|
gamemode = killData.Mode,
|
||||||
// loadout_ship = LocalPlayerData.PlayerShip ?? "Unknown",
|
|
||||||
loadout_ship = killData.Ship,
|
loadout_ship = killData.Ship,
|
||||||
game_version = killData.GameVersion,
|
game_version = killData.GameVersion,
|
||||||
trackr_version = killData.TrackRver,
|
trackr_version = killData.TrackRver,
|
||||||
location = "Unknown"
|
location = "Unknown",
|
||||||
|
time = DateTimeOffset.UtcNow.ToUnixTimeSeconds()
|
||||||
};
|
};
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(apiKillData.rsi))
|
if (string.IsNullOrEmpty(apiKillData.rsi))
|
||||||
{
|
{
|
||||||
apiKillData.rsi = "-1";
|
apiKillData.rsi = "-1";
|
||||||
}
|
}
|
||||||
|
|
||||||
var httpClient = new HttpClient();
|
var httpClient = new HttpClient();
|
||||||
string jsonData = JsonSerializer.Serialize(apiKillData);
|
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");
|
||||||
|
|
||||||
|
Console.WriteLine("\n=== Kill Submission Debug Info ===");
|
||||||
|
Console.WriteLine($"API URL: {ConfigManager.ApiUrl}register-kill");
|
||||||
|
Console.WriteLine($"Victim: {apiKillData.victim}");
|
||||||
|
Console.WriteLine($"Victim Ship: {apiKillData.victim_ship}");
|
||||||
|
Console.WriteLine($"Weapon: {apiKillData.weapon}");
|
||||||
|
Console.WriteLine($"Method: {apiKillData.method}");
|
||||||
|
Console.WriteLine($"Game Mode: {apiKillData.gamemode}");
|
||||||
|
Console.WriteLine($"Time (Unix): {apiKillData.time}");
|
||||||
|
Console.WriteLine($"Time (UTC): {DateTimeOffset.UtcNow}");
|
||||||
|
Console.WriteLine("=== End Debug Info ===\n");
|
||||||
|
|
||||||
var response = 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)
|
if (response.StatusCode != HttpStatusCode.OK)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Failed to submit kill data: ");
|
Console.WriteLine("Failed to submit kill data:");
|
||||||
|
Console.WriteLine($"Status Code: {response.StatusCode}");
|
||||||
|
Console.WriteLine($"Response: {await response.Content.ReadAsStringAsync()}");
|
||||||
|
Console.WriteLine("Request Data:");
|
||||||
Console.WriteLine(jsonData);
|
Console.WriteLine(jsonData);
|
||||||
}
|
}
|
||||||
else if (response.StatusCode == HttpStatusCode.OK)
|
else if (response.StatusCode == HttpStatusCode.OK)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Successfully submitted kill data");
|
Console.WriteLine("Successfully submitted kill data");
|
||||||
|
Console.WriteLine($"Response: {await response.Content.ReadAsStringAsync()}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue