From 2442016e0cccab1017f2b1b9398c6ba8d5d3511f Mon Sep 17 00:00:00 2001 From: JustArchi Date: Sat, 4 May 2019 23:19:14 +0200 Subject: [PATCH] Closes #1219 --- ArchiSteamFarm/Bot.cs | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 8fe4f42e0..d93a5af71 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -62,6 +62,7 @@ namespace ArchiSteamFarm { internal static EOSType OSType { get; private set; } = EOSType.Unknown; private static readonly SemaphoreSlim BotsSemaphore = new SemaphoreSlim(1, 1); + private static readonly SemaphoreSlim LoginRateLimitingSemaphore = new SemaphoreSlim(1, 1); private static readonly SemaphoreSlim LoginSemaphore = new SemaphoreSlim(1, 1); [JsonIgnore] @@ -1896,12 +1897,17 @@ namespace ArchiSteamFarm { await LoginSemaphore.WaitAsync().ConfigureAwait(false); - Utilities.InBackground( - async () => { - await Task.Delay(ASF.GlobalConfig.LoginLimiterDelay * 1000).ConfigureAwait(false); - LoginSemaphore.Release(); - } - ); + try { + await LoginRateLimitingSemaphore.WaitAsync().ConfigureAwait(false); + LoginRateLimitingSemaphore.Release(); + } finally { + Utilities.InBackground( + async () => { + await Task.Delay(ASF.GlobalConfig.LoginLimiterDelay * 1000).ConfigureAwait(false); + LoginSemaphore.Release(); + } + ); + } } private async void OnConnected(SteamClient.ConnectedCallback callback) { @@ -2071,7 +2077,15 @@ namespace ArchiSteamFarm { break; case EResult.RateLimitExceeded: ArchiLogger.LogGenericInfo(string.Format(Strings.BotRateLimitExceeded, TimeSpan.FromMinutes(LoginCooldownInMinutes).ToHumanReadable())); - await Task.Delay(LoginCooldownInMinutes * 60 * 1000).ConfigureAwait(false); + + await LoginRateLimitingSemaphore.WaitAsync().ConfigureAwait(false); + + Utilities.InBackground( + async () => { + await Task.Delay(LoginCooldownInMinutes * 60 * 1000).ConfigureAwait(false); + LoginRateLimitingSemaphore.Release(); + } + ); break; }