示例#1
0
        /// <summary>
        /// Fetches the inventory for the given Steam ID using the Steam API.
        /// </summary>
        /// <returns>The give users inventory.</returns>
        /// <param name='steamId'>Steam identifier.</param>
        /// <param name='apiKey'>The needed Steam API key.</param>
        /// <param name="steamWeb">The SteamWeb instance for this Bot</param>
        public static Inventory FetchInventory(ulong steamId, string apiKey, SteamWeb steamWeb)
        {
            int attempts             = 1;
            InventoryResponse result = null;

            while ((result == null || result.result.items == null) && attempts <= 3)
            {
                var    url      = "https://api.steampowered.com/IEconItems_570/GetPlayerItems/v0001/?key=" + apiKey + "&steamid=" + steamId;
                string response = steamWeb.Fetch(url, "GET", null, false);
                result = JsonConvert.DeserializeObject <InventoryResponse>(response);
                attempts++;
            }
            return(new Inventory(result.result));
        }
示例#2
0
        /// <summary>
        /// Gets the inventory for the given Steam ID using the Steam Community website.
        /// </summary>
        /// <returns>The inventory for the given user. </returns>
        /// <param name='steamid'>The Steam identifier. </param>
        /// <param name="steamWeb">The SteamWeb instance for this Bot</param>
        public static dynamic GetInventory(SteamID steamid, SteamWeb steamWeb)
        {
            string url = String.Format(
                "http://steamcommunity.com/profiles/{0}/inventory/json/570/2/?trading=1",
                steamid.ConvertToUInt64()
                );

            try
            {
                string response = steamWeb.Fetch(url, "GET");
                return(JsonConvert.DeserializeObject(response));
            }
            catch (Exception)
            {
                return(JsonConvert.DeserializeObject("{\"success\":\"false\"}"));
            }
        }
示例#3
0
        public void loadImplementation(int appid, IEnumerable <long> contextIds, SteamID steamid)
        {
            dynamic invResponse;

            isLoaded = false;
            Dictionary <string, string> tmpAppData;

            _items.Clear();
            _descriptions.Clear();
            _errors.Clear();

            try
            {
                foreach (long contextId in contextIds)
                {
                    string response = SteamWeb.Fetch(string.Format("http://steamcommunity.com/profiles/{0}/inventory/json/{1}/{2}/", steamid.ConvertToUInt64(), appid, contextId), "GET", null, true);
                    invResponse = JsonConvert.DeserializeObject(response);

                    if (invResponse.success == false)
                    {
                        _errors.Add("Fail to open backpack: " + invResponse.Error);
                        continue;
                    }

                    //rgInventory = Items on Steam Inventory
                    foreach (var item in invResponse.rgInventory)
                    {
                        foreach (var itemId in item)
                        {
                            string descriptionid = itemId.classid + "_" + itemId.instanceid;
                            _items.Add((ulong)itemId.id, new Item(appid, contextId, (ulong)itemId.id, descriptionid));
                            break;
                        }
                    }

                    // rgDescriptions = Item Schema (sort of)
                    foreach (var description in invResponse.rgDescriptions)
                    {
                        foreach (var class_instance in description)// classid + '_' + instenceid
                        {
                            if (class_instance.app_data != null)
                            {
                                tmpAppData = new Dictionary <string, string>();
                                foreach (var value in class_instance.app_data)
                                {
                                    tmpAppData.Add("" + value.Name, "" + value.Value);
                                }
                            }
                            else
                            {
                                tmpAppData = null;
                            }

                            _descriptions.Add("" + (class_instance.classid ?? '0') + "_" + (class_instance.instanceid ?? '0'),
                                              new ItemDescription()
                            {
                                name       = class_instance.name,
                                type       = class_instance.type,
                                marketable = (bool)class_instance.marketable,
                                tradable   = (bool)class_instance.tradable,
                                classid    = long.Parse((string)class_instance.classid),
                                url        = (class_instance.actions != null && class_instance.actions.First["link"] != null ? class_instance.actions.First["link"] : ""),
                                app_data   = tmpAppData
                            }
                                              );
                            break;
                        }
                    }
                } //end for (contextId)
            }     //end try
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                _errors.Add("Exception: " + e.Message);
            }
            isLoaded = true;
        }