forked from DoctorMcKay/node-steam-user
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
197 lines (164 loc) · 5.12 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
require('@doctormckay/stats-reporter').setup(require('./package.json'));
var Steam = require('steam-client');
var AppDirectory = require('appdirectory');
var FileStorage = require('file-manager');
require('util').inherits(SteamUser, require('events').EventEmitter);
module.exports = SteamUser;
SteamUser.Steam = Steam;
SteamUser.CurrencyData = require('./resources/CurrencyData.js');
SteamUser.EMachineIDType = require('./resources/EMachineIDType.js');
SteamUser.EPurchaseResult = require('./resources/EPurchaseResult.js');
SteamUser.EClientUIMode = require('./resources/EClientUIMode.js');
require('./resources/enums.js');
try {
SteamUser.Steam.servers = require('./resources/servers.json');
} catch (e) {
// It's okay if it isn't there
}
function SteamUser(client, options) {
if (client && client.constructor.name !== 'SteamClient' && client.constructor.name !== 'CMClient') {
options = client;
client = null;
}
this.client = client ? client : new Steam.CMClient();
this.steamID = null;
// Account info
this.limitations = null;
this.vac = null;
this.wallet = null;
this.emailInfo = null;
this.licenses = null;
this.gifts = null;
// Friends and users info
this.users = {};
this.groups = {};
this.chats = {};
this.myFriends = {};
this.myGroups = {};
this.myFriendGroups = {};
this.myNicknames = {};
this.steamServers = {};
this.contentServersReady = false;
this.playingState = {"blocked": false, "appid": 0};
this._playingBlocked = false;
this._gcTokens = []; // game connect tokens
this._connectTime = 0;
this._connectionCount = 0;
this._authSeqMe = 0;
this._authSeqThem = 0;
this._hSteamPipe = Math.floor(Math.random() * 1000000) + 1;
this._contentServers = [];
this._contentServerTokens = {};
this._lastNotificationCounts = {};
// App and package cache
this._changelistUpdateTimer = null;
this.picsCache = {
"changenumber": 0,
"apps": {},
"packages": {}
};
this._sentry = null;
this.options = options || {};
var defaultOptions = {
"autoRelogin": true,
"singleSentryfile": false,
"promptSteamGuardCode": true,
"machineIdType": SteamUser.EMachineIDType.AccountNameGenerated,
"machineIdFormat": ["SteamUser Hash BB3 {account_name}", "SteamUser Hash FF2 {account_name}", "SteamUser Hash 3B3 {account_name}"],
"enablePicsCache": false,
"picsCacheAll": false,
"changelistUpdateInterval": 60000,
"saveAppTickets": true,
"debug": false
};
for (var i in defaultOptions) {
if (!defaultOptions.hasOwnProperty(i)) {
continue;
}
if (typeof this.options[i] === 'undefined') {
this.options[i] = defaultOptions[i];
}
}
if (!this.options.dataDirectory && this.options.dataDirectory !== null) {
if (process.env.OPENSHIFT_DATA_DIR) {
this.options.dataDirectory = process.env.OPENSHIFT_DATA_DIR + "/node-steamuser";
} else {
this.options.dataDirectory = (new AppDirectory({
"appName": "node-steamuser",
"appAuthor": "doctormckay"
})).userData();
}
}
if (this.options.dataDirectory) {
this.storage = new FileStorage(this.options.dataDirectory);
}
this.client.on('message', this._handleMessage.bind(this));
var self = this;
this.client.on('error', function(e) {
if (!self.steamID && e.result != SteamUser.EResult.ConnectFailed) {
return; // We've already handled this
}
self._handleLogOff(e.eresult || SteamUser.EResult.NoConnection, e.message || "NoConnection");
});
this.client.on('servers', function(servers) {
if (self.storage) {
self.storage.writeFile('servers.json', JSON.stringify(servers, null, "\t"));
}
if (!client) {
// It's an internal client, so we know that our Steam has an up-to-date server list
Steam['__SteamUserServersSet__'] = true;
}
});
}
SteamUser.prototype.setOption = function(option, value) {
this.options[option] = value;
// Handle anything that needs to happen when particular options update
switch (option) {
case 'dataDirectory':
if (!this.storage) {
this.storage = new FileStorage(value);
} else {
this.storage.directory = value;
}
break;
case 'enablePicsCache':
this._resetChangelistUpdateTimer();
this._getLicenseInfo();
break;
case 'changelistUpdateInterval':
this._resetChangelistUpdateTimer();
break;
}
};
SteamUser.prototype.setOptions = function(options) {
for (var i in options) {
if (!options.hasOwnProperty(i)) {
continue;
}
this.setOption(i, options[i]);
}
};
require('./components/messages.js');
require('./components/webapi.js');
require('./components/logon.js');
require('./components/sentry.js');
require('./components/web.js');
require('./components/notifications.js');
require('./components/apps.js');
require('./components/appauth.js');
require('./components/account.js');
require('./components/gameservers.js');
require('./components/utility.js');
require('./components/trading.js');
require('./components/friends.js');
require('./components/chat.js');
require('./components/twofactor.js');
require('./components/pubfiles.js');
require('./components/cdn.js');
require('./components/econ.js');
require('./components/store.js');
/**
* Called when the request completes.
* @callback SteamUser~genericEResultCallback
* @param {EResult} eresult - The result of the operation
*/