private static bool ParseItems(Dictionary <ulong, Tuple <uint, Steam.Item.EType> > descriptions, List <KeyValue> input, HashSet <Steam.Item> output) { if ((descriptions == null) || (input == null) || (input.Count == 0) || (output == null)) { Logging.LogNullError(nameof(descriptions) + " || " + nameof(input) + " || " + nameof(output)); return(false); } foreach (KeyValue item in input) { uint appID = item["appid"].AsUnsignedInteger(); if (appID == 0) { Logging.LogNullError(nameof(appID)); return(false); } ulong contextID = item["contextid"].AsUnsignedLong(); if (contextID == 0) { Logging.LogNullError(nameof(contextID)); return(false); } ulong classID = item["classid"].AsUnsignedLong(); if (classID == 0) { Logging.LogNullError(nameof(classID)); return(false); } uint amount = item["amount"].AsUnsignedInteger(); if (amount == 0) { Logging.LogNullError(nameof(amount)); return(false); } uint realAppID = 0; Steam.Item.EType type = Steam.Item.EType.Unknown; Tuple <uint, Steam.Item.EType> description; if (descriptions.TryGetValue(classID, out description)) { realAppID = description.Item1; type = description.Item2; } Steam.Item steamItem = new Steam.Item(appID, contextID, classID, amount, realAppID, type); output.Add(steamItem); } return(true); }
internal async Task <bool> SendTradeOffer(List <Steam.Item> inventory, ulong partnerID, string token = null) { if (inventory == null || inventory.Count == 0 || partnerID == 0) { return(false); } string sessionID; if (!Cookie.TryGetValue("sessionid", out sessionID)) { return(false); } List <Steam.TradeOfferRequest> trades = new List <Steam.TradeOfferRequest>(1 + inventory.Count / Trading.MaxItemsPerTrade); Steam.TradeOfferRequest singleTrade = null; for (ushort i = 0; i < inventory.Count; i++) { if (i % Trading.MaxItemsPerTrade == 0) { if (trades.Count >= Trading.MaxTradesPerAccount) { break; } singleTrade = new Steam.TradeOfferRequest(); trades.Add(singleTrade); } Steam.Item item = inventory[i]; singleTrade.me.assets.Add(new Steam.Item() { appid = "753", contextid = "6", amount = item.amount, assetid = item.id }); } string referer = SteamCommunityURL + "/tradeoffer/new"; string request = referer + "/send"; foreach (Steam.TradeOfferRequest trade in trades) { Dictionary <string, string> data = new Dictionary <string, string>(6) { { "sessionid", sessionID }, { "serverid", "1" }, { "partner", partnerID.ToString() }, { "tradeoffermessage", "Sent by ASF" }, { "json_tradeoffer", JsonConvert.SerializeObject(trade) }, { "trade_offer_create_params", string.IsNullOrEmpty(token) ? "" : $"{{\"trade_offer_access_token\":\"{token}\"}}" } }; HttpResponseMessage response = null; for (byte i = 0; i < WebBrowser.MaxRetries && response == null; i++) { response = await WebBrowser.UrlPost(request, data, Cookie, referer).ConfigureAwait(false); } if (response == null) { Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName); return(false); } } return(true); }
internal HashSet <Steam.TradeOffer> GetTradeOffers() { if (string.IsNullOrEmpty(Bot.BotConfig.SteamApiKey)) { return(null); } KeyValue response = null; using (dynamic iEconService = WebAPI.GetInterface("IEconService", Bot.BotConfig.SteamApiKey)) { iEconService.Timeout = Timeout; for (byte i = 0; (i < WebBrowser.MaxRetries) && (response == null); i++) { try { response = iEconService.GetTradeOffers( get_received_offers: 1, active_only: 1, get_descriptions: 1, secure: !Program.GlobalConfig.ForceHttp ); } catch (Exception e) { Logging.LogGenericException(e, Bot.BotName); } } } if (response == null) { Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName); return(null); } Dictionary <Tuple <ulong, ulong>, Tuple <uint, Steam.Item.EType> > descriptions = new Dictionary <Tuple <ulong, ulong>, Tuple <uint, Steam.Item.EType> >(); foreach (KeyValue description in response["descriptions"].Children) { ulong classID = description["classid"].AsUnsignedLong(); if (classID == 0) { continue; } ulong instanceID = description["instanceid"].AsUnsignedLong(); Tuple <ulong, ulong> key = new Tuple <ulong, ulong>(classID, instanceID); if (descriptions.ContainsKey(key)) { continue; } uint appID = 0; Steam.Item.EType type = Steam.Item.EType.Unknown; string hashName = description["market_hash_name"].Value; if (!string.IsNullOrEmpty(hashName)) { appID = GetAppIDFromMarketHashName(hashName); } string descriptionType = description["type"].Value; if (!string.IsNullOrEmpty(descriptionType)) { type = GetItemType(descriptionType); } descriptions[key] = new Tuple <uint, Steam.Item.EType>(appID, type); } HashSet <Steam.TradeOffer> result = new HashSet <Steam.TradeOffer>(); foreach (KeyValue trade in response["trade_offers_received"].Children) { Steam.TradeOffer tradeOffer = new Steam.TradeOffer { TradeOfferID = trade["tradeofferid"].AsUnsignedLong(), OtherSteamID3 = (uint)trade["accountid_other"].AsUnsignedLong(), State = trade["trade_offer_state"].AsEnum <Steam.TradeOffer.ETradeOfferState>() }; foreach (KeyValue item in trade["items_to_give"].Children) { Steam.Item steamItem = new Steam.Item { AppID = (uint)item["appid"].AsUnsignedLong(), ContextID = item["contextid"].AsUnsignedLong(), AssetID = item["assetid"].AsUnsignedLong(), ClassID = item["classid"].AsUnsignedLong(), InstanceID = item["instanceid"].AsUnsignedLong(), Amount = (uint)item["amount"].AsUnsignedLong() }; Tuple <ulong, ulong> key = new Tuple <ulong, ulong>(steamItem.ClassID, steamItem.InstanceID); Tuple <uint, Steam.Item.EType> description; if (descriptions.TryGetValue(key, out description)) { steamItem.RealAppID = description.Item1; steamItem.Type = description.Item2; } tradeOffer.ItemsToGive.Add(steamItem); } foreach (KeyValue item in trade["items_to_receive"].Children) { Steam.Item steamItem = new Steam.Item { AppID = (uint)item["appid"].AsUnsignedLong(), ContextID = item["contextid"].AsUnsignedLong(), AssetID = item["assetid"].AsUnsignedLong(), ClassID = item["classid"].AsUnsignedLong(), InstanceID = item["instanceid"].AsUnsignedLong(), Amount = (uint)item["amount"].AsUnsignedLong() }; Tuple <ulong, ulong> key = new Tuple <ulong, ulong>(steamItem.ClassID, steamItem.InstanceID); Tuple <uint, Steam.Item.EType> description; if (descriptions.TryGetValue(key, out description)) { steamItem.RealAppID = description.Item1; steamItem.Type = description.Item2; } tradeOffer.ItemsToReceive.Add(steamItem); } result.Add(tradeOffer); } return(result); }