mirror of
https://github.com/BubbaGumpShrump/AutoTrackR2.git
synced 2025-07-25 02:47:49 +00:00
Initial refactor to C# from PS
This commit is contained in:
parent
77a3c936fd
commit
a08de59a73
15 changed files with 855 additions and 300 deletions
AutoTrackR2
102
AutoTrackR2/WebHandler.cs
Normal file
102
AutoTrackR2/WebHandler.cs
Normal file
|
@ -0,0 +1,102 @@
|
|||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
using AutoTrackR2.LogEventHandlers;
|
||||
|
||||
namespace AutoTrackR2;
|
||||
|
||||
public static class WebHandler
|
||||
{
|
||||
class APIKillData
|
||||
{
|
||||
public string? victim_ship { get; set; }
|
||||
public string? victim{ get; set; }
|
||||
public string? enlisted{ get; set; }
|
||||
public string? rsi{ get; set; }
|
||||
public string? weapon{ get; set; }
|
||||
public string? method{ get; set; }
|
||||
public string? loadout_ship{ get; set; }
|
||||
public string? game_version{ get; set; }
|
||||
public string? gamemode{ get; set; }
|
||||
public string? trackr_version{ get; set; }
|
||||
public string? location{ get; set; }
|
||||
}
|
||||
|
||||
public static async Task<PlayerData?> GetPlayerData(string enemyPilot)
|
||||
{
|
||||
var joinDataPattern = new Regex("<span class=\"label\">Enlisted</span>\\s*<strong class=\"value\">([^<]+)</strong>");
|
||||
var ueePattern = new Regex("<p class=\"entry citizen-record\">\\s*<span class=\"label\">UEE Citizen Record<\\/span>\\s*<strong class=\"value\">#?(n\\/a|\\d+)<\\/strong>\\s*<\\/p>");
|
||||
var orgPattern = new Regex("\\/orgs\\/(?<OrgURL>[A-z0-9]+)\" .*\\>(?<OrgName>.*)<");
|
||||
var pfpPattern = new Regex("/media/(.*)\"");
|
||||
|
||||
// Make web request to check player data
|
||||
var playerData = new PlayerData();
|
||||
var httpClient = new HttpClient();
|
||||
var response = await httpClient.GetAsync($"https://robertsspaceindustries.com/en/citizens/{enemyPilot}");
|
||||
|
||||
if (response.StatusCode != HttpStatusCode.OK)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var content = await response.Content.ReadAsStringAsync();
|
||||
var joinDataMatch = joinDataPattern.Match(content);
|
||||
if (joinDataMatch.Success)
|
||||
{
|
||||
playerData.JoinDate = joinDataMatch.Groups[1].Value;
|
||||
}
|
||||
|
||||
var ueeMatch = ueePattern.Match(content);
|
||||
if (ueeMatch.Success)
|
||||
{
|
||||
playerData.UEERecord = ueeMatch.Groups[1].Value;
|
||||
}
|
||||
|
||||
var orgMatch = orgPattern.Match(content);
|
||||
if (orgMatch.Success)
|
||||
{
|
||||
playerData.OrgName = orgMatch.Groups["OrgName"].Value;
|
||||
playerData.OrgURL = "https://robertsspaceindustries.com/en/orgs/" + orgMatch.Groups["OrgURL"].Value;
|
||||
}
|
||||
|
||||
var pfpMatch = pfpPattern.Match(content);
|
||||
if (pfpMatch.Success)
|
||||
{
|
||||
var match = pfpMatch.Groups[1].Value;
|
||||
if (match.Contains("heap_thumb"))
|
||||
{
|
||||
playerData.PFPURL = "https://cdn.robertsspaceindustries.com/static/images/account/avatar_default_big.jpg";
|
||||
}
|
||||
else
|
||||
{
|
||||
playerData.PFPURL = "https://robertsspaceindustries.com/media/" + pfpMatch.Groups[1].Value;
|
||||
}
|
||||
}
|
||||
|
||||
return playerData;
|
||||
}
|
||||
|
||||
public static async Task SubmitKill(ActorDeathData deathData, PlayerData? enemyPlayerData)
|
||||
{
|
||||
var killData = new APIKillData
|
||||
{
|
||||
victim_ship = deathData.VictimShip,
|
||||
victim = deathData.VictimPilot,
|
||||
enlisted = enemyPlayerData?.JoinDate,
|
||||
rsi = enemyPlayerData?.UEERecord,
|
||||
weapon = deathData.Weapon,
|
||||
method = deathData.DamageType,
|
||||
loadout_ship = LocalPlayerData.PlayerShip ?? "Unknown",
|
||||
game_version = LocalPlayerData.GameVersion ?? "Unknown",
|
||||
gamemode = LocalPlayerData.CurrentGameMode.ToString() ?? "Unknown",
|
||||
trackr_version = UpdatePage.currentVersion ?? "Unknown",
|
||||
location = LocalPlayerData.LastSeenVehicleLocation ?? "Unknown"
|
||||
};
|
||||
|
||||
var httpClient = new HttpClient();
|
||||
string jsonData = JsonSerializer.Serialize(killData);
|
||||
await httpClient.PostAsync(ConfigManager.ApiUrl + "/register-kill", new StringContent(jsonData, Encoding.UTF8, "application/json"));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue