/// <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 TF2Inventory 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 TF2Inventory(result.result) as TF2Inventory); }
public Trade(TradeOffers tradeOffers, SteamID partnerId, SteamWeb steamWeb) { this.TradeOffers = tradeOffers; this.partnerId = partnerId; this.steamWeb = steamWeb; tradeStatus = new TradeStatus(); tradeStatus.version = 1; tradeStatus.newversion = true; tradeStatus.me = new TradeStatusUser(ref tradeStatus); tradeStatus.them = new TradeStatusUser(ref tradeStatus); }
public GenericInventory(SteamID steamId, SteamID botId, SteamWeb steamWeb) { ConstructTask = Task.Factory.StartNew(() => { this.steamWeb = steamWeb; string baseInventoryUrl = "http://steamcommunity.com/profiles/" + steamId.ConvertToUInt64() + "/inventory/"; string response = RetryWebRequest(baseInventoryUrl, botId); Regex reg = new Regex("var g_rgAppContextData = (.*?);"); Match m = reg.Match(response); if (m.Success) { try { string json = m.Groups[1].Value; var schemaResult = JsonConvert.DeserializeObject <Dictionary <int, InventoryApps> >(json); foreach (var app in schemaResult) { int appId = app.Key; InventoryTasks[appId] = new InventoryTasks.ContextTask(); foreach (var contextId in app.Value.RgContexts.Keys) { InventoryTasks[appId][contextId] = Task.Factory.StartNew(() => { string inventoryUrl = string.Format("http://steamcommunity.com/profiles/{0}/inventory/json/{1}/{2}/", steamId.ConvertToUInt64(), appId, contextId); var inventory = FetchInventory(inventoryUrl, steamId, botId, appId, contextId); if (!inventories.HasAppId(appId)) { inventories[appId] = new BotInventories.ContextInventory(); } if (inventory != null && !inventories[appId].HasContextId(contextId)) { inventories[appId].Add(contextId, inventory); } }); } } } catch (Exception ex) { Success = false; Console.WriteLine(ex); } } else { Success = false; IsPrivate = true; } }); }
/// <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/730/2/?trading=1", steamid.ConvertToUInt64() ); try { string response = steamWeb.Fetch(url, "GET"); return(JsonConvert.DeserializeObject(response)); } catch (Exception) { return(JsonConvert.DeserializeObject("{\"success\":\"false\"}")); } }
private static string RetryWebRequest(SteamWeb steamWeb, string url, string method, NameValueCollection data, bool ajax = false, string referer = "") { for (int i = 0; i < 10; i++) { try { var response = steamWeb.Request(url, method, data, ajax, referer); using (System.IO.Stream responseStream = response.GetResponseStream()) { using (var reader = new System.IO.StreamReader(responseStream)) { string result = reader.ReadToEnd(); if (string.IsNullOrEmpty(result)) { Console.WriteLine("Web request failed (status: {0}). Retrying...", response.StatusCode); System.Threading.Thread.Sleep(1000); } else { return(result); } } } } catch (WebException ex) { try { if (ex.Status == WebExceptionStatus.ProtocolError) { Console.WriteLine("Status Code: {0}, {1}", (int)((HttpWebResponse)ex.Response).StatusCode, ((HttpWebResponse)ex.Response).StatusDescription); } Console.WriteLine("Error: {0}", new System.IO.StreamReader(ex.Response.GetResponseStream()).ReadToEnd()); } catch { } } catch (Exception ex) { Console.WriteLine(ex); } } return(""); }
public TradeOffers(SteamID botId, SteamWeb steamWeb, string accountApiKey, List <ulong> pendingTradeOffers = null) { this.BotId = botId; this.SteamWeb = steamWeb; this.AccountApiKey = accountApiKey; this.ShouldCheckPendingTradeOffers = true; if (pendingTradeOffers == null) { this.OurPendingTradeOffers = new List <ulong>(); } else { this.OurPendingTradeOffers = pendingTradeOffers; } this.ReceivedPendingTradeOffers = new List <ulong>(); new System.Threading.Thread(CheckPendingTradeOffers).Start(); }
/// <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 CSGOInventory FetchInventory(ulong steamId, string apiKey, SteamWeb steamWeb) { var url = "http://api.steampowered.com/IEconItems_730/GetPlayerItems/v0001/?key=" + apiKey + "&steamid=" + steamId; for (int i = 0; i < 100; i++) { try { string response = steamWeb.Fetch(url, "GET", null, false); InventoryResponse result = JsonConvert.DeserializeObject <InventoryResponse>(response); if (result.result != null) { return(new CSGOInventory(result.result) as CSGOInventory); } } catch (System.Net.WebException we) { } } throw new InventoryException("Failed to load CSGO inventory."); }
public static GenericInventory FetchInventories(SteamID steamId, SteamID botId, SteamWeb steamWeb) { return(new GenericInventory(steamId, botId, steamWeb)); }