From 1e9133d02762a5f020a1b9245d8a69c372813460 Mon Sep 17 00:00:00 2001 From: JustArchi Date: Tue, 15 Nov 2016 14:24:04 +0100 Subject: [PATCH] Implement experimental workaround for fuckups --- ArchiSteamFarm/Bot.cs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index c5b86dd85..80e607b20 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -98,6 +98,7 @@ namespace ArchiSteamFarm { internal ulong SteamID => SteamClient.SteamID; private bool FirstTradeSent, PlayingBlocked, SkipFirstShutdown; + private byte HeartBeatFailures; private string AuthCode, TwoFactorCode; private ulong LibraryLockedBySteamID; private EResult LastLogOnResult; @@ -624,22 +625,35 @@ namespace ArchiSteamFarm { } } - private void Destroy() { - Stop(); + private void Destroy(bool force = false) { + if (!force) { + Stop(); + } else { + // Stop() will most likely block due to fuckup, don't wait for it + Task.Run(() => Stop()).Forget(); + } Bot ignored; Bots.TryRemove(BotName, out ignored); } private async Task HeartBeat() { - if (!IsConnectedAndLoggedOn) { + if (!IsConnectedAndLoggedOn || (HeartBeatFailures == byte.MaxValue)) { return; } try { await SteamApps.PICSGetProductInfo(0, null); } catch { - if (!IsConnectedAndLoggedOn) { + if (!IsConnectedAndLoggedOn || (HeartBeatFailures == byte.MaxValue)) { + return; + } + + if (++HeartBeatFailures >= 15) { + HeartBeatFailures = byte.MaxValue; + ArchiLogger.LogGenericError("HeartBeat failed to disconnect the client, abandoning this bot instance!"); + Destroy(true); + new Bot(BotName).Forget(); return; }