diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 6d8072ab8..2e2cbe025 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -80,6 +80,7 @@ namespace ArchiSteamFarm { private readonly ConcurrentHashSet HandledGifts = new ConcurrentHashSet(); private readonly Timer HeartBeatTimer; private readonly SemaphoreSlim InitializationSemaphore = new SemaphoreSlim(1); + private readonly SemaphoreSlim LootingSemaphore = new SemaphoreSlim(1); private readonly ConcurrentHashSet OwnedPackageIDs = new ConcurrentHashSet(); private readonly Statistics Statistics; @@ -2003,11 +2004,11 @@ namespace ArchiSteamFarm { return FormatBotResponse(Strings.BotNoASFAuthenticator); } - if (await AcceptConfirmations(confirm).ConfigureAwait(false)) { - return FormatBotResponse(Strings.Success); + if (!await AcceptConfirmations(confirm).ConfigureAwait(false)) { + return FormatBotResponse(Strings.WarningFailed); } - return FormatBotResponse(Strings.WarningFailed); + return FormatBotResponse(Strings.Success); } private static async Task Response2FAConfirm(ulong steamID, string botNames, bool confirm) { @@ -2497,21 +2498,35 @@ namespace ArchiSteamFarm { return FormatBotResponse(Strings.BotLootingYourself); } - HashSet inventory = await ArchiWebHandler.GetMySteamInventory(true, BotConfig.LootableTypes).ConfigureAwait(false); - if ((inventory == null) || (inventory.Count == 0)) { - return FormatBotResponse(string.Format(Strings.ErrorIsEmpty, nameof(inventory))); - } - - if (!await ArchiWebHandler.MarkSentTrades().ConfigureAwait(false)) { + if (!LootingSemaphore.Wait(0)) { return FormatBotResponse(Strings.BotLootingFailed); } - if (!await ArchiWebHandler.SendTradeOffer(inventory, targetSteamMasterID, BotConfig.SteamTradeToken).ConfigureAwait(false)) { - return FormatBotResponse(Strings.BotLootingFailed); + try { + HashSet inventory = await ArchiWebHandler.GetMySteamInventory(true, BotConfig.LootableTypes).ConfigureAwait(false); + if ((inventory == null) || (inventory.Count == 0)) { + return FormatBotResponse(string.Format(Strings.ErrorIsEmpty, nameof(inventory))); + } + + if (!await ArchiWebHandler.MarkSentTrades().ConfigureAwait(false)) { + return FormatBotResponse(Strings.BotLootingFailed); + } + + if (!await ArchiWebHandler.SendTradeOffer(inventory, targetSteamMasterID, BotConfig.SteamTradeToken).ConfigureAwait(false)) { + return FormatBotResponse(Strings.BotLootingFailed); + } + + if (HasMobileAuthenticator) { + // Give Steam network some time to generate confirmations + await Task.Delay(3000).ConfigureAwait(false); + if (!await AcceptConfirmations(true, Steam.ConfirmationDetails.EType.Trade, targetSteamMasterID).ConfigureAwait(false)) { + return FormatBotResponse(Strings.BotLootingFailed); + } + } + } finally { + LootingSemaphore.Release(); } - await Task.Delay(3000).ConfigureAwait(false); // Sometimes we can be too fast for Steam servers to generate confirmations, wait a short moment - await AcceptConfirmations(true, Steam.ConfirmationDetails.EType.Trade, targetSteamMasterID).ConfigureAwait(false); return FormatBotResponse(Strings.BotLootingSuccess); } diff --git a/ArchiSteamFarm/Trading.cs b/ArchiSteamFarm/Trading.cs index 88d98c3e8..1ea3b2971 100644 --- a/ArchiSteamFarm/Trading.cs +++ b/ArchiSteamFarm/Trading.cs @@ -104,7 +104,8 @@ namespace ArchiSteamFarm { if (Bot.HasMobileAuthenticator) { HashSet acceptedWithItemLoseTradeIDs = new HashSet(results.Where(result => (result != null) && (result.Result == ParseTradeResult.EResult.AcceptedWithItemLose)).Select(result => result.TradeID)); if (acceptedWithItemLoseTradeIDs.Count > 0) { - await Task.Delay(3000).ConfigureAwait(false); // Sometimes we can be too fast for Steam servers to generate confirmations, wait a short moment + // Give Steam network some time to generate confirmations + await Task.Delay(3000).ConfigureAwait(false); await Bot.AcceptConfirmations(true, Steam.ConfirmationDetails.EType.Trade, 0, acceptedWithItemLoseTradeIDs).ConfigureAwait(false); } }