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.
This commit is contained in:
Archi
2023-01-17 19:19:27 +01:00
parent 5049f82dad
commit 27639b32d5

View File

@@ -655,7 +655,7 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable {
return;
}
bool hasWorkingAuthenticator = false;
HashSet<ulong> pendingMobileTradeOfferIDs = new();
byte maxTradeHoldDuration = ASF.GlobalConfig?.MaxTradeHoldDuration ?? GlobalConfig.DefaultMaxTradeHoldDuration;
@@ -836,21 +836,7 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable {
(bool success, HashSet<ulong>? 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));
}
}