Skip to content

Commit

Permalink
Merge pull request joshuaferrara#40 from Step7750/master
Browse files Browse the repository at this point in the history
ItemPreviewDataBlock Support
joshuaferrara authored Jul 4, 2016
2 parents 8a87962 + d860047 commit c0eb631
Showing 4 changed files with 112 additions and 0 deletions.
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -132,6 +132,27 @@ Requests a player's profile from the game coordinator. The player must be online

Sets the rich presence object for the currently logged in user. Rich presence is Valve's solution to giving friends information on what you're doing in a game. For example, when you see information about another friends matchmaking game (as in, the map and score), this is set by using rich presence. An example of how to use this method can be found in [example.js](https://github.com/joshuaferrara/node-csgo/blob/master/example/example.js)

## Item Data

### `itemDataRequest(string s, string a, string d, string m)`

Requests item data for the specified CSGO item inspect link parameters. The parameter `s` has a value when the inspect link is from an inventory; likewise, the parameter `m` has a value when the inspect link is from the market. If there is no value for a given parameter from the inspect link, set it to `"0"`.

Listen for the `itemData` event for the game coordinator's response.

Example for an inventory inspect link for a CSGO item
```javascript
// steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20S76561198084749846A6768147729D12557175561287951743
CSGO.itemDataRequest("76561198084749846", "6768147729", "12557175561287951743", "0");
```

Example for a market inspect link for a CSGO item
```javascript
// steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20M563330426657599553A6710760926D9406593057029549017
CSGO.itemDataRequest("0", "6710760926", "9406593057029549017", "563330426657599553");
```


## Sharecode Decoding/Encoding

### `new CSGO.SharecodeDecoder(string code);`
@@ -155,6 +176,35 @@ Emitted when the GC is ready to receive messages. Be careful not to declare ano
### `unready`
Emitted when the connection status to the GC changes, and renders the library unavailable to interact. You should clear any event handlers set in the `ready` event here, otherwise you'll have multiple handlers for each message every time a new `ready` event is sent.

### `itemData` (`itemDataResponse`)

```javascript
{
"iteminfo":
{
"accountid": null,
"itemid": Long { "low": -1821786863, "high": 1, "unsigned": true },
"defindex": 7,
"paintindex": 474,
"rarity": 6,
"quality": 4,
"paintwear": 1054492909,
"paintseed": 183,
"killeaterscoretype": null,
"killeatervalue": null,
"customname": null,
"stickers": [],
"inventory": 3221225475,
"origin": 8,
"questid": null,
"dropreason": null,
"floatvalue": 0.4263376295566559
}
}
```

Emitted when the game coordinator responds to the `itemDataRequest` method.

### `matchmakingStatsData` (`matchmakingStatsResponse`)
* `matchmakingStatsResponse` - Raw response object. Example response below.

7 changes: 7 additions & 0 deletions example/example.js
Original file line number Diff line number Diff line change
@@ -78,6 +78,13 @@ var onSteamLogOn = function onSteamLogOn(response){
time: 161.164087 // This might be the amount of time since you have started the game, not sure.
}
});

// steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20S76561198084749846A6768147729D12557175561287951743
CSGOCli.itemDataRequest("76561198084749846", "6768147729", "12557175561287951743", "0");

CSGOCli.on("itemData", function(itemdata) {
console.log(itemdata);
});
});
});

54 changes: 54 additions & 0 deletions handlers/items.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
var CSGO = require("../index"),
util = require("util"),
protos = require("../helpers/protos");

CSGO.CSGOClient.prototype.itemDataRequest = function(s, a, d, m) {
/*
An inspect link will include s or m depending on whether the
item is in an inventory or the market
If there is no value for a parameter, set it to "0"
REMEMBER: The parameters must be strings in order for JavaScript to keep precision
*/

if (!this._gcReady) {
if (this.debug) {
util.log("GC not ready");
}
return null;
}

if (this.debug) {
util.log("Sending item data request");
}

var payload = new protos.CMsgGCCStrike15_v2_Client2GCEconPreviewDataBlockRequest({
param_s: s,
param_a: a,
param_d: d,
param_m: m
});

this._gc.send({msg:CSGO.ECSGOCMsg.k_EMsgGCCStrike15_v2_Client2GCEconPreviewDataBlockRequest, proto: {}},
payload.toBuffer());
};

var handlers = CSGO.CSGOClient.prototype._handlers;

handlers[CSGO.ECSGOCMsg.k_EMsgGCCStrike15_v2_Client2GCEconPreviewDataBlockResponse] = function onItemDataResponse(message) {
var itemDataResponse = protos.CMsgGCCStrike15_v2_Client2GCEconPreviewDataBlockResponse.decode(message);

if (this.debug) {
util.log("Received item data");
}

// Convert the paintwear uint32 to float
if ("iteminfo" in itemDataResponse && "paintwear" in itemDataResponse["iteminfo"]) {
floatbuffer = new Buffer(4);
floatbuffer.writeUInt32LE(itemDataResponse["iteminfo"]["paintwear"], 0);
itemDataResponse["iteminfo"]["floatvalue"] = floatbuffer.readFloatLE(0);
}

this.emit("itemData", itemDataResponse);
};
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -183,3 +183,4 @@ CSGO.SharecodeDecoder = require("./helpers/sharecode").SharecodeDecoder;
require("./handlers/match");
require("./handlers/player");
require("./handlers/rich_presence");
require("./handlers/items");

0 comments on commit c0eb631

Please sign in to comment.