From d36eaebbfe47fa77d091c138705b3f31533cf576 Mon Sep 17 00:00:00 2001 From: JustArchi Date: Sun, 25 Dec 2016 05:52:17 +0100 Subject: [PATCH] Closes #383 --- ArchiSteamFarm/ArchiWebHandler.cs | 13 +++++- ArchiSteamFarm/Bot.cs | 9 +--- ArchiSteamFarm/BotConfig.cs | 4 ++ ArchiSteamFarm/JSON/Steam.cs | 8 ++-- ArchiSteamFarm/Trading.cs | 2 +- ArchiSteamFarm/config/example.json | 57 +++++++++++++------------- ConfigGenerator/BotConfig.cs | 4 ++ ConfigGenerator/ConfigGenerator.csproj | 1 + ConfigGenerator/JSON/Steam.cs | 20 +++++++++ 9 files changed, 74 insertions(+), 44 deletions(-) create mode 100644 ConfigGenerator/JSON/Steam.cs diff --git a/ArchiSteamFarm/ArchiWebHandler.cs b/ArchiSteamFarm/ArchiWebHandler.cs index 307cf0d01..3695d6d7d 100644 --- a/ArchiSteamFarm/ArchiWebHandler.cs +++ b/ArchiSteamFarm/ArchiWebHandler.cs @@ -40,10 +40,10 @@ using Formatting = Newtonsoft.Json.Formatting; namespace ArchiSteamFarm { internal sealed class ArchiWebHandler : IDisposable { private const byte MinSessionTTL = GlobalConfig.DefaultHttpTimeout / 4; // Assume session is valid for at least that amount of seconds + private const string SteamCommunityHost = "steamcommunity.com"; // We must use HTTPS for SteamCommunity, as http would make certain POST requests failing (trades) private const string SteamCommunityURL = "https://" + SteamCommunityHost; - private const string SteamCommunityHost = "steamcommunity.com"; // We could (and should) use HTTPS for SteamStore, but that would make certain POST requests failing private const string SteamStoreHost = "store.steampowered.com"; @@ -417,7 +417,12 @@ namespace ArchiSteamFarm { return await WebBrowser.UrlGetToHtmlDocumentRetry(request).ConfigureAwait(false); } - internal async Task> GetMySteamInventory(bool tradable) { + internal async Task> GetMySteamInventory(bool tradable, HashSet wantedTypes) { + if ((wantedTypes == null) || (wantedTypes.Count == 0)) { + Bot.ArchiLogger.LogNullError(nameof(wantedTypes)); + return null; + } + if (!await RefreshSessionIfNeeded().ConfigureAwait(false)) { return null; } @@ -513,6 +518,10 @@ namespace ArchiSteamFarm { steamItem.Type = description.Item2; } + if (!wantedTypes.Contains(steamItem.Type)) { + continue; + } + result.Add(steamItem); } diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index df8413004..c294dcddb 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -1739,18 +1739,11 @@ namespace ArchiSteamFarm { await Trading.LimitInventoryRequestsAsync().ConfigureAwait(false); - HashSet inventory = await ArchiWebHandler.GetMySteamInventory(true).ConfigureAwait(false); + HashSet inventory = await ArchiWebHandler.GetMySteamInventory(true, BotConfig.LootableTypes).ConfigureAwait(false); if ((inventory == null) || (inventory.Count == 0)) { return "Nothing to send, inventory seems empty!"; } - // Remove from our pending inventory all items that are not steam cards and boosters - if (inventory.RemoveWhere(item => (item.Type != Steam.Item.EType.TradingCard) && ((item.Type != Steam.Item.EType.FoilTradingCard) || !BotConfig.IsBotAccount) && (item.Type != Steam.Item.EType.BoosterPack)) > 0) { - if (inventory.Count == 0) { - return "Nothing to send, inventory seems empty!"; - } - } - if (!await ArchiWebHandler.SendTradeOffer(inventory, BotConfig.SteamMasterID, BotConfig.SteamTradeToken).ConfigureAwait(false)) { return "Trade offer failed due to error!"; } diff --git a/ArchiSteamFarm/BotConfig.cs b/ArchiSteamFarm/BotConfig.cs index d66b46f4f..f13a23b57 100644 --- a/ArchiSteamFarm/BotConfig.cs +++ b/ArchiSteamFarm/BotConfig.cs @@ -27,6 +27,7 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; +using ArchiSteamFarm.JSON; using Newtonsoft.Json; namespace ArchiSteamFarm { @@ -77,6 +78,9 @@ namespace ArchiSteamFarm { [JsonProperty(Required = Required.DisallowNull)] internal readonly bool IsBotAccount = false; + [JsonProperty(Required = Required.DisallowNull)] + internal readonly HashSet LootableTypes = new HashSet { Steam.Item.EType.BoosterPack, Steam.Item.EType.FoilTradingCard, Steam.Item.EType.TradingCard }; + [JsonProperty(Required = Required.DisallowNull)] internal readonly CryptoHelper.ECryptoMethod PasswordFormat = CryptoHelper.ECryptoMethod.PlainText; diff --git a/ArchiSteamFarm/JSON/Steam.cs b/ArchiSteamFarm/JSON/Steam.cs index 9d61924b5..bf781bc34 100644 --- a/ArchiSteamFarm/JSON/Steam.cs +++ b/ArchiSteamFarm/JSON/Steam.cs @@ -359,16 +359,14 @@ namespace ArchiSteamFarm.JSON { internal enum EType : byte { Unknown, - BoosterPack, Coupon, - Gift, - SteamGems, - Emoticon, + Gift, FoilTradingCard, ProfileBackground, - TradingCard + TradingCard, + SteamGems } } diff --git a/ArchiSteamFarm/Trading.cs b/ArchiSteamFarm/Trading.cs index 2e6320d34..f491fe4fb 100644 --- a/ArchiSteamFarm/Trading.cs +++ b/ArchiSteamFarm/Trading.cs @@ -230,7 +230,7 @@ namespace ArchiSteamFarm { // Now check if it's worth for us to do the trade await LimitInventoryRequestsAsync().ConfigureAwait(false); - HashSet inventory = await Bot.ArchiWebHandler.GetMySteamInventory(false).ConfigureAwait(false); + HashSet inventory = await Bot.ArchiWebHandler.GetMySteamInventory(false, new HashSet { Steam.Item.EType.TradingCard }).ConfigureAwait(false); if ((inventory == null) || (inventory.Count == 0)) { return new ParseTradeResult(tradeOffer.TradeOfferID, ParseTradeResult.EResult.AcceptedWithItemLose); // OK, assume that this trade is valid, we can't check our EQ } diff --git a/ArchiSteamFarm/config/example.json b/ArchiSteamFarm/config/example.json index 63617b797..c937237f9 100644 --- a/ArchiSteamFarm/config/example.json +++ b/ArchiSteamFarm/config/example.json @@ -1,29 +1,30 @@ { - "Enabled": false, - "Paused": false, - "SteamLogin": null, - "SteamPassword": null, - "PasswordFormat": 0, - "SteamParentalPIN": "0", - "SteamApiKey": null, - "SteamMasterID": 0, - "SteamMasterClanID": 0, - "CardDropsRestricted": true, - "DismissInventoryNotifications": true, - "FarmingOrder": 0, - "FarmOffline": false, - "HandleOfflineMessages": false, - "AcceptGifts": false, - "IsBotAccount": false, - "ForwardKeysToOtherBots": false, - "DistributeKeys": false, - "ShutdownOnFarmingFinished": false, - "SendOnFarmingFinished": false, - "SteamTradeToken": null, - "SendTradePeriod": 0, - "TradingPreferences": 1, - "AcceptConfirmationsPeriod": 0, - "CustomGamePlayedWhileFarming": null, - "CustomGamePlayedWhileIdle": null, - "GamesPlayedWhileIdle": [] -} \ No newline at end of file + "AcceptConfirmationsPeriod" : 0, + "AcceptGifts" : false, + "CardDropsRestricted" : true, + "CustomGamePlayedWhileFarming" : null, + "CustomGamePlayedWhileIdle" : null, + "DismissInventoryNotifications" : true, + "DistributeKeys" : false, + "Enabled" : false, + "FarmOffline" : false, + "FarmingOrder" : 0, + "ForwardKeysToOtherBots" : false, + "GamesPlayedWhileIdle" : [], + "HandleOfflineMessages" : false, + "IsBotAccount" : false, + "LootableTypes" : [ 1, 5, 7 ], + "PasswordFormat" : 0, + "Paused" : false, + "SendOnFarmingFinished" : false, + "SendTradePeriod" : 0, + "ShutdownOnFarmingFinished" : false, + "SteamApiKey" : null, + "SteamLogin" : null, + "SteamMasterClanID" : 0, + "SteamMasterID" : 0, + "SteamParentalPIN" : "0", + "SteamPassword" : null, + "SteamTradeToken" : null, + "TradingPreferences" : 1 +} diff --git a/ConfigGenerator/BotConfig.cs b/ConfigGenerator/BotConfig.cs index f71014f40..d4e6456e5 100644 --- a/ConfigGenerator/BotConfig.cs +++ b/ConfigGenerator/BotConfig.cs @@ -28,6 +28,7 @@ using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Drawing.Design; using System.IO; +using ConfigGenerator.JSON; using Newtonsoft.Json; namespace ConfigGenerator { @@ -83,6 +84,9 @@ namespace ConfigGenerator { [JsonProperty(Required = Required.DisallowNull)] public bool IsBotAccount { get; set; } = false; + [JsonProperty(Required = Required.DisallowNull)] + public List LootableTypes = new List { Steam.Item.EType.BoosterPack, Steam.Item.EType.FoilTradingCard, Steam.Item.EType.TradingCard }; + [Category("\tAccess")] [JsonProperty(Required = Required.DisallowNull)] public ECryptoMethod PasswordFormat { get; set; } = ECryptoMethod.PlainText; diff --git a/ConfigGenerator/ConfigGenerator.csproj b/ConfigGenerator/ConfigGenerator.csproj index b79d403af..6b1f71647 100644 --- a/ConfigGenerator/ConfigGenerator.csproj +++ b/ConfigGenerator/ConfigGenerator.csproj @@ -73,6 +73,7 @@ Component + Form diff --git a/ConfigGenerator/JSON/Steam.cs b/ConfigGenerator/JSON/Steam.cs new file mode 100644 index 000000000..75b282291 --- /dev/null +++ b/ConfigGenerator/JSON/Steam.cs @@ -0,0 +1,20 @@ +using System.Diagnostics.CodeAnalysis; + +namespace ConfigGenerator.JSON { + internal static class Steam { + internal static class Item { + [SuppressMessage("ReSharper", "UnusedMember.Global")] + internal enum EType : byte { + Unknown, + BoosterPack, + Coupon, + Emoticon, + Gift, + FoilTradingCard, + ProfileBackground, + TradingCard, + SteamGems + } + } + } +}