steamcommunity 3.43.1 → 3.44.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -1,589 +1,589 @@
1
- const hex2b64 = require('node-bignumber').hex2b64;
2
- const Request = require('request');
3
- const RSA = require('node-bignumber').Key;
4
- const SteamID = require('steamid');
5
-
6
- const Helpers = require('./components/helpers.js');
7
-
8
- const USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36";
9
-
10
- require('util').inherits(SteamCommunity, require('events').EventEmitter);
11
-
12
- module.exports = SteamCommunity;
13
-
14
- SteamCommunity.SteamID = SteamID;
15
- SteamCommunity.ConfirmationType = require('./resources/EConfirmationType.js');
16
- SteamCommunity.EResult = require('./resources/EResult.js');
17
- SteamCommunity.EFriendRelationship = require('./resources/EFriendRelationship.js');
18
-
19
-
20
- function SteamCommunity(options) {
21
- options = options || {};
22
-
23
- this._jar = Request.jar();
24
- this._captchaGid = -1;
25
- this._httpRequestID = 0;
26
- this.chatState = SteamCommunity.ChatState.Offline;
27
-
28
- var defaults = {
29
- "jar": this._jar,
30
- "timeout": options.timeout || 50000,
31
- "gzip": true,
32
- "headers": {
33
- "User-Agent": options.userAgent || USER_AGENT
34
- }
35
- };
36
-
37
- if (typeof options == "string") {
38
- options = {
39
- localAddress: options
40
- };
41
- }
42
- this._options = options;
43
-
44
- if (options.localAddress) {
45
- defaults.localAddress = options.localAddress;
46
- }
47
-
48
- this.request = options.request || Request.defaults({"forever": true}); // "forever" indicates that we want a keep-alive agent
49
- this.request = this.request.defaults(defaults);
50
-
51
- // English
52
- this._setCookie(Request.cookie('Steam_Language=english'));
53
-
54
- // UTC
55
- this._setCookie(Request.cookie('timezoneOffset=0,0'));
56
- }
57
-
58
- SteamCommunity.prototype.login = function(details, callback) {
59
- if (!details.accountName || !details.password) {
60
- throw new Error("Missing either accountName or password to login; both are needed");
61
- }
62
-
63
- if (details.steamguard) {
64
- var parts = details.steamguard.split('||');
65
- this._setCookie(Request.cookie('steamMachineAuth' + parts[0] + '=' + encodeURIComponent(parts[1])), true);
66
- }
67
-
68
- var disableMobile = details.disableMobile;
69
-
70
- var self = this;
71
-
72
- // Delete the cache
73
- delete self._profileURL;
74
-
75
- // headers required to convince steam that we're logging in from a mobile device so that we can get the oAuth data
76
- var mobileHeaders = {};
77
- if (!disableMobile) {
78
- mobileHeaders = {
79
- "X-Requested-With": "com.valvesoftware.android.steam.community",
80
- "Referer": "https://steamcommunity.com/mobilelogin?oauth_client_id=DE45CD61&oauth_scope=read_profile%20write_profile%20read_client%20write_client",
81
- "User-Agent": this._options.mobileUserAgent || details.mobileUserAgent || "Mozilla/5.0 (Linux; U; Android 4.1.1; en-us; Google Nexus 4 - 4.1.1 - API 16 - 768x1280 Build/JRO03S) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30",
82
- "Accept": "text/javascript, text/html, application/xml, text/xml, */*"
83
- };
84
-
85
- this._setCookie(Request.cookie("mobileClientVersion=0 (2.1.3)"));
86
- this._setCookie(Request.cookie("mobileClient=android"));
87
- } else {
88
- mobileHeaders = {"Referer": "https://steamcommunity.com/login"};
89
- }
90
-
91
- this.httpRequestPost("https://steamcommunity.com/login/getrsakey/", {
92
- "form": {"username": details.accountName},
93
- "headers": mobileHeaders,
94
- "json": true
95
- }, function(err, response, body) {
96
- // Remove the mobile cookies
97
- if (err) {
98
- deleteMobileCookies();
99
- callback(err);
100
- return;
101
- }
102
-
103
- if (!body.publickey_mod || !body.publickey_exp) {
104
- deleteMobileCookies();
105
- callback(new Error("Invalid RSA key received"));
106
- return;
107
- }
108
-
109
- var key = new RSA();
110
- key.setPublic(body.publickey_mod, body.publickey_exp);
111
-
112
- var formObj = {
113
- "captcha_text": details.captcha || "",
114
- "captchagid": self._captchaGid,
115
- "emailauth": details.authCode || "",
116
- "emailsteamid": "",
117
- "password": hex2b64(key.encrypt(details.password)),
118
- "remember_login": "true",
119
- "rsatimestamp": body.timestamp,
120
- "twofactorcode": details.twoFactorCode || "",
121
- "username": details.accountName,
122
- "loginfriendlyname": "",
123
- "donotcache": Date.now()
124
- };
125
-
126
- if(!disableMobile){
127
- formObj.oauth_client_id = "DE45CD61";
128
- formObj.oauth_scope = "read_profile write_profile read_client write_client";
129
- formObj.loginfriendlyname = "#login_emailauth_friendlyname_mobile";
130
- }
131
-
132
- self.httpRequestPost({
133
- "uri": "https://steamcommunity.com/login/dologin/",
134
- "json": true,
135
- "form": formObj,
136
- "headers": mobileHeaders
137
- }, function(err, response, body) {
138
- deleteMobileCookies();
139
-
140
- if (err) {
141
- callback(err);
142
- return;
143
- }
144
-
145
- var error;
146
- if (!body.success && body.emailauth_needed) {
147
- // Steam Guard (email)
148
- error = new Error("SteamGuard");
149
- error.emaildomain = body.emaildomain;
150
-
151
- callback(error);
152
- } else if (!body.success && body.requires_twofactor) {
153
- // Steam Guard (app)
154
- callback(new Error("SteamGuardMobile"));
155
- } else if (!body.success && body.captcha_needed && body.message.match(/Please verify your humanity/)) {
156
- error = new Error("CAPTCHA");
157
- error.captchaurl = "https://steamcommunity.com/login/rendercaptcha/?gid=" + body.captcha_gid;
158
-
159
- self._captchaGid = body.captcha_gid;
160
-
161
- callback(error);
162
- } else if (!body.success) {
163
- callback(new Error(body.message || "Unknown error"));
164
- } else if (!disableMobile && !body.oauth) {
165
- callback(new Error("Malformed response"));
166
- } else {
167
- var sessionID = generateSessionID();
168
- var oAuth;
169
- self._setCookie(Request.cookie('sessionid=' + sessionID));
170
-
171
- var cookies = self._jar.getCookieString("https://steamcommunity.com").split(';').map(function(cookie) {
172
- return cookie.trim();
173
- });
174
-
175
- if (!disableMobile){
176
- oAuth = JSON.parse(body.oauth);
177
- self.steamID = new SteamID(oAuth.steamid);
178
- self.oAuthToken = oAuth.oauth_token;
179
- }else{
180
- for(var i = 0; i < cookies.length; i++) {
181
- var parts = cookies[i].split('=');
182
- if(parts[0] == 'steamLogin') {
183
- self.steamID = new SteamID(decodeURIComponent(parts[1]).split('||')[0])
184
- break;
185
- }
186
- }
187
-
188
- self.oAuthToken = null;
189
- }
190
-
191
- // Find the Steam Guard cookie
192
- var steamguard = null;
193
- for(var i = 0; i < cookies.length; i++) {
194
- var parts = cookies[i].split('=');
195
- if(parts[0] == 'steamMachineAuth' + self.steamID) {
196
- steamguard = self.steamID.toString() + '||' + decodeURIComponent(parts[1]);
197
- break;
198
- }
199
- }
200
-
201
- self.setCookies(cookies);
202
-
203
- callback(null, sessionID, cookies, steamguard, disableMobile ? null : oAuth.oauth_token);
204
- }
205
- }, "steamcommunity");
206
- }, "steamcommunity");
207
-
208
- function deleteMobileCookies() {
209
- var cookie = Request.cookie('mobileClientVersion=');
210
- cookie.expires = new Date(0);
211
- self._setCookie(cookie);
212
-
213
- cookie = Request.cookie('mobileClient=');
214
- cookie.expires = new Date(0);
215
- self._setCookie(cookie);
216
- }
217
- };
218
-
219
- SteamCommunity.prototype.oAuthLogin = function(steamguard, token, callback) {
220
- steamguard = steamguard.split('||');
221
- var steamID = new SteamID(steamguard[0]);
222
-
223
- var self = this;
224
- this.httpRequestPost({
225
- "uri": "https://api.steampowered.com/IMobileAuthService/GetWGToken/v1/",
226
- "form": {
227
- "access_token": token
228
- },
229
- "json": true
230
- }, function(err, response, body) {
231
- if (err) {
232
- callback(err);
233
- return;
234
- }
235
-
236
- if(!body.response || !body.response.token || !body.response.token_secure) {
237
- callback(new Error("Malformed response"));
238
- return;
239
- }
240
-
241
- var cookies = [
242
- 'steamLogin=' + encodeURIComponent(steamID.getSteamID64() + '||' + body.response.token),
243
- 'steamLoginSecure=' + encodeURIComponent(steamID.getSteamID64() + '||' + body.response.token_secure),
244
- 'steamMachineAuth' + steamID.getSteamID64() + '=' + steamguard[1],
245
- 'sessionid=' + self.getSessionID()
246
- ];
247
-
248
- self.setCookies(cookies);
249
- callback(null, self.getSessionID(), cookies);
250
- }, "steamcommunity");
251
- };
252
-
253
- /**
254
- * Get a token that can be used to log onto Steam using steam-user.
255
- * @param {function} callback
256
- */
257
- SteamCommunity.prototype.getClientLogonToken = function(callback) {
258
- this.httpRequestGet({
259
- "uri": "https://steamcommunity.com/chat/clientjstoken",
260
- "json": true
261
- }, (err, res, body) => {
262
- if (err || res.statusCode != 200) {
263
- callback(err ? err : new Error('HTTP error ' + res.statusCode));
264
- return;
265
- }
266
-
267
- if (!body.logged_in) {
268
- let e = new Error('Not Logged In');
269
- callback(e);
270
- this._notifySessionExpired(e);
271
- return;
272
- }
273
-
274
- if (!body.steamid || !body.account_name || !body.token) {
275
- callback(new Error('Malformed response'));
276
- return;
277
- }
278
-
279
- callback(null, {
280
- "steamID": new SteamID(body.steamid),
281
- "accountName": body.account_name,
282
- "webLogonToken": body.token
283
- });
284
- });
285
- };
286
-
287
- SteamCommunity.prototype._setCookie = function(cookie, secure) {
288
- var protocol = secure ? "https" : "http";
289
- cookie.secure = !!secure;
290
-
291
- this._jar.setCookie(cookie.clone(), protocol + "://steamcommunity.com");
292
- this._jar.setCookie(cookie.clone(), protocol + "://store.steampowered.com");
293
- this._jar.setCookie(cookie.clone(), protocol + "://help.steampowered.com");
294
- };
295
-
296
- SteamCommunity.prototype.setCookies = function(cookies) {
297
- cookies.forEach((cookie) => {
298
- var cookieName = cookie.match(/(.+)=/)[1];
299
- if (cookieName == 'steamLogin' || cookieName == 'steamLoginSecure') {
300
- this.steamID = new SteamID(cookie.match(/=(\d+)/)[1]);
301
- }
302
-
303
- this._setCookie(Request.cookie(cookie), !!(cookieName.match(/^steamMachineAuth/) || cookieName.match(/Secure$/)));
304
- });
305
- };
306
-
307
- SteamCommunity.prototype.getSessionID = function(host = "http://steamcommunity.com") {
308
- var cookies = this._jar.getCookieString(host).split(';');
309
- for(var i = 0; i < cookies.length; i++) {
310
- var match = cookies[i].trim().match(/([^=]+)=(.+)/);
311
- if(match[1] == 'sessionid') {
312
- return decodeURIComponent(match[2]);
313
- }
314
- }
315
-
316
- var sessionID = generateSessionID();
317
- this._setCookie(Request.cookie('sessionid=' + sessionID));
318
- return sessionID;
319
- };
320
-
321
- function generateSessionID() {
322
- return require('crypto').randomBytes(12).toString('hex');
323
- }
324
-
325
- SteamCommunity.prototype.parentalUnlock = function(pin, callback) {
326
- var self = this;
327
- var sessionID = self.getSessionID();
328
-
329
- this.httpRequestPost("https://steamcommunity.com/parental/ajaxunlock", {
330
- "json": true,
331
- "form": {
332
- "pin": pin,
333
- "sessionid": sessionID
334
- }
335
- }, function(err, response, body) {
336
- if(!callback) {
337
- return;
338
- }
339
-
340
- if (err) {
341
- callback(err);
342
- return;
343
- }
344
-
345
- if (!body || typeof body.success !== 'boolean') {
346
- callback("Invalid response");
347
- return;
348
- }
349
-
350
- if (!body.success) {
351
- switch (body.eresult) {
352
- case 15:
353
- callback("Incorrect PIN");
354
- break;
355
-
356
- case 25:
357
- callback("Too many invalid PIN attempts");
358
- break;
359
-
360
- default:
361
- callback("Error " + body.eresult);
362
- }
363
-
364
- return;
365
- }
366
-
367
- callback();
368
- }.bind(this), "steamcommunity");
369
- };
370
-
371
- SteamCommunity.prototype.getNotifications = function(callback) {
372
- var self = this;
373
- this.httpRequestGet({
374
- "uri": "https://steamcommunity.com/actions/GetNotificationCounts",
375
- "json": true
376
- }, function(err, response, body) {
377
- if (err) {
378
- callback(err);
379
- return;
380
- }
381
-
382
- if (!body || !body.notifications) {
383
- callback(new Error("Malformed response"));
384
- return;
385
- }
386
-
387
- var notifications = {
388
- "trades": body.notifications[1] || 0,
389
- "gameTurns": body.notifications[2] || 0,
390
- "moderatorMessages": body.notifications[3] || 0,
391
- "comments": body.notifications[4] || 0,
392
- "items": body.notifications[5] || 0,
393
- "invites": body.notifications[6] || 0,
394
- // dunno about 7
395
- "gifts": body.notifications[8] || 0,
396
- "chat": body.notifications[9] || 0,
397
- "helpRequestReplies": body.notifications[10] || 0,
398
- "accountAlerts": body.notifications[11] || 0
399
- };
400
-
401
- callback(null, notifications);
402
- }, "steamcommunity");
403
- };
404
-
405
- SteamCommunity.prototype.resetItemNotifications = function(callback) {
406
- var self = this;
407
- this.httpRequestGet("https://steamcommunity.com/my/inventory", function(err, response, body) {
408
- if(!callback) {
409
- return;
410
- }
411
-
412
- callback(err || null);
413
- }, "steamcommunity");
414
- };
415
-
416
- SteamCommunity.prototype.loggedIn = function(callback) {
417
- this.httpRequestGet({
418
- "uri": "https://steamcommunity.com/my",
419
- "followRedirect": false,
420
- "checkHttpError": false
421
- }, function(err, response, body) {
422
- if(err || (response.statusCode != 302 && response.statusCode != 403)) {
423
- callback(err || new Error("HTTP error " + response.statusCode));
424
- return;
425
- }
426
-
427
- if(response.statusCode == 403) {
428
- callback(null, true, true);
429
- return;
430
- }
431
-
432
- callback(null, !!response.headers.location.match(/steamcommunity\.com(\/(id|profiles)\/[^\/]+)\/?/), false);
433
- }, "steamcommunity");
434
- };
435
-
436
- SteamCommunity.prototype.getTradeURL = function(callback) {
437
- this._myProfile("tradeoffers/privacy", null, (err, response, body) => {
438
- if (err) {
439
- callback(err);
440
- return;
441
- }
442
-
443
- var match = body.match(/https?:\/\/(www.)?steamcommunity.com\/tradeoffer\/new\/?\?partner=\d+(&|&amp;)token=([a-zA-Z0-9-_]+)/);
444
- if (match) {
445
- var token = match[3];
446
- callback(null, match[0], token);
447
- } else {
448
- callback(new Error("Malformed response"));
449
- }
450
- }, "steamcommunity");
451
- };
452
-
453
- SteamCommunity.prototype.changeTradeURL = function(callback) {
454
- this._myProfile("tradeoffers/newtradeurl", {"sessionid": this.getSessionID()}, (err, response, body) => {
455
- if (!callback) {
456
- return;
457
- }
458
-
459
- if (!body || typeof body !== "string" || body.length < 3 || body.indexOf('"') !== 0) {
460
- callback(new Error("Malformed response"));
461
- return;
462
- }
463
-
464
- var newToken = body.replace(/"/g, ''); //"t1o2k3e4n" => t1o2k3e4n
465
- callback(null, "https://steamcommunity.com/tradeoffer/new/?partner=" + this.steamID.accountid + "&token=" + newToken, newToken);
466
- }, "steamcommunity");
467
- };
468
-
469
- /**
470
- * Clear your profile name (alias) history.
471
- * @param {function} callback
472
- */
473
- SteamCommunity.prototype.clearPersonaNameHistory = function(callback) {
474
- this._myProfile("ajaxclearaliashistory/", {"sessionid": this.getSessionID()}, (err, res, body) => {
475
- if (!callback) {
476
- return;
477
- }
478
-
479
- if (err) {
480
- return callback(err);
481
- }
482
-
483
- if (res.statusCode != 200) {
484
- return callback(new Error("HTTP error " + res.statusCode));
485
- }
486
-
487
- try {
488
- body = JSON.parse(body);
489
- callback(Helpers.eresultError(body.success));
490
- } catch (ex) {
491
- return callback(new Error("Malformed response"));
492
- }
493
- });
494
- };
495
-
496
- SteamCommunity.prototype._myProfile = function(endpoint, form, callback) {
497
- var self = this;
498
-
499
- if (this._profileURL) {
500
- completeRequest(this._profileURL);
501
- } else {
502
- this.httpRequest("https://steamcommunity.com/my", {"followRedirect": false}, function(err, response, body) {
503
- if(err || response.statusCode != 302) {
504
- callback(err || "HTTP error " + response.statusCode);
505
- return;
506
- }
507
-
508
- var match = response.headers.location.match(/steamcommunity\.com(\/(id|profiles)\/[^\/]+)\/?/);
509
- if(!match) {
510
- callback(new Error("Can't get profile URL"));
511
- return;
512
- }
513
-
514
- self._profileURL = match[1];
515
- setTimeout(function () {
516
- delete self._profileURL; // delete the cache
517
- }, 60000).unref();
518
-
519
- completeRequest(match[1]);
520
- }, "steamcommunity");
521
- }
522
-
523
- function completeRequest(url) {
524
- var options = endpoint.endpoint ? endpoint : {};
525
- options.uri = "https://steamcommunity.com" + url + "/" + (endpoint.endpoint || endpoint);
526
-
527
- if (form) {
528
- options.method = "POST";
529
- options.form = form;
530
- options.followAllRedirects = true;
531
- } else if (!options.method) {
532
- options.method = "GET";
533
- }
534
-
535
- self.httpRequest(options, callback, "steamcommunity");
536
- }
537
- };
538
-
539
- /**
540
- * Returns an object whose keys are 64-bit SteamIDs, and whose values are values from the EFriendRelationship enum.
541
- * Therefore, you can deduce your friends or blocked list from this object.
542
- * @param {function} callback
543
- */
544
- SteamCommunity.prototype.getFriendsList = function(callback) {
545
- this.httpRequestGet({
546
- "uri": "https://steamcommunity.com/textfilter/ajaxgetfriendslist",
547
- "json": true
548
- }, (err, res, body) => {
549
- if (err) {
550
- callback(err ? err : new Error('HTTP error ' + res.statusCode));
551
- return;
552
- }
553
-
554
- if (body.success != 1) {
555
- callback(Helpers.eresultError(body.success));
556
- return;
557
- }
558
-
559
- if (!body.friendslist || !body.friendslist.friends) {
560
- callback(new Error('Malformed response'));
561
- return;
562
- }
563
-
564
- const friends = {};
565
- body.friendslist.friends.forEach(friend => (friends[friend.ulfriendid] = friend.efriendrelationship));
566
- callback(null, friends);
567
- });
568
- };
569
-
570
- require('./components/http.js');
571
- require('./components/chat.js');
572
- require('./components/profile.js');
573
- require('./components/market.js');
574
- require('./components/groups.js');
575
- require('./components/users.js');
576
- require('./components/inventoryhistory.js');
577
- require('./components/webapi.js');
578
- require('./components/twofactor.js');
579
- require('./components/confirmations.js');
580
- require('./components/help.js');
581
- require('./classes/CMarketItem.js');
582
- require('./classes/CMarketSearchResult.js');
583
- require('./classes/CSteamGroup.js');
584
- require('./classes/CSteamUser.js');
585
-
586
- /**
587
- @callback SteamCommunity~genericErrorCallback
588
- @param {Error|null} err - An Error object on failure, or null on success
589
- */
1
+ const hex2b64 = require('node-bignumber').hex2b64;
2
+ const Request = require('request');
3
+ const RSA = require('node-bignumber').Key;
4
+ const SteamID = require('steamid');
5
+
6
+ const Helpers = require('./components/helpers.js');
7
+
8
+ const USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36";
9
+
10
+ require('util').inherits(SteamCommunity, require('events').EventEmitter);
11
+
12
+ module.exports = SteamCommunity;
13
+
14
+ SteamCommunity.SteamID = SteamID;
15
+ SteamCommunity.ConfirmationType = require('./resources/EConfirmationType.js');
16
+ SteamCommunity.EResult = require('./resources/EResult.js');
17
+ SteamCommunity.EFriendRelationship = require('./resources/EFriendRelationship.js');
18
+
19
+
20
+ function SteamCommunity(options) {
21
+ options = options || {};
22
+
23
+ this._jar = Request.jar();
24
+ this._captchaGid = -1;
25
+ this._httpRequestID = 0;
26
+ this.chatState = SteamCommunity.ChatState.Offline;
27
+
28
+ var defaults = {
29
+ "jar": this._jar,
30
+ "timeout": options.timeout || 50000,
31
+ "gzip": true,
32
+ "headers": {
33
+ "User-Agent": options.userAgent || USER_AGENT
34
+ }
35
+ };
36
+
37
+ if (typeof options == "string") {
38
+ options = {
39
+ localAddress: options
40
+ };
41
+ }
42
+ this._options = options;
43
+
44
+ if (options.localAddress) {
45
+ defaults.localAddress = options.localAddress;
46
+ }
47
+
48
+ this.request = options.request || Request.defaults({"forever": true}); // "forever" indicates that we want a keep-alive agent
49
+ this.request = this.request.defaults(defaults);
50
+
51
+ // English
52
+ this._setCookie(Request.cookie('Steam_Language=english'));
53
+
54
+ // UTC
55
+ this._setCookie(Request.cookie('timezoneOffset=0,0'));
56
+ }
57
+
58
+ SteamCommunity.prototype.login = function(details, callback) {
59
+ if (!details.accountName || !details.password) {
60
+ throw new Error("Missing either accountName or password to login; both are needed");
61
+ }
62
+
63
+ if (details.steamguard) {
64
+ var parts = details.steamguard.split('||');
65
+ this._setCookie(Request.cookie('steamMachineAuth' + parts[0] + '=' + encodeURIComponent(parts[1])), true);
66
+ }
67
+
68
+ var disableMobile = details.disableMobile;
69
+
70
+ var self = this;
71
+
72
+ // Delete the cache
73
+ delete self._profileURL;
74
+
75
+ // headers required to convince steam that we're logging in from a mobile device so that we can get the oAuth data
76
+ var mobileHeaders = {};
77
+ if (!disableMobile) {
78
+ mobileHeaders = {
79
+ "X-Requested-With": "com.valvesoftware.android.steam.community",
80
+ "Referer": "https://steamcommunity.com/mobilelogin?oauth_client_id=DE45CD61&oauth_scope=read_profile%20write_profile%20read_client%20write_client",
81
+ "User-Agent": this._options.mobileUserAgent || details.mobileUserAgent || "Mozilla/5.0 (Linux; U; Android 4.1.1; en-us; Google Nexus 4 - 4.1.1 - API 16 - 768x1280 Build/JRO03S) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30",
82
+ "Accept": "text/javascript, text/html, application/xml, text/xml, */*"
83
+ };
84
+
85
+ this._setCookie(Request.cookie("mobileClientVersion=0 (2.1.3)"));
86
+ this._setCookie(Request.cookie("mobileClient=android"));
87
+ } else {
88
+ mobileHeaders = {"Referer": "https://steamcommunity.com/login"};
89
+ }
90
+
91
+ this.httpRequestPost("https://steamcommunity.com/login/getrsakey/", {
92
+ "form": {"username": details.accountName},
93
+ "headers": mobileHeaders,
94
+ "json": true
95
+ }, function(err, response, body) {
96
+ // Remove the mobile cookies
97
+ if (err) {
98
+ deleteMobileCookies();
99
+ callback(err);
100
+ return;
101
+ }
102
+
103
+ if (!body.publickey_mod || !body.publickey_exp) {
104
+ deleteMobileCookies();
105
+ callback(new Error("Invalid RSA key received"));
106
+ return;
107
+ }
108
+
109
+ var key = new RSA();
110
+ key.setPublic(body.publickey_mod, body.publickey_exp);
111
+
112
+ var formObj = {
113
+ "captcha_text": details.captcha || "",
114
+ "captchagid": self._captchaGid,
115
+ "emailauth": details.authCode || "",
116
+ "emailsteamid": "",
117
+ "password": hex2b64(key.encrypt(details.password)),
118
+ "remember_login": "true",
119
+ "rsatimestamp": body.timestamp,
120
+ "twofactorcode": details.twoFactorCode || "",
121
+ "username": details.accountName,
122
+ "loginfriendlyname": "",
123
+ "donotcache": Date.now()
124
+ };
125
+
126
+ if(!disableMobile){
127
+ formObj.oauth_client_id = "DE45CD61";
128
+ formObj.oauth_scope = "read_profile write_profile read_client write_client";
129
+ formObj.loginfriendlyname = "#login_emailauth_friendlyname_mobile";
130
+ }
131
+
132
+ self.httpRequestPost({
133
+ "uri": "https://steamcommunity.com/login/dologin/",
134
+ "json": true,
135
+ "form": formObj,
136
+ "headers": mobileHeaders
137
+ }, function(err, response, body) {
138
+ deleteMobileCookies();
139
+
140
+ if (err) {
141
+ callback(err);
142
+ return;
143
+ }
144
+
145
+ var error;
146
+ if (!body.success && body.emailauth_needed) {
147
+ // Steam Guard (email)
148
+ error = new Error("SteamGuard");
149
+ error.emaildomain = body.emaildomain;
150
+
151
+ callback(error);
152
+ } else if (!body.success && body.requires_twofactor) {
153
+ // Steam Guard (app)
154
+ callback(new Error("SteamGuardMobile"));
155
+ } else if (!body.success && body.captcha_needed && body.message.match(/Please verify your humanity/)) {
156
+ error = new Error("CAPTCHA");
157
+ error.captchaurl = "https://steamcommunity.com/login/rendercaptcha/?gid=" + body.captcha_gid;
158
+
159
+ self._captchaGid = body.captcha_gid;
160
+
161
+ callback(error);
162
+ } else if (!body.success) {
163
+ callback(new Error(body.message || "Unknown error"));
164
+ } else if (!disableMobile && !body.oauth) {
165
+ callback(new Error("Malformed response"));
166
+ } else {
167
+ var sessionID = generateSessionID();
168
+ var oAuth;
169
+ self._setCookie(Request.cookie('sessionid=' + sessionID));
170
+
171
+ var cookies = self._jar.getCookieString("https://steamcommunity.com").split(';').map(function(cookie) {
172
+ return cookie.trim();
173
+ });
174
+
175
+ if (!disableMobile){
176
+ oAuth = JSON.parse(body.oauth);
177
+ self.steamID = new SteamID(oAuth.steamid);
178
+ self.oAuthToken = oAuth.oauth_token;
179
+ }else{
180
+ for(var i = 0; i < cookies.length; i++) {
181
+ var parts = cookies[i].split('=');
182
+ if(parts[0] == 'steamLogin') {
183
+ self.steamID = new SteamID(decodeURIComponent(parts[1]).split('||')[0])
184
+ break;
185
+ }
186
+ }
187
+
188
+ self.oAuthToken = null;
189
+ }
190
+
191
+ // Find the Steam Guard cookie
192
+ var steamguard = null;
193
+ for(var i = 0; i < cookies.length; i++) {
194
+ var parts = cookies[i].split('=');
195
+ if(parts[0] == 'steamMachineAuth' + self.steamID) {
196
+ steamguard = self.steamID.toString() + '||' + decodeURIComponent(parts[1]);
197
+ break;
198
+ }
199
+ }
200
+
201
+ self.setCookies(cookies);
202
+
203
+ callback(null, sessionID, cookies, steamguard, disableMobile ? null : oAuth.oauth_token);
204
+ }
205
+ }, "steamcommunity");
206
+ }, "steamcommunity");
207
+
208
+ function deleteMobileCookies() {
209
+ var cookie = Request.cookie('mobileClientVersion=');
210
+ cookie.expires = new Date(0);
211
+ self._setCookie(cookie);
212
+
213
+ cookie = Request.cookie('mobileClient=');
214
+ cookie.expires = new Date(0);
215
+ self._setCookie(cookie);
216
+ }
217
+ };
218
+
219
+ SteamCommunity.prototype.oAuthLogin = function(steamguard, token, callback) {
220
+ steamguard = steamguard.split('||');
221
+ var steamID = new SteamID(steamguard[0]);
222
+
223
+ var self = this;
224
+ this.httpRequestPost({
225
+ "uri": "https://api.steampowered.com/IMobileAuthService/GetWGToken/v1/",
226
+ "form": {
227
+ "access_token": token
228
+ },
229
+ "json": true
230
+ }, function(err, response, body) {
231
+ if (err) {
232
+ callback(err);
233
+ return;
234
+ }
235
+
236
+ if(!body.response || !body.response.token || !body.response.token_secure) {
237
+ callback(new Error("Malformed response"));
238
+ return;
239
+ }
240
+
241
+ var cookies = [
242
+ 'steamLogin=' + encodeURIComponent(steamID.getSteamID64() + '||' + body.response.token),
243
+ 'steamLoginSecure=' + encodeURIComponent(steamID.getSteamID64() + '||' + body.response.token_secure),
244
+ 'steamMachineAuth' + steamID.getSteamID64() + '=' + steamguard[1],
245
+ 'sessionid=' + self.getSessionID()
246
+ ];
247
+
248
+ self.setCookies(cookies);
249
+ callback(null, self.getSessionID(), cookies);
250
+ }, "steamcommunity");
251
+ };
252
+
253
+ /**
254
+ * Get a token that can be used to log onto Steam using steam-user.
255
+ * @param {function} callback
256
+ */
257
+ SteamCommunity.prototype.getClientLogonToken = function(callback) {
258
+ this.httpRequestGet({
259
+ "uri": "https://steamcommunity.com/chat/clientjstoken",
260
+ "json": true
261
+ }, (err, res, body) => {
262
+ if (err || res.statusCode != 200) {
263
+ callback(err ? err : new Error('HTTP error ' + res.statusCode));
264
+ return;
265
+ }
266
+
267
+ if (!body.logged_in) {
268
+ let e = new Error('Not Logged In');
269
+ callback(e);
270
+ this._notifySessionExpired(e);
271
+ return;
272
+ }
273
+
274
+ if (!body.steamid || !body.account_name || !body.token) {
275
+ callback(new Error('Malformed response'));
276
+ return;
277
+ }
278
+
279
+ callback(null, {
280
+ "steamID": new SteamID(body.steamid),
281
+ "accountName": body.account_name,
282
+ "webLogonToken": body.token
283
+ });
284
+ });
285
+ };
286
+
287
+ SteamCommunity.prototype._setCookie = function(cookie, secure) {
288
+ var protocol = secure ? "https" : "http";
289
+ cookie.secure = !!secure;
290
+
291
+ this._jar.setCookie(cookie.clone(), protocol + "://steamcommunity.com");
292
+ this._jar.setCookie(cookie.clone(), protocol + "://store.steampowered.com");
293
+ this._jar.setCookie(cookie.clone(), protocol + "://help.steampowered.com");
294
+ };
295
+
296
+ SteamCommunity.prototype.setCookies = function(cookies) {
297
+ cookies.forEach((cookie) => {
298
+ var cookieName = cookie.match(/(.+)=/)[1];
299
+ if (cookieName == 'steamLogin' || cookieName == 'steamLoginSecure') {
300
+ this.steamID = new SteamID(cookie.match(/=(\d+)/)[1]);
301
+ }
302
+
303
+ this._setCookie(Request.cookie(cookie), !!(cookieName.match(/^steamMachineAuth/) || cookieName.match(/Secure$/)));
304
+ });
305
+ };
306
+
307
+ SteamCommunity.prototype.getSessionID = function(host = "http://steamcommunity.com") {
308
+ var cookies = this._jar.getCookieString(host).split(';');
309
+ for(var i = 0; i < cookies.length; i++) {
310
+ var match = cookies[i].trim().match(/([^=]+)=(.+)/);
311
+ if(match[1] == 'sessionid') {
312
+ return decodeURIComponent(match[2]);
313
+ }
314
+ }
315
+
316
+ var sessionID = generateSessionID();
317
+ this._setCookie(Request.cookie('sessionid=' + sessionID));
318
+ return sessionID;
319
+ };
320
+
321
+ function generateSessionID() {
322
+ return require('crypto').randomBytes(12).toString('hex');
323
+ }
324
+
325
+ SteamCommunity.prototype.parentalUnlock = function(pin, callback) {
326
+ var self = this;
327
+ var sessionID = self.getSessionID();
328
+
329
+ this.httpRequestPost("https://steamcommunity.com/parental/ajaxunlock", {
330
+ "json": true,
331
+ "form": {
332
+ "pin": pin,
333
+ "sessionid": sessionID
334
+ }
335
+ }, function(err, response, body) {
336
+ if(!callback) {
337
+ return;
338
+ }
339
+
340
+ if (err) {
341
+ callback(err);
342
+ return;
343
+ }
344
+
345
+ if (!body || typeof body.success !== 'boolean') {
346
+ callback("Invalid response");
347
+ return;
348
+ }
349
+
350
+ if (!body.success) {
351
+ switch (body.eresult) {
352
+ case 15:
353
+ callback("Incorrect PIN");
354
+ break;
355
+
356
+ case 25:
357
+ callback("Too many invalid PIN attempts");
358
+ break;
359
+
360
+ default:
361
+ callback("Error " + body.eresult);
362
+ }
363
+
364
+ return;
365
+ }
366
+
367
+ callback();
368
+ }.bind(this), "steamcommunity");
369
+ };
370
+
371
+ SteamCommunity.prototype.getNotifications = function(callback) {
372
+ var self = this;
373
+ this.httpRequestGet({
374
+ "uri": "https://steamcommunity.com/actions/GetNotificationCounts",
375
+ "json": true
376
+ }, function(err, response, body) {
377
+ if (err) {
378
+ callback(err);
379
+ return;
380
+ }
381
+
382
+ if (!body || !body.notifications) {
383
+ callback(new Error("Malformed response"));
384
+ return;
385
+ }
386
+
387
+ var notifications = {
388
+ "trades": body.notifications[1] || 0,
389
+ "gameTurns": body.notifications[2] || 0,
390
+ "moderatorMessages": body.notifications[3] || 0,
391
+ "comments": body.notifications[4] || 0,
392
+ "items": body.notifications[5] || 0,
393
+ "invites": body.notifications[6] || 0,
394
+ // dunno about 7
395
+ "gifts": body.notifications[8] || 0,
396
+ "chat": body.notifications[9] || 0,
397
+ "helpRequestReplies": body.notifications[10] || 0,
398
+ "accountAlerts": body.notifications[11] || 0
399
+ };
400
+
401
+ callback(null, notifications);
402
+ }, "steamcommunity");
403
+ };
404
+
405
+ SteamCommunity.prototype.resetItemNotifications = function(callback) {
406
+ var self = this;
407
+ this.httpRequestGet("https://steamcommunity.com/my/inventory", function(err, response, body) {
408
+ if(!callback) {
409
+ return;
410
+ }
411
+
412
+ callback(err || null);
413
+ }, "steamcommunity");
414
+ };
415
+
416
+ SteamCommunity.prototype.loggedIn = function(callback) {
417
+ this.httpRequestGet({
418
+ "uri": "https://steamcommunity.com/my",
419
+ "followRedirect": false,
420
+ "checkHttpError": false
421
+ }, function(err, response, body) {
422
+ if(err || (response.statusCode != 302 && response.statusCode != 403)) {
423
+ callback(err || new Error("HTTP error " + response.statusCode));
424
+ return;
425
+ }
426
+
427
+ if(response.statusCode == 403) {
428
+ callback(null, true, true);
429
+ return;
430
+ }
431
+
432
+ callback(null, !!response.headers.location.match(/steamcommunity\.com(\/(id|profiles)\/[^\/]+)\/?/), false);
433
+ }, "steamcommunity");
434
+ };
435
+
436
+ SteamCommunity.prototype.getTradeURL = function(callback) {
437
+ this._myProfile("tradeoffers/privacy", null, (err, response, body) => {
438
+ if (err) {
439
+ callback(err);
440
+ return;
441
+ }
442
+
443
+ var match = body.match(/https?:\/\/(www.)?steamcommunity.com\/tradeoffer\/new\/?\?partner=\d+(&|&amp;)token=([a-zA-Z0-9-_]+)/);
444
+ if (match) {
445
+ var token = match[3];
446
+ callback(null, match[0], token);
447
+ } else {
448
+ callback(new Error("Malformed response"));
449
+ }
450
+ }, "steamcommunity");
451
+ };
452
+
453
+ SteamCommunity.prototype.changeTradeURL = function(callback) {
454
+ this._myProfile("tradeoffers/newtradeurl", {"sessionid": this.getSessionID()}, (err, response, body) => {
455
+ if (!callback) {
456
+ return;
457
+ }
458
+
459
+ if (!body || typeof body !== "string" || body.length < 3 || body.indexOf('"') !== 0) {
460
+ callback(new Error("Malformed response"));
461
+ return;
462
+ }
463
+
464
+ var newToken = body.replace(/"/g, ''); //"t1o2k3e4n" => t1o2k3e4n
465
+ callback(null, "https://steamcommunity.com/tradeoffer/new/?partner=" + this.steamID.accountid + "&token=" + newToken, newToken);
466
+ }, "steamcommunity");
467
+ };
468
+
469
+ /**
470
+ * Clear your profile name (alias) history.
471
+ * @param {function} callback
472
+ */
473
+ SteamCommunity.prototype.clearPersonaNameHistory = function(callback) {
474
+ this._myProfile("ajaxclearaliashistory/", {"sessionid": this.getSessionID()}, (err, res, body) => {
475
+ if (!callback) {
476
+ return;
477
+ }
478
+
479
+ if (err) {
480
+ return callback(err);
481
+ }
482
+
483
+ if (res.statusCode != 200) {
484
+ return callback(new Error("HTTP error " + res.statusCode));
485
+ }
486
+
487
+ try {
488
+ body = JSON.parse(body);
489
+ callback(Helpers.eresultError(body.success));
490
+ } catch (ex) {
491
+ return callback(new Error("Malformed response"));
492
+ }
493
+ });
494
+ };
495
+
496
+ SteamCommunity.prototype._myProfile = function(endpoint, form, callback) {
497
+ var self = this;
498
+
499
+ if (this._profileURL) {
500
+ completeRequest(this._profileURL);
501
+ } else {
502
+ this.httpRequest("https://steamcommunity.com/my", {"followRedirect": false}, function(err, response, body) {
503
+ if(err || response.statusCode != 302) {
504
+ callback(err || "HTTP error " + response.statusCode);
505
+ return;
506
+ }
507
+
508
+ var match = response.headers.location.match(/steamcommunity\.com(\/(id|profiles)\/[^\/]+)\/?/);
509
+ if(!match) {
510
+ callback(new Error("Can't get profile URL"));
511
+ return;
512
+ }
513
+
514
+ self._profileURL = match[1];
515
+ setTimeout(function () {
516
+ delete self._profileURL; // delete the cache
517
+ }, 60000).unref();
518
+
519
+ completeRequest(match[1]);
520
+ }, "steamcommunity");
521
+ }
522
+
523
+ function completeRequest(url) {
524
+ var options = endpoint.endpoint ? endpoint : {};
525
+ options.uri = "https://steamcommunity.com" + url + "/" + (endpoint.endpoint || endpoint);
526
+
527
+ if (form) {
528
+ options.method = "POST";
529
+ options.form = form;
530
+ options.followAllRedirects = true;
531
+ } else if (!options.method) {
532
+ options.method = "GET";
533
+ }
534
+
535
+ self.httpRequest(options, callback, "steamcommunity");
536
+ }
537
+ };
538
+
539
+ /**
540
+ * Returns an object whose keys are 64-bit SteamIDs, and whose values are values from the EFriendRelationship enum.
541
+ * Therefore, you can deduce your friends or blocked list from this object.
542
+ * @param {function} callback
543
+ */
544
+ SteamCommunity.prototype.getFriendsList = function(callback) {
545
+ this.httpRequestGet({
546
+ "uri": "https://steamcommunity.com/textfilter/ajaxgetfriendslist",
547
+ "json": true
548
+ }, (err, res, body) => {
549
+ if (err) {
550
+ callback(err ? err : new Error('HTTP error ' + res.statusCode));
551
+ return;
552
+ }
553
+
554
+ if (body.success != 1) {
555
+ callback(Helpers.eresultError(body.success));
556
+ return;
557
+ }
558
+
559
+ if (!body.friendslist || !body.friendslist.friends) {
560
+ callback(new Error('Malformed response'));
561
+ return;
562
+ }
563
+
564
+ const friends = {};
565
+ body.friendslist.friends.forEach(friend => (friends[friend.ulfriendid] = friend.efriendrelationship));
566
+ callback(null, friends);
567
+ });
568
+ };
569
+
570
+ require('./components/http.js');
571
+ require('./components/chat.js');
572
+ require('./components/profile.js');
573
+ require('./components/market.js');
574
+ require('./components/groups.js');
575
+ require('./components/users.js');
576
+ require('./components/inventoryhistory.js');
577
+ require('./components/webapi.js');
578
+ require('./components/twofactor.js');
579
+ require('./components/confirmations.js');
580
+ require('./components/help.js');
581
+ require('./classes/CMarketItem.js');
582
+ require('./classes/CMarketSearchResult.js');
583
+ require('./classes/CSteamGroup.js');
584
+ require('./classes/CSteamUser.js');
585
+
586
+ /**
587
+ @callback SteamCommunity~genericErrorCallback
588
+ @param {Error|null} err - An Error object on failure, or null on success
589
+ */