forked from seishun/node-steam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
75 lines (57 loc) · 2.19 KB
/
index.js
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
var EventEmitter = require('events').EventEmitter;
var Steam = require('../../steam_client');
var EMsg = Steam.EMsg;
var schema = Steam.Internal;
function SteamUser(steamClient) {
this._client = steamClient;
this._client.on('message', function(header, body, callback) {
if (header.msg in handlers)
handlers[header.msg].call(this, body, callback);
}.bind(this));
}
require('util').inherits(SteamUser, EventEmitter);
// Methods
SteamUser.prototype.logOn = function(logOnDetails) {
// construct temporary SteamID
this._client.steamID = new (require('../../steamID'))({
accountInstance: 1,
accountUniverse: Steam.EUniverse.Public,
accountType: Steam.EAccountType.Individual
}).toString();
logOnDetails.protocol_version = 65575;
this._client.send({
msg: EMsg.ClientLogon,
proto: {}
}, new schema.CMsgClientLogon(logOnDetails).toBuffer());
};
SteamUser.prototype.requestWebAPIAuthenticateUserNonce = function(callback) {
this._client.send({
msg: EMsg.ClientRequestWebAPIAuthenticateUserNonce,
proto: {}
}, new schema.CMsgClientRequestWebAPIAuthenticateUserNonce().toBuffer(), function(header, body) {
var nonce = schema.CMsgClientRequestWebAPIAuthenticateUserNonceResponse.decode(body);
callback(Steam._processProto(nonce));
});
};
SteamUser.prototype.gamesPlayed = function(gamesPlayed) {
this._client.send({
msg: EMsg.ClientGamesPlayed,
proto: {}
}, new schema.CMsgClientGamesPlayed(gamesPlayed).toBuffer());
};
// Handlers
var handlers = {};
handlers[EMsg.ClientUpdateMachineAuth] = function(data, callback) {
var machineAuth = schema.CMsgClientUpdateMachineAuth.decode(data);
this.emit('updateMachineAuth', Steam._processProto(machineAuth), function(response) {
callback({
msg: EMsg.ClientUpdateMachineAuthResponse,
proto: {}
}, new schema.CMsgClientUpdateMachineAuthResponse(response).toBuffer());
});
};
handlers[EMsg.ClientUserNotifications] = function(data) {
var notifications = schema.CMsgClientUserNotifications.decode(data).notifications;
this.emit('tradeOffers', notifications.length ? notifications[0].count : 0); // assuming length == 1 and userNotificationType == 1
};
Steam.SteamUser = SteamUser;