Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

small fixes

  • Loading branch information...
commit 5488a1904804049cddbb7ad8488f315ab956809d 1 parent b9a059b
@gabrielmtzcarrillo gabrielmtzcarrillo authored
View
38 Docs/inventories.htm
@@ -5,8 +5,8 @@
<title>Non TF2 Inventories</title>
<style type="text/css">
body{margin:0px;padding:5px 10px;font-family:consolas,profont,monospace;font-size:0.8em}
- table,td{border:1px dashed silver}
- table{margin-bottom:20px}
+ table,td{border:1px solid silver}
+ table{margin-bottom:20px;empty-cells:hide}
caption,table,th,td{padding:5px}
pre{font-size:1.2em}
h1,b{color:#69C}
@@ -15,19 +15,19 @@
</style>
</head>
<body>
-<p class="version">Version 1.0 (2013/08/18)</p>
+<p class="version">Version 1.1 (2013/08/18)</p>
<h1>Known Inventories</h1>
<p>
- <b>Base URL:</b> http://steamcommunity.com/id/<b>userName</b>/inventory/json/<b>AppId</b>/<b>Type</b><br>
+ <b>Base URL:</b> http://steamcommunity.com/id/<b>userName</b>/inventory/json/<b>AppId</b>/<b>ContextId</b><br>
<b>Game Appids List:</b> <a href="http://api.steampowered.com/ISteamApps/GetAppList/v2">http://api.steampowered.com/ISteamApps/GetAppList/v2</a><br>
- <b>NOTE:</b> Inventory type changes according to the AppId item schema, so it's up to you find it out wich ones work :/
+ <b>NOTE:</b> Inventory Context Id (type) changes according to the AppId item schema, so it's up to you find it out wich ones work :/
</p>
<!--
TEMPLATE
<table>
<caption>Name (AppId)</caption>
- <tr><th>Type</th><th>Description</th><th>Notes</th></tr>
+ <tr><th>Context Id</th><th>Description</th><th>Notes</th></tr>
<tr>
<td></td>
<td></td>
@@ -37,8 +37,8 @@
-->
<table>
- <caption>Steam (AppId 753)</caption>
- <tr><th>Type</th><th>Description</th><th>Notes</th></tr>
+ <caption>Steam Inventory (AppId 753)</caption>
+ <tr><th>Context Id</th><th>Description</th><th>Notes</th></tr>
<tr>
<td>1</td>
@@ -47,15 +47,31 @@
</tr>
<tr>
+ <td>3</td>
+ <td>Coupons</td>
+ <td></td>
+ </tr>
+
+ <tr>
<td>6</td>
- <td>Trading Cards, Profile Backgrounds &amp; Emoticons</td>
- <td>-</td>
+ <td>Steam Trading Cards</td>
+ <td>Game Cards, Profile Backgrounds &amp; Emoticons</td>
</tr>
</table>
<table>
+ <caption>Counter-Strike: Global Offensive (AppId 730)</caption>
+ <tr><th>Context Id</th><th>Description</th><th>Notes</th></tr>
+ <tr>
+ <td>2</td>
+ <td>Inventory</td>
+ <td>Weapons</td>
+ </tr>
+ </table>
+
+ <table>
<caption>Dota 2 (AppId 570)</caption>
- <tr><th>Type</th><th>Description</th><th>Notes</th></tr>
+ <tr><th>Context Id</th><th>Description</th><th>Notes</th></tr>
<tr>
<td>2</td>
<td>Main Inventory</td>
View
4 SteamBot/SteamTradeDemoHandler.cs
@@ -127,7 +127,7 @@ public override void OnTradeInit()
foreach (var item in mySteamInventory.items)
{
- Trade.AddItem(item.Value.id, item.Value.appid, item.Value.contextid);
+ Trade.AddItem(item.Value.assetid, item.Value.appid, item.Value.contextid);
}
break;
@@ -135,7 +135,7 @@ public override void OnTradeInit()
case "remove":
foreach (var item in mySteamInventory.items)
{
- Trade.RemoveItem(item.Value.id, item.Value.appid, item.Value.contextid);
+ Trade.RemoveItem(item.Value.assetid, item.Value.appid, item.Value.contextid);
}
break;
}
View
72 SteamTrade/GenericInventory.cs
@@ -2,11 +2,14 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using SteamKit2;
-using System.Diagnostics;
-
+using SteamTrade.TradeWebAPI;
namespace SteamTrade
{
+
+ /// <summary>
+ /// Generic Steam Backpak Interface
+ /// </summary>
public class GenericInventory
{
public Dictionary<ulong, Item> items = new Dictionary<ulong, Item>();
@@ -15,21 +18,9 @@ public class GenericInventory
public bool loaded = false;
public List<string> errors = new List<string>();
- public class Item
+ public class Item : TradeUserAssets
{
-
- public ulong id { get; set; }
- public ulong classid { get; set; }//Defindex for TF2
- public int appid { get; set; }
- public int contextid { get; set; }
-
- public Item(ulong Id = 0, int AppId = 0, int ContextId = 0, ulong ClassId = 0)
- {
- id = Id;
- classid = ClassId;
- appid = AppId;
- contextid = ContextId;
- }
+ public ulong classid { get; set; }
}
public class ItemDescription
@@ -70,18 +61,16 @@ public bool itemExists(ulong id)
}
}
- public bool load(int appid,List<int> contextid, SteamID steamid)
+ public bool load(int appid,List<int> types, SteamID steamid)
{
dynamic invResponse;
- Item tmpItemData;
- ItemDescription tmpDescription;
loaded = false;
try
{
- for (int i = 0; i < contextid.Count; i++)
+ 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, contextid[i]), "GET", null, null, true);
+ 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);
@@ -97,8 +86,13 @@ public bool load(int appid,List<int> contextid, SteamID steamid)
foreach (var itemId in item)
{
- tmpItemData = new Item((ulong) itemId.id, appid, contextid[i], (ulong) itemId.classid);
- items.Add((ulong)itemId.id, tmpItemData);
+ items.Add((ulong)itemId.id, new Item()
+ {
+ appid = appid,
+ contextid = types[i],
+ assetid = itemId.id,
+ classid = itemId.classid
+ });
break;
}
}
@@ -108,28 +102,22 @@ public bool load(int appid,List<int> contextid, SteamID steamid)
{
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);
+ if (!descriptions.ContainsKey((ulong)classid_instanceid.classid))
+ descriptions.Add((ulong)classid_instanceid.classid, new ItemDescription(){
+ name = classid_instanceid.name,
+ type = classid_instanceid.type,
+ marketable = (bool) classid_instanceid.marketable,
+ tradable = (bool) classid_instanceid.marketable,
+ metadata = classid_instanceid.descriptions
+ });
break;
}
}
- }//end for (inventory type)
-
- if (errors.Count > 0)
- return false;
- else
- {
- loaded = true;
- return true;
- }
+ if (errors.Count > 0)
+ return false;
+
+ }//end for (contextId)
}//end try
catch (Exception e)
{
@@ -137,6 +125,8 @@ public bool load(int appid,List<int> contextid, SteamID steamid)
errors.Add("Exception: " + e.Message);
return false;
}
+ loaded = true;
+ return true;
}
}
}
View
36 SteamTrade/Trade.cs
@@ -217,9 +217,13 @@ public bool CancelTrade ()
/// Adds a specified item by its itemid.
/// </summary>
/// <returns><c>false</c> if the item was not found in the inventory.</returns>
- public bool AddItem (ulong itemid,int appid = 0,int contextid = 0)
+ public bool AddItem (ulong itemid)//TF2 Default
{
- if (appid == 0 & MyInventory.GetItem(itemid) == null)
+ return AddItem(itemid,440,2);
+ }
+ public bool AddItem(ulong itemid, int appid, int contextid)
+ {
+ if (appid == 440 & MyInventory.GetItem(itemid) == null)
return false;
var slot = NextTradeSlot();
@@ -287,14 +291,19 @@ public uint AddAllItemsByDefindex (int defindex, uint numToAdd = 0)
/// Removes an item by its itemid.
/// </summary>
/// <returns><c>false</c> the item was not found in the trade.</returns>
- public bool RemoveItem (ulong itemid,int appid = 0,int contextid = 0)
+ ///
+ public bool RemoveItem(ulong itemid)
+ {
+ return RemoveItem(itemid,440,2);
+ }
+ public bool RemoveItem (ulong itemid,int appid,int contextid)
{
int? slot = GetItemSlot (itemid);
if (!slot.HasValue)
return false;
bool ok = session.RemoveItemWebCmd(itemid, slot.Value,appid,contextid);
-
+
if (!ok)
throw new TradeException ("The web command to remove the item failed.");
@@ -604,10 +613,12 @@ private void FireOnUserAddItem(TradeEvent tradeEvent)
}
else
{
- item = new Inventory.Item();
- item.Id = itemID;
- item.AppId = tradeEvent.appid;
- item.ContextId = tradeEvent.contextid;
+ item = new Inventory.Item()
+ {
+ Id=itemID,
+ AppId=tradeEvent.appid,
+ ContextId=tradeEvent.contextid
+ };
//Console.WriteLine("User added a non TF2 item to the trade.");
OnUserAddItem(null, item);
}
@@ -667,9 +678,12 @@ private void FireOnUserRemoveItem(TradeEvent tradeEvent)
else
{
// TODO: Log this (Couldn't find item in user's inventory can't find item in CurrentSchema
- item = new Inventory.Item();
- item.Id = itemID;
- item.AppId = tradeEvent.appid;
+ item = new Inventory.Item()
+ {
+ Id = itemID,
+ AppId = tradeEvent.appid,
+ ContextId = tradeEvent.contextid
+ };
OnUserRemoveItem(null, item);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.