示例#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)
 {
     var url = "http://api.steampowered.com/IEconItems_440/GetPlayerItems/v0001/?key=" + apiKey + "&steamid=" + steamId;
     string response = steamWeb.Fetch (url, "GET", null, false);
     InventoryResponse result = JsonConvert.DeserializeObject<InventoryResponse>(response);
     return new Inventory(result.result);
 }
示例#2
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>
 public static Inventory FetchInventory (ulong steamId, string apiKey)
 {
     var url = "http://api.steampowered.com/IEconItems_440/GetPlayerItems/v0001/?key=" + apiKey + "&steamid=" + steamId;
     string response = SteamWeb.Fetch (url, "GET", null, null, false);
     InventoryResponse result = JsonConvert.DeserializeObject<InventoryResponse>(response);
     return new Inventory(result.result);
 }
示例#3
0
文件: Schema.cs 项目: sixty/SteamBot
        public static Schema FetchSchema(string apiKey)
        {
            var url = "http://api.steampowered.com/IEconItems_440/GetSchema/v0001/?key=" + apiKey;

            string result = SteamWeb.Fetch(url, "GET");

            SchemaResult schemaResult = JsonConvert.DeserializeObject <SchemaResult> (result);

            return(schemaResult.result ?? null);
        }
示例#4
0
        private SteamID GetSelfId()
        {
            var html  = web.Fetch(@"https://steamcommunity.com/", "get");
            var temp  = html.Split(new[] { "data-miniprofile" }, StringSplitOptions.None)[0];
            var temp2 = temp.Split(new[] { "href=" }, StringSplitOptions.None);
            var id    = temp2[temp2.Length - 1].Replace("\"", "");

            if (id.Contains("/id/"))
            {
                string profileVanity = id.Split(new[] { "id/" }, StringSplitOptions.None)[1].Split('/')[0];
                var    xml           = web.Fetch($@"http://steamcommunity.com/id/{profileVanity}/?xml=1", "get");

                string profile64 = xml.Split(new[] { "<steamID64>" }, StringSplitOptions.None)[1].Split(new[] { "</steamID64>" }, StringSplitOptions.None)[0];
                return(new SteamID(ulong.Parse(profile64)));
            }
            else
            {
                string profile64 = id.Split(new[] { "profiles/" }, StringSplitOptions.None)[1].Split('/')[0];
                return(new SteamID(ulong.Parse(profile64)));
            }
        }
示例#5
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, Action <string> chatMessage)
        {
            int attempts             = 1;
            InventoryResponse result = null;

            while (result == null || result.result?.items == null)
            {
                try
                {
                    var    url      = "http://api.steampowered.com/IEconItems_440/GetPlayerItems/v0001/?key=" + apiKey + "&steamid=" + steamId;
                    string response = steamWeb.Fetch(url, "GET", null, false);
                    result = JsonConvert.DeserializeObject <InventoryResponse>(response);
                }
                catch (WebException e)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("ERROR IN INVENTORY.FETCHINVENTORY: " + e.ToString());
                    Console.ForegroundColor = ConsoleColor.White;
                    result = null;

                    Thread.Sleep(500);
                }

                attempts++;

                if (attempts == 4)
                {
                    attempts = 0;

                    if (_failedFetch)
                    {
                        //Console.ForegroundColor = ConsoleColor.Red;
                        //Console.WriteLine("Fetch Failing already. Aborting.");
                        //Thread.CurrentThread.Abort();
                    }

                    if (chatMessage != null)
                    {
                        _failedFetch            = true;
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Unable to fetch inventory of user #{0}. Giving up.", steamId.ToString());
                        Console.ForegroundColor = ConsoleColor.White;
                        //chatMessage("I am currently encountering issues connecting to Steam. Please try again in a few minutes.");

                        return(null);
                    }
                }
            }

            return(new Inventory(result.result));
        }
示例#6
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, Action<string> chatMessage)
        {
            int attempts = 1;
            InventoryResponse result = null;
            while (result == null || result.result?.items == null)
            {
                try
                {
                    var url = "http://api.steampowered.com/IEconItems_440/GetPlayerItems/v0001/?key=" + apiKey + "&steamid=" + steamId;
                    string response = steamWeb.Fetch(url, "GET", null, false);
                    result = JsonConvert.DeserializeObject<InventoryResponse>(response);
                }
                catch (WebException e)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("ERROR IN INVENTORY.FETCHINVENTORY: " + e.ToString());
                    Console.ForegroundColor = ConsoleColor.White;
                    result = null;

                    Thread.Sleep(500);
                }

                attempts++;

                if (attempts == 4)
                {
                    attempts = 0;

                    if (_failedFetch)
                    {
                        //Console.ForegroundColor = ConsoleColor.Red;
                        //Console.WriteLine("Fetch Failing already. Aborting.");
                        //Thread.CurrentThread.Abort();
                    }

                    if (chatMessage != null)
                    {
                        _failedFetch = true;
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Unable to fetch inventory of user #{0}. Giving up.", steamId.ToString());
                        Console.ForegroundColor = ConsoleColor.White;
                        //chatMessage("I am currently encountering issues connecting to Steam. Please try again in a few minutes.");

                        return null;
                    }
                }
            }

            return new Inventory(result.result);
        }
示例#7
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      = "http://api.steampowered.com/IEconItems_440/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));
        }
示例#8
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>
        public static dynamic GetInventory(SteamID steamid)
        {
            string url = String.Format(
                "http://steamcommunity.com/profiles/{0}/inventory/json/440/2/?trading=1",
                steamid.ConvertToUInt64()
                );

            try
            {
                string response = SteamWeb.Fetch(url, "GET", null, null, true);
                return(JsonConvert.DeserializeObject(response));
            }
            catch (Exception)
            {
                return(JsonConvert.DeserializeObject("{\"success\":\"false\"}"));
            }
        }
 /// <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/440/2/?trading=1",
         steamid.ConvertToUInt64 ()
     );
     
     try
     {
         string response = steamWeb.Fetch (url, "GET");
         return JsonConvert.DeserializeObject (response);
     }
     catch (Exception)
     {
         return JsonConvert.DeserializeObject ("{\"success\":\"false\"}");
     }
 }
示例#10
0
        /// <summary>
        /// Loads the inventory
        /// </summary>
        /// <param name="steamid">Steamid64 of user</param>
        /// <param name="appid">Steam app id</param>
        /// <param name="contextid">Inventory context id</param>
        /// <returns>Returns true if successful</returns>
        public bool Load(ulong steamid, int appid, long contextid)
        {
            Items.Clear();
            Errors.Clear();

            try
            {
                string  response    = mSteamWeb.Fetch($"http://steamcommunity.com/profiles/{steamid}/inventory/json/{appid}/{contextid}/", "GET", null, true);
                dynamic invResponse = JsonConvert.DeserializeObject(response);

                if (invResponse.success == false)
                {
                    Errors.Add($"Unable to load inventory: {invResponse?.Error}");
                    return(false);
                }

                foreach (var item in invResponse.rgInventory)
                {
                    foreach (var info in item)
                    {
                        Items.Add(new InventoryItem()
                        {
                            assetId = (long)info.id,
                            classId = (long)info.classid,
                            amount  = (int)info.amount,
                            pos     = (int)info.pos
                        });
                    }
                }

                return(true);
            }
            catch (WebException ex)
            {
                Errors.Add($"Web exception: {ex.Message}");
            }
            catch (Exception ex)
            {
                Errors.Add($"Exception: {ex.Message}");
            }

            return(false);
        }
示例#11
0
        /// <summary>
        /// Calls the given function multiple times, until we get a non-null/non-false/non-zero result, or we've made at least
        /// WEB_REQUEST_MAX_RETRIES attempts (with WEB_REQUEST_TIME_BETWEEN_RETRIES_MS between attempts)
        /// </summary>
        /// <returns>The result of the function if it succeeded, or an empty string otherwise</returns>
        private string RetryWebRequest(string url, SteamID botId)
        {
            for (int i = 0; i < WEB_REQUEST_MAX_RETRIES; i++)
            {
                try
                {
                    return(SteamWeb.Fetch(url, "GET", null, Cookies[botId]));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }

                if (i != WEB_REQUEST_MAX_RETRIES)
                {
                    System.Threading.Thread.Sleep(WEB_REQUEST_TIME_BETWEEN_RETRIES_MS);
                }
            }
            return("");
        }
示例#12
0
        public void loadImplementation(int appid, IEnumerable <long> contextIds, SteamID steamid, string language = "english")
        {
            dynamic invResponse;

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

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

            try
            {
                foreach (long contextId in contextIds)
                {
                    string moreStart = null;
                    do
                    {
                        var data = String.IsNullOrEmpty(moreStart) ? null : new NameValueCollection {
                            { "start", moreStart }
                        };
                        string response = SteamWeb.Fetch(
                            String.Format("https://steamcommunity.com/profiles/{0}/inventory/json/{1}/{2}/?l={3}", steamid.ConvertToUInt64(), appid, contextId, language),
                            "GET", data);
                        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)
                            {
                                ulong id = (ulong)itemId.id;
                                if (!_items.ContainsKey(id))
                                {
                                    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
                            {
                                string key = "" + (class_instance.classid ?? '0') + "_" + (class_instance.instanceid ?? '0');
                                if (!_descriptions.ContainsKey(key))
                                {
                                    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(key,
                                                      new ItemDescription()
                                    {
                                        name             = class_instance.name,
                                        market_hash_name = class_instance.market_hash_name,
                                        type             = class_instance.type,
                                        marketable       = (bool)class_instance.marketable,
                                        tradable         = (bool)class_instance.tradable,
                                        classid          = String.IsNullOrEmpty((string)class_instance.classid) ? -1 : 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,
                                        market_fee_app_id = (class_instance.market_fee_app != null ? class_instance.market_fee_app : 0),
                                    }
                                                      );
                                    break;
                                }
                            }
                        }

                        try
                        {
                            moreStart = invResponse.more_start;
                        }
                        catch (Exception e)
                        {
                            moreStart = null;
                        }
                    } while (!String.IsNullOrEmpty(moreStart) && moreStart.ToLower() != "false" && moreStart != "0");
                } //end for (contextId)
            }     //end try
            catch (Exception e)
            {
                Console.WriteLine(e);
                _errors.Add("Exception: " + e.Message);
            }
            isLoaded = true;
        }
示例#13
0
 string Fetch(string url, string method, NameValueCollection data = null)
 {
     return(SteamWeb.Fetch(url, method, data, cookies));
 }
示例#14
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, 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)
                        {
                            _items.Add((ulong)itemId.id, new Item()
                            {
                                appid         = appid,
                                contextid     = contextId,
                                assetid       = itemId.id,
                                descriptionid = itemId.classid + "_" + itemId.instanceid
                            });
                            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,
                                app_data   = tmpAppData
                            }
                                              );
                            break;
                        }
                    }
                } //end for (contextId)
            }     //end try
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                _errors.Add("Exception: " + e.Message);
            }
            isLoaded = true;
        }
示例#15
0
        public bool load(ulong appid, List <uint> types, SteamID steamid)
        {
            dynamic         invResponse;
            Item            tmpItemData;
            ItemDescription tmpDescription;

            loaded = false;

            try
            {
                for (int i = 0; i < types.Count; i++)
                {
                    string response = SteamWeb.Fetch(string.Format("http://steamcommunity.com/profiles/{0}/inventory/json/{1}/{2}/?trading=1", steamid.ConvertToUInt64(), appid, types[i]), "GET", null, null, true);

                    invResponse = JsonConvert.DeserializeObject(response);

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

                    //rgInventory = Items on Steam Inventory
                    foreach (var item in invResponse.rgInventory)
                    {
                        foreach (var itemId in item)
                        {
                            tmpItemData         = new Item();
                            tmpItemData.id      = itemId.id;
                            tmpItemData.classid = itemId.classid;

                            items.Add((ulong)itemId.id, tmpItemData);
                            break;
                        }
                    }

                    // rgDescriptions = Item Schema (sort of)
                    foreach (var description in invResponse.rgDescriptions)
                    {
                        foreach (var classid_instanceid in description)// classid + '_' + instenceid
                        {
                            tmpDescription            = new ItemDescription();
                            tmpDescription.name       = classid_instanceid.name;
                            tmpDescription.type       = classid_instanceid.type;
                            tmpDescription.marketable = (bool)classid_instanceid.marketable;
                            tmpDescription.tradable   = (bool)classid_instanceid.marketable;

                            tmpDescription.metadata = classid_instanceid.descriptions;

                            descriptions.Add((ulong)classid_instanceid.classid, tmpDescription);
                            break;
                        }
                    }
                } //end for (inventory type)
            }     //end try
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                errors.Add("Exception: " + e.Message);
                return(false);
            }
            loaded = true;
            return(true);
        }
        private void loadImplementation(int appid, IEnumerable <long> contextIds, SteamID steamid)
        {
            dynamic invResponse;
            string  url = "<empty>";

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

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

            try
            {
                foreach (long contextId in contextIds)
                {
                    string moreStart = null;
                    bool   more      = false;
                    do
                    {
                        var data = String.IsNullOrEmpty(moreStart) ? null : new NameValueCollection {
                            { "start", moreStart }
                        };
                        url = String.Format("http://steamcommunity.com/profiles/{0}/inventory/json/{1}/{2}/", steamid.ConvertToUInt64(), appid, contextId);

                        string response = SteamWeb.Fetch(url, "GET", data);
                        invResponse = JsonConvert.DeserializeObject(response);

                        if (invResponse == null)
                        {
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.WriteLine("Unable to find items in inventory because bot is scanning inventory too fast. Try again later.");
                            Console.ForegroundColor = ConsoleColor.White;
                        }
                        else if (invResponse.success == false)
                        {
                            _errors.Add("Failed to open backpack: " + invResponse.Error);
                            continue;
                        }
                        else
                        {
                            //rgInventory = Items on Steam Inventory
                            foreach (var item in invResponse.rgInventory)
                            {
                                foreach (var itemId in item)
                                {
                                    ulong id = (ulong)itemId.id;
                                    if (!_items.ContainsKey(id))
                                    {
                                        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
                                {
                                    string key = "" + (class_instance.classid ?? '0') + "_" + (class_instance.instanceid ?? '0');
                                    if (!_descriptions.ContainsKey(key))
                                    {
                                        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(key,
                                                          new ItemDescription()
                                        {
                                            name             = class_instance.name,
                                            type             = class_instance.type,
                                            market_hash_name = class_instance.market_hash_name,
                                            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,
                                            market_fee_app_id = (class_instance.market_fee_app != null ? class_instance.market_fee_app : 0),
                                        }
                                                          );
                                        break;
                                    }
                                }
                            }

                            try
                            {
                                moreStart = invResponse.more_start;
                            }
                            catch (Exception e)
                            {
                                moreStart = null;
                            }

                            try
                            {
                                more = invResponse.more;
                            }
                            catch (Exception e)
                            {
                                more = false;
                            }
                        }
                    } while (!String.IsNullOrEmpty(moreStart) && moreStart.ToLower() != "false" && more == true);
                } //end for (contextId)
            }     //end try
            catch (Exception e)
            {
                _errors.Add("Exception: " + e);
                _errors.Add("For more infos; visit this link :\n" + url);
            }

            isLoaded = true;
        }