UNPKG

1.67 kBJavaScriptView Raw
1var CSGO = require("../index"),
2 util = require("util"),
3 protos = require("../helpers/protos");
4
5CSGO.CSGOClient.prototype.itemDataRequest = function(s, a, d, m) {
6 /*
7 An inspect link will include s or m depending on whether the
8 item is in an inventory or the market
9
10 If there is no value for a parameter, set it to "0"
11
12 REMEMBER: The parameters must be strings in order for JavaScript to keep precision
13 */
14
15 if (!this._gcReady) {
16 if (this.debug) {
17 util.log("GC not ready");
18 }
19 return null;
20 }
21
22 if (this.debug) {
23 util.log("Sending item data request");
24 }
25
26 var payload = new protos.CMsgGCCStrike15_v2_Client2GCEconPreviewDataBlockRequest({
27 param_s: s,
28 param_a: a,
29 param_d: d,
30 param_m: m
31 });
32
33 this._gc.send({msg:CSGO.ECSGOCMsg.k_EMsgGCCStrike15_v2_Client2GCEconPreviewDataBlockRequest, proto: {}},
34 payload.toBuffer());
35};
36
37var handlers = CSGO.CSGOClient.prototype._handlers;
38
39handlers[CSGO.ECSGOCMsg.k_EMsgGCCStrike15_v2_Client2GCEconPreviewDataBlockResponse] = function onItemDataResponse(message) {
40 var itemDataResponse = protos.CMsgGCCStrike15_v2_Client2GCEconPreviewDataBlockResponse.decode(message);
41
42 if (this.debug) {
43 util.log("Received item data");
44 }
45
46 // Convert the paintwear uint32 to float
47 if ("iteminfo" in itemDataResponse && "paintwear" in itemDataResponse["iteminfo"]) {
48 floatbuffer = new Buffer(4);
49 floatbuffer.writeUInt32LE(itemDataResponse["iteminfo"]["paintwear"], 0);
50 itemDataResponse["iteminfo"]["floatvalue"] = floatbuffer.readFloatLE(0);
51 }
52
53 this.emit("itemData", itemDataResponse);
54};