From 939391a275977f78d8877db3f481738b897795de Mon Sep 17 00:00:00 2001 From: JustArchi Date: Sat, 8 Oct 2016 17:42:52 +0200 Subject: [PATCH] Add 5 seconds delay when issuing reconnects due to network issues Also clean up that part of code while I'm at it --- ArchiSteamFarm/Bot.cs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 5eba970a7..d432bb3bb 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -1850,20 +1850,26 @@ namespace ArchiSteamFarm { return; } - if (lastLogOnResult != EResult.Invalid) { - if (lastLogOnResult == EResult.InvalidPassword) { - if (!string.IsNullOrEmpty(BotDatabase.LoginKey)) { // InvalidPassword means usually that login key has expired, if we used it - BotDatabase.LoginKey = null; - Logging.LogGenericInfo("Removed expired login key", BotName); - } else { // If we didn't use login key, InvalidPassword usually means we got captcha or other network-based throttling - lastLogOnResult = EResult.RateLimitExceeded; + switch (lastLogOnResult) { + 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; } - } - if (lastLogOnResult == EResult.RateLimitExceeded) { + BotDatabase.LoginKey = null; + Logging.LogGenericInfo("Removed expired login key", BotName); + break; + case EResult.NoConnection: + case EResult.ServiceUnavailable: + case EResult.Timeout: + case EResult.TryAnotherCM: + await Task.Delay(5000).ConfigureAwait(false); + break; + case EResult.RateLimitExceeded: Logging.LogGenericInfo("Will retry after 25 minutes...", BotName); await Task.Delay(25 * 60 * 1000).ConfigureAwait(false); // Captcha disappears after around 20 minutes, so we make it 25 - } + break; } if (!KeepRunning || SteamClient.IsConnected) {