From 08926aa2f13bcfba9094d9cc16f9a8cb100ae388 Mon Sep 17 00:00:00 2001 From: JustArchi Date: Sun, 23 Jun 2019 02:05:49 +0200 Subject: [PATCH] Improve InvalidPassword/RateLimitExceeded procedure Previously we had this awful "assume rate limit if invalid password" because Steam used to do this falsely for rate limits as well. Since I can no longer reproduce this false behaviour with latest network, I assume that Valve corrected whatever they had broken back then and the network will properly tell us RLE in RLE condition, and invalid password when account credentials are invalid. There is still case for invalid account credentials when login key is invalid, and we should still handle that one gracefully. --- ArchiSteamFarm/Bot.cs | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index cfbc143c3..0bec3bf3a 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -65,8 +65,6 @@ namespace ArchiSteamFarm { private static readonly SemaphoreSlim LoginRateLimitingSemaphore = new SemaphoreSlim(1, 1); private static readonly SemaphoreSlim LoginSemaphore = new SemaphoreSlim(1, 1); - private static bool LoginRateLimited; - [JsonIgnore] [PublicAPI] public readonly Actions Actions; @@ -2033,6 +2031,7 @@ namespace ArchiSteamFarm { switch (lastLogOnResult) { case EResult.AccountDisabled: + case EResult.InvalidPassword when string.IsNullOrEmpty(BotDatabase.LoginKey): // Do not attempt to reconnect, those failures are permanent return; case EResult.Invalid: @@ -2042,11 +2041,6 @@ namespace ArchiSteamFarm { break; case EResult.InvalidPassword: - // If we didn't use login key, it's nearly always rate limiting - if (string.IsNullOrEmpty(BotDatabase.LoginKey)) { - goto case EResult.RateLimitExceeded; - } - await BotDatabase.SetLoginKey().ConfigureAwait(false); ArchiLogger.LogGenericInfo(Strings.BotRemovedExpiredLoginKey); @@ -2061,22 +2055,12 @@ namespace ArchiSteamFarm { case EResult.RateLimitExceeded: ArchiLogger.LogGenericInfo(string.Format(Strings.BotRateLimitExceeded, TimeSpan.FromMinutes(LoginCooldownInMinutes).ToHumanReadable())); - if (LoginRateLimited) { + if (!await LoginRateLimitingSemaphore.WaitAsync(1000 * WebBrowser.MaxTries).ConfigureAwait(false)) { break; } - await LoginRateLimitingSemaphore.WaitAsync().ConfigureAwait(false); - try { - if (LoginRateLimited) { - break; - } - - LoginRateLimited = true; - await Task.Delay(LoginCooldownInMinutes * 60 * 1000).ConfigureAwait(false); - - LoginRateLimited = false; } finally { LoginRateLimitingSemaphore.Release(); } @@ -2350,6 +2334,7 @@ namespace ArchiSteamFarm { switch (callback.Result) { case EResult.AccountDisabled: + case EResult.InvalidPassword when string.IsNullOrEmpty(BotDatabase.LoginKey): // Those failures are permanent, we should Stop() the bot if any of those happen ArchiLogger.LogGenericWarning(string.Format(Strings.BotUnableToLogin, callback.Result, callback.ExtendedResult)); Stop();