From 27639b32d554536938c2d9754a10d02ea8d4faa6 Mon Sep 17 00:00:00 2001 From: Archi Date: Tue, 17 Jan 2023 19:19:27 +0100 Subject: [PATCH] Accept all confirmations from ItemsMatcher at once Previously we accepted those after each trade, because the overhead of loading other inventory was too big to leave those pending. Since we have all possible matches at once now, it makes sense to firstly schedule all trade offers, and then just confirm them all at once, especially since confirmations endpoint is horrific and very often problematic, on top of having 10-seconds rate-limiting. --- .../RemoteCommunication.cs | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs index de1cd062f..a00d8cc12 100644 --- a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs +++ b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs @@ -655,7 +655,7 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { return; } - bool hasWorkingAuthenticator = false; + HashSet pendingMobileTradeOfferIDs = new(); byte maxTradeHoldDuration = ASF.GlobalConfig?.MaxTradeHoldDuration ?? GlobalConfig.DefaultMaxTradeHoldDuration; @@ -836,21 +836,7 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { (bool success, HashSet? mobileTradeOfferIDs) = await Bot.ArchiWebHandler.SendTradeOffer(listedUser.SteamID, itemsToGive, itemsToReceive, listedUser.TradeToken, true).ConfigureAwait(false); if (mobileTradeOfferIDs?.Count > 0) { - (bool twoFactorSuccess, _, _) = await Bot.Actions.HandleTwoFactorAuthenticationConfirmations(true, Confirmation.EType.Trade, mobileTradeOfferIDs, true).ConfigureAwait(false); - - if (!twoFactorSuccess) { - Bot.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, nameof(twoFactorSuccess))); - - if (hasWorkingAuthenticator) { - // We can assume this to be just a temporary Steam issue, and we may try to continue the matching with other users - break; - } - - // User didn't confirm even one single trade, naturally this could be just a coincidence, but it's more likely that his ASF 2FA credentials are invalid and this is why we'll refuse to continue for now - return; - } - - hasWorkingAuthenticator = true; + pendingMobileTradeOfferIDs.UnionWith(mobileTradeOfferIDs); } if (!success) { @@ -934,6 +920,16 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { } } + if (pendingMobileTradeOfferIDs.Count > 0) { + (bool twoFactorSuccess, _, _) = await Bot.Actions.HandleTwoFactorAuthenticationConfirmations(true, Confirmation.EType.Trade, pendingMobileTradeOfferIDs, true).ConfigureAwait(false); + + if (!twoFactorSuccess) { + Bot.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, nameof(twoFactorSuccess))); + + return; + } + } + Bot.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, Localization.Strings.ActivelyMatchingItemsRound, matchedSets)); } }