0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-12 22:30:44 -05:00

Fixed post-raid healing; Exposed SessionId from RequestHandler

This commit is contained in:
Terkoiz 2023-12-30 21:26:22 +02:00
parent 8590f243a4
commit fc1bb34bc2
2 changed files with 11 additions and 9 deletions

View File

@ -9,11 +9,12 @@ namespace Aki.Common.Http
public static class RequestHandler
{
private static string _host;
private static string _session;
private static Request _request;
private static Dictionary<string, string> _headers;
private static ManualLogSource _logger;
public static string SessionId { get; private set; }
static RequestHandler()
{
_logger = Logger.CreateLogSource(nameof(RequestHandler));
@ -36,11 +37,11 @@ namespace Aki.Common.Http
if (arg.Contains("-token="))
{
_session = arg.Replace("-token=", string.Empty);
SessionId = arg.Replace("-token=", string.Empty);
_headers = new Dictionary<string, string>()
{
{ "Cookie", $"PHPSESSID={_session}" },
{ "SessionId", _session }
{ "Cookie", $"PHPSESSID={SessionId}" },
{ "SessionId", SessionId }
};
}
}
@ -70,7 +71,7 @@ namespace Aki.Common.Http
{
string url = (hasHost) ? path : _host + path;
_logger.LogInfo($"Request GET data: {_session}:{url}");
_logger.LogInfo($"Request GET data: {SessionId}:{url}");
byte[] result = _request.Send(url, "GET", null, headers: _headers);
ValidateData(result);
@ -81,7 +82,7 @@ namespace Aki.Common.Http
{
string url = (hasHost) ? path : _host + path;
_logger.LogInfo($"Request GET json: {_session}:{url}");
_logger.LogInfo($"Request GET json: {SessionId}:{url}");
byte[] data = _request.Send(url, "GET", headers: _headers);
string result = Encoding.UTF8.GetString(data);
@ -93,7 +94,7 @@ namespace Aki.Common.Http
{
string url = (hasHost) ? path : _host + path;
_logger.LogInfo($"Request POST json: {_session}:{url}");
_logger.LogInfo($"Request POST json: {SessionId}:{url}");
byte[] data = _request.Send(url, "POST", Encoding.UTF8.GetBytes(json), true, "application/json", _headers);
string result = Encoding.UTF8.GetString(data);
@ -104,7 +105,7 @@ namespace Aki.Common.Http
public static void PutJson(string path, string json, bool hasHost = false)
{
string url = (hasHost) ? path : _host + path;
_logger.LogInfo($"Request PUT json: {_session}:{url}");
_logger.LogInfo($"Request PUT json: {SessionId}:{url}");
_request.Send(url, "PUT", Encoding.UTF8.GetBytes(json), true, "application/json", _headers);
}
}

View File

@ -1,3 +1,4 @@
using System;
using Aki.Reflection.Patching;
using Aki.Reflection.Utils;
using EFT;
@ -24,7 +25,7 @@ namespace Aki.SinglePlayer.Patches.Healing
{
await __result;
if (profile?.Id.StartsWith("pmc") == true)
if (profile?.Id.Equals(Common.Http.RequestHandler.SessionId, StringComparison.InvariantCultureIgnoreCase) ?? false)
{
Logger.LogDebug($"Hooking up health listener to profile: {profile.Id}");
var listener = Utils.Healing.HealthListener.Instance;