From fc1bb34bc258f183faf7fd3848a455272827e7d5 Mon Sep 17 00:00:00 2001 From: Terkoiz Date: Sat, 30 Dec 2023 21:26:22 +0200 Subject: [PATCH] Fixed post-raid healing; Exposed SessionId from RequestHandler --- project/Aki.Common/Http/RequestHandler.cs | 17 +++++++++-------- .../Patches/Healing/PlayerPatch.cs | 3 ++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/project/Aki.Common/Http/RequestHandler.cs b/project/Aki.Common/Http/RequestHandler.cs index 1b73438..c62bc83 100644 --- a/project/Aki.Common/Http/RequestHandler.cs +++ b/project/Aki.Common/Http/RequestHandler.cs @@ -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 _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() { - { "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); } } diff --git a/project/Aki.SinglePlayer/Patches/Healing/PlayerPatch.cs b/project/Aki.SinglePlayer/Patches/Healing/PlayerPatch.cs index a5828b4..b974584 100644 --- a/project/Aki.SinglePlayer/Patches/Healing/PlayerPatch.cs +++ b/project/Aki.SinglePlayer/Patches/Healing/PlayerPatch.cs @@ -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;