forked from joshuaferrara/node-steam-key
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
56 lines (47 loc) · 1.72 KB
/
index.js
File metadata and controls
56 lines (47 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var protos = require("./protos"),
protoMask = 0x80000000,
EventEmitter = require('events').EventEmitter,
util = require('util'),
vdf = require('./VDF');
var SteamRegistrar = function SteamRegistrar(steamUser, steamGC, debug) {
EventEmitter.call(this);
this.debug = debug || false;
this._user = steamUser;
this._gc = steamGC;
this._handlers = {};
var self = this;
this._gc.on('message', function(type, message, callback) {
callback = callback || null;
var msgId = type.msg & ~protoMask;
if (self.debug)
console.info("Message from GC: " + msgId);
switch (msgId) { // In the event that we need more in the future.
case 763: // ClientPurchaseResponse = 763;
if (self.debug)
console.info("Emitting purchaseResponse");
var purchaseResponse = protos.ClientPurchaseResponse.decode(message);
purchaseResponse.purchase_receipt_info = vdf.decode(purchaseResponse.purchase_receipt_info.toBuffer());
self.emit("purchaseResponse", purchaseResponse);
break;
}
});
};
util.inherits(SteamRegistrar, EventEmitter);
SteamRegistrar.prototype.activateKey = function(key, callback) {
if (this.debug)
console.info("Sending activation request");
var newCallback = function(header, message) {
var purchaseResponse = protos.ClientPurchaseResponse.decode(message);
purchaseResponse.purchase_receipt_info = vdf.decode(purchaseResponse.purchase_receipt_info.toBuffer());
callback(purchaseResponse);
};
if (callback === undefined) newCallback = undefined; // Otherwise, the event will not be emitted.
var payload = new protos.ClientRegisterKey({
key: key
});
this._gc._send({
msg: 743, // ClientRegisterKey = 743;
proto: {},
}, payload.toBuffer(), newCallback);
};
exports.SteamRegistrar = SteamRegistrar;