Skip to content
Permalink
Browse files

small fixes

  • Loading branch information...
gabrielmtzcarrillo committed Sep 14, 2013
1 parent b9a059b commit 5488a1904804049cddbb7ad8488f315ab956809d
Showing with 85 additions and 65 deletions.
  1. +27 −11 Docs/inventories.htm
  2. +2 −2 SteamBot/SteamTradeDemoHandler.cs
  3. +31 −41 SteamTrade/GenericInventory.cs
  4. +25 −11 SteamTrade/Trade.cs
@@ -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,25 +37,41 @@ <h1>Known Inventories</h1>
-->

<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>
<td>Gifts (Games)</td>
<td><Strong>WARNING:</Strong> Automatization (buy &amp; sell) may be against Steam TOS</td>
</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>
@@ -127,15 +127,15 @@ 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;

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;
}
@@ -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,35 +102,31 @@ 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)
{
Console.WriteLine(e.Message);
errors.Add("Exception: " + e.Message);
return false;
}
loaded = true;
return true;
}
}
}
@@ -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);
}
}

0 comments on commit 5488a19

Please sign in to comment.
You can’t perform that action at this time.