mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-25 15:09:26 -07:00
48 lines
1.3 KiB
C#
48 lines
1.3 KiB
C#
using System;
|
|
using System.Threading;
|
|
using HarmonyLib;
|
|
|
|
internal static class ConnectionGate
|
|
{
|
|
private const int WaitMilliseconds = 15000;
|
|
|
|
private static readonly ManualResetEventSlim Opened = new ManualResetEventSlim(false);
|
|
|
|
private static int _holds;
|
|
|
|
internal static void Install(Harmony harmony)
|
|
{
|
|
harmony.PatchAll(typeof(ConnectionGatePatch));
|
|
}
|
|
|
|
internal static void Open()
|
|
{
|
|
Opened.Set();
|
|
}
|
|
|
|
internal static void Hold()
|
|
{
|
|
if (Opened.IsSet) return;
|
|
|
|
var count = Interlocked.Increment(ref _holds);
|
|
RadicadeEacBypassPlugin.LogSource.LogWarning("[Patch] a server request arrived before the patch list finished; holding it until it does (hold #"
|
|
+ count + ").");
|
|
|
|
if (Opened.Wait(WaitMilliseconds)) return;
|
|
|
|
RadicadeEacBypassPlugin.LogSource.LogError("[Patch] the patch list did not finish within "
|
|
+ (WaitMilliseconds / 1000) + "s; releasing this request and every later one so the client is not held forever.");
|
|
Opened.Set();
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(BestHTTP.HTTPManager), "SendRequest", new[] { typeof(BestHTTP.HTTPRequest) })]
|
|
internal static class ConnectionGatePatch
|
|
{
|
|
[HarmonyPriority(Priority.First)]
|
|
internal static void Prefix()
|
|
{
|
|
ConnectionGate.Hold();
|
|
}
|
|
}
|