From d46c3a66b7cebfc690b61c9addde93d10aed3549 Mon Sep 17 00:00:00 2001 From: JustArchi Date: Fri, 12 Oct 2018 16:54:21 +0200 Subject: [PATCH] Improve confirmations speed --- ArchiSteamFarm/Actions.cs | 45 ++++++++++++++++++++++----------------- ArchiSteamFarm/Trading.cs | 4 +--- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/ArchiSteamFarm/Actions.cs b/ArchiSteamFarm/Actions.cs index 011572632..e6a5f8084 100644 --- a/ArchiSteamFarm/Actions.cs +++ b/ArchiSteamFarm/Actions.cs @@ -55,30 +55,39 @@ namespace ArchiSteamFarm { CardsFarmerResumeTimer?.Dispose(); } - internal async Task AcceptConfirmations(bool accept, Steam.ConfirmationDetails.EType acceptedType = Steam.ConfirmationDetails.EType.Unknown, ulong acceptedSteamID = 0, IReadOnlyCollection acceptedTradeIDs = null) { + internal async Task AcceptConfirmations(bool accept, Steam.ConfirmationDetails.EType acceptedType = Steam.ConfirmationDetails.EType.Unknown, ulong acceptedSteamID = 0, IReadOnlyCollection acceptedTradeIDs = null, bool waitIfNeeded = false) { if (!Bot.HasMobileAuthenticator) { return false; } - HashSet confirmations = await Bot.BotDatabase.MobileAuthenticator.GetConfirmations(acceptedType).ConfigureAwait(false); - if ((confirmations == null) || (confirmations.Count == 0)) { - return true; - } + for (byte i = 0; (i == 0) || ((i < WebBrowser.MaxTries) && waitIfNeeded); i++) { + if (i > 0) { + await Task.Delay(1000).ConfigureAwait(false); + } + + HashSet confirmations = await Bot.BotDatabase.MobileAuthenticator.GetConfirmations(acceptedType).ConfigureAwait(false); + if ((confirmations == null) || (confirmations.Count == 0)) { + continue; + } + + if ((acceptedSteamID == 0) && ((acceptedTradeIDs == null) || (acceptedTradeIDs.Count == 0))) { + return await Bot.BotDatabase.MobileAuthenticator.HandleConfirmations(confirmations, accept).ConfigureAwait(false); + } + + IList results = await Utilities.InParallel(confirmations.Select(Bot.BotDatabase.MobileAuthenticator.GetConfirmationDetails)).ConfigureAwait(false); + + foreach (MobileAuthenticator.Confirmation confirmation in results.Where(details => (details != null) && ((acceptedType != details.Type) || ((acceptedSteamID != 0) && (details.OtherSteamID64 != 0) && (acceptedSteamID != details.OtherSteamID64)) || ((acceptedTradeIDs != null) && (details.TradeOfferID != 0) && !acceptedTradeIDs.Contains(details.TradeOfferID)))).Select(details => details.Confirmation)) { + confirmations.Remove(confirmation); + } + + if (confirmations.Count == 0) { + continue; + } - if ((acceptedSteamID == 0) && ((acceptedTradeIDs == null) || (acceptedTradeIDs.Count == 0))) { return await Bot.BotDatabase.MobileAuthenticator.HandleConfirmations(confirmations, accept).ConfigureAwait(false); } - IList results = await Utilities.InParallel(confirmations.Select(Bot.BotDatabase.MobileAuthenticator.GetConfirmationDetails)).ConfigureAwait(false); - - foreach (MobileAuthenticator.Confirmation confirmation in results.Where(details => (details != null) && ((acceptedType != details.Type) || ((acceptedSteamID != 0) && (details.OtherSteamID64 != 0) && (acceptedSteamID != details.OtherSteamID64)) || ((acceptedTradeIDs != null) && (details.TradeOfferID != 0) && !acceptedTradeIDs.Contains(details.TradeOfferID)))).Select(details => details.Confirmation)) { - confirmations.Remove(confirmation); - if (confirmations.Count == 0) { - return true; - } - } - - return await Bot.BotDatabase.MobileAuthenticator.HandleConfirmations(confirmations, accept).ConfigureAwait(false); + return true; } internal async Task AcceptDigitalGiftCards() { @@ -280,9 +289,7 @@ namespace ArchiSteamFarm { } if (Bot.HasMobileAuthenticator) { - // Give Steam network some time to generate confirmations - await Task.Delay(3000).ConfigureAwait(false); - if (!await AcceptConfirmations(true, Steam.ConfirmationDetails.EType.Trade, targetSteamID).ConfigureAwait(false)) { + if (!await AcceptConfirmations(true, Steam.ConfirmationDetails.EType.Trade, targetSteamID, waitIfNeeded: true).ConfigureAwait(false)) { return (false, Strings.BotLootingFailed); } } diff --git a/ArchiSteamFarm/Trading.cs b/ArchiSteamFarm/Trading.cs index 7eb463ab4..7b8202f5d 100644 --- a/ArchiSteamFarm/Trading.cs +++ b/ArchiSteamFarm/Trading.cs @@ -204,9 +204,7 @@ namespace ArchiSteamFarm { if (Bot.HasMobileAuthenticator) { HashSet acceptedWithItemLoseTradeIDs = results.Where(result => (result != null) && (result.Result == ParseTradeResult.EResult.AcceptedWithItemLose)).Select(result => result.TradeID).ToHashSet(); if (acceptedWithItemLoseTradeIDs.Count > 0) { - // Give Steam network some time to generate confirmations - await Task.Delay(3000).ConfigureAwait(false); - await Bot.Actions.AcceptConfirmations(true, Steam.ConfirmationDetails.EType.Trade, 0, acceptedWithItemLoseTradeIDs).ConfigureAwait(false); + await Bot.Actions.AcceptConfirmations(true, Steam.ConfirmationDetails.EType.Trade, 0, acceptedWithItemLoseTradeIDs, true).ConfigureAwait(false); } }