From 04bf32e3724e63f5fa657a97ccec5b91acbbf2d6 Mon Sep 17 00:00:00 2001 From: JustArchi Date: Fri, 12 Apr 2019 13:43:48 +0200 Subject: [PATCH] Improve cooldown when ASF detects recent playing --- ArchiSteamFarm/Bot.cs | 27 +++++++++++++------ ArchiSteamFarm/CardsFarmer.cs | 2 ++ .../Localization/Strings.Designer.cs | 9 +++++++ ArchiSteamFarm/Localization/Strings.resx | 4 +++ 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index ebe7d5a65..2152dd846 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -1460,14 +1460,17 @@ namespace ArchiSteamFarm { StopPlayingWasBlockedTimer(); if (!IsPlayingPossible) { - ArchiLogger.LogGenericInfo(Strings.BotAccountOccupied); PlayingWasBlocked = true; + ArchiLogger.LogGenericInfo(Strings.BotAccountOccupied); return; } + if (PlayingWasBlocked && (PlayingWasBlockedTimer == null)) { + InitPlayingWasBlockedTimer(); + } + ArchiLogger.LogGenericInfo(Strings.BotAccountFree); - PlayingWasBlocked = false; if (!await CardsFarmer.Resume(false).ConfigureAwait(false)) { await ResetGamesPlayed().ConfigureAwait(false); @@ -1797,6 +1800,19 @@ namespace ArchiSteamFarm { await RegisterBot(BotName).ConfigureAwait(false); } + private void InitPlayingWasBlockedTimer() { + if (PlayingWasBlockedTimer != null) { + return; + } + + PlayingWasBlockedTimer = new Timer( + e => ResetPlayingWasBlockedWithTimer(), + null, + TimeSpan.FromSeconds(MinPlayingBlockedTTL), // Delay + Timeout.InfiniteTimeSpan // Period + ); + } + private void InitStart() { if (!BotConfig.Enabled) { ArchiLogger.LogGenericInfo(Strings.BotInstanceNotStartingBecauseDisabled); @@ -2353,12 +2369,7 @@ namespace ArchiSteamFarm { PlayingBlocked = false; if (PlayingWasBlocked && (PlayingWasBlockedTimer == null)) { - PlayingWasBlockedTimer = new Timer( - e => ResetPlayingWasBlockedWithTimer(), - null, - TimeSpan.FromSeconds(MinPlayingBlockedTTL), // Delay - Timeout.InfiniteTimeSpan // Period - ); + InitPlayingWasBlockedTimer(); } if (IsAccountLimited) { diff --git a/ArchiSteamFarm/CardsFarmer.cs b/ArchiSteamFarm/CardsFarmer.cs index 95d1eebb7..1c01af9d4 100755 --- a/ArchiSteamFarm/CardsFarmer.cs +++ b/ArchiSteamFarm/CardsFarmer.cs @@ -268,6 +268,8 @@ namespace ArchiSteamFarm { } if (Bot.PlayingWasBlocked) { + Bot.ArchiLogger.LogGenericInfo(string.Format(Strings.BotExtraIdlingCooldown, TimeSpan.FromSeconds(Bot.MinPlayingBlockedTTL).ToHumanReadable())); + for (byte i = 0; (i < Bot.MinPlayingBlockedTTL) && Bot.IsPlayingPossible; i++) { await Task.Delay(1000).ConfigureAwait(false); } diff --git a/ArchiSteamFarm/Localization/Strings.Designer.cs b/ArchiSteamFarm/Localization/Strings.Designer.cs index 876c14600..fbf54b16b 100644 --- a/ArchiSteamFarm/Localization/Strings.Designer.cs +++ b/ArchiSteamFarm/Localization/Strings.Designer.cs @@ -312,6 +312,15 @@ namespace ArchiSteamFarm.Localization { } } + /// + /// Wyszukuje zlokalizowany ciąg podobny do ciągu Waiting additional {0} to ensure that we're free to start idling.... + /// + public static string BotExtraIdlingCooldown { + get { + return ResourceManager.GetString("BotExtraIdlingCooldown", resourceCulture); + } + } + /// /// Wyszukuje zlokalizowany ciąg podobny do ciągu Bot has {0} games remaining in its background queue.. /// diff --git a/ArchiSteamFarm/Localization/Strings.resx b/ArchiSteamFarm/Localization/Strings.resx index 5d1a6625b..ab8c27a89 100644 --- a/ArchiSteamFarm/Localization/Strings.resx +++ b/ArchiSteamFarm/Localization/Strings.resx @@ -724,4 +724,8 @@ StackTrace: Successfully handled {0} confirmations! {0} will be replaced by number of confirmations + + Waiting additional {0} to ensure that we're free to start idling... + {0} will be replaced by translated TimeSpan string (such as "1 minute") + \ No newline at end of file