Add 5 seconds delay when issuing reconnects due to network issues

Also clean up that part of code while I'm at it
This commit is contained in:
JustArchi
2016-10-08 17:42:52 +02:00
parent fc9ae8dd7b
commit 939391a275

View File

@@ -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) {