mirror of
https://github.com/DoctorMcKay/node-steamcommunity.git
synced 2026-08-19 21:23:28 +08:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e789d07833 | ||
|
|
88059596b3 | ||
|
|
399cc5ee84 | ||
|
|
a24bb9d4ad | ||
|
|
81eb26b30d | ||
|
|
0c95e75e39 | ||
|
|
2eaa5b057d | ||
|
|
d5592246cf | ||
|
|
22ab86434a | ||
|
|
d367ceb2a6 | ||
|
|
5ab5a6d401 | ||
|
|
a88a39c62c | ||
|
|
5f4f4a03a4 | ||
|
|
079db4b7bf | ||
|
|
22ba30f5da |
118
index.js
118
index.js
@@ -13,8 +13,9 @@ function SteamCommunity() {
|
||||
}
|
||||
|
||||
SteamCommunity.prototype.login = function(details, callback) {
|
||||
if(details.steamID && details.sentry) {
|
||||
this._jar.setCookie(Request.cookie('steamMachineAuth' + details.steamID.getSteamID64() + '=' + encodeURIComponent(details.sentry)), 'https://steamcommunity.com');
|
||||
if(details.steamguard) {
|
||||
var parts = details.steamguard.split('||');
|
||||
this._jar.setCookie(Request.cookie('steamMachineAuth' + parts[0] + '=' + encodeURIComponent(parts[1])), 'https://steamcommunity.com');
|
||||
}
|
||||
|
||||
var self = this;
|
||||
@@ -80,7 +81,7 @@ SteamCommunity.prototype.login = function(details, callback) {
|
||||
for(var i = 0; i < cookies.length; i++) {
|
||||
var parts = cookies[i].split('=');
|
||||
if(parts[0] == 'steamMachineAuth' + self.steamID) {
|
||||
steamguard = {"steamID": self.steamID, "sentry": decodeURIComponent(parts[1])};
|
||||
steamguard = self.steamID.toString() + '||' + decodeURIComponent(parts[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -121,6 +122,117 @@ function generateSessionID() {
|
||||
return Math.floor(Math.random() * 1000000000);
|
||||
};
|
||||
|
||||
SteamCommunity.prototype.getWebApiKey = function(domain, callback) {
|
||||
var self = this;
|
||||
this._request("https://steamcommunity.com/dev/apikey", function(err, response, body) {
|
||||
if(err || response.statusCode != 200) {
|
||||
return callback(err.message || "HTTP error " + response.statusCode);
|
||||
}
|
||||
|
||||
if(body.match(/<h2>Access Denied<\/h2>/)) {
|
||||
return callback("Access Denied");
|
||||
}
|
||||
|
||||
var match = body.match(/<p>Key: ([0-9A-F]+)<\/p>/);
|
||||
if(match) {
|
||||
// We already have an API key registered
|
||||
callback(null, match[1]);
|
||||
} else {
|
||||
// We need to register a new API key
|
||||
self._request.post('https://steamcommunity.com/dev/registerkey', {
|
||||
"form": {
|
||||
"domain": domain,
|
||||
"agreeToTerms": "agreed",
|
||||
"sessionid": self.getSessionID(),
|
||||
"Submit": "Register"
|
||||
}
|
||||
}, function(err, response, body) {
|
||||
if(err || response.statusCode >= 400) {
|
||||
return callback(err.message || "HTTP error " + response.statusCode);
|
||||
}
|
||||
|
||||
self.getWebApiKey(domain, callback);
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
SteamCommunity.prototype.parentalUnlock = function(pin, callback) {
|
||||
this._request.post("https://steamcommunity.com/parental/ajaxunlock", {
|
||||
"json": true,
|
||||
"form": {
|
||||
"pin": pin
|
||||
}
|
||||
}, function(err, response, body) {
|
||||
if(!callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(err || response.statusCode != 200) {
|
||||
return callback(err.message || "HTTP error " + response.statusCode);
|
||||
}
|
||||
|
||||
if(!body || typeof body.success !== 'boolean') {
|
||||
return callback("Invalid response");
|
||||
}
|
||||
|
||||
if(!body.success) {
|
||||
return callback("Incorrect PIN");
|
||||
}
|
||||
|
||||
callback();
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
SteamCommunity.prototype.getNotifications = function(callback) {
|
||||
this._request.get("https://steamcommunity.com/actions/RefreshNotificationArea", function(err, response, body) {
|
||||
if(err || response.statusCode != 200) {
|
||||
return callback(err.message || "HTTP error " + response.statusCode);
|
||||
}
|
||||
|
||||
var notifications = {
|
||||
"comments": 0,
|
||||
"items": 0,
|
||||
"invites": 0,
|
||||
"gifts": 0,
|
||||
"chat": 0,
|
||||
"trades": 0
|
||||
};
|
||||
|
||||
var items = {
|
||||
"comments": /(\d+) new comments?/,
|
||||
"items": /(\d+) new items? in your inventory/,
|
||||
"invites": /(\d+) new invites?/,
|
||||
"gifts": /(\d+) new gifts?/,
|
||||
"chat": /(\d+) unread chat messages?/,
|
||||
"trades": /(\d+) new trade notifications?/
|
||||
};
|
||||
|
||||
var match;
|
||||
for(var i in items) {
|
||||
if(match = body.match(items[i])) {
|
||||
notifications[i] = parseInt(match[1], 10);
|
||||
}
|
||||
}
|
||||
|
||||
callback(null, notifications);
|
||||
});
|
||||
};
|
||||
|
||||
SteamCommunity.prototype.resetItemNotifications = function(callback) {
|
||||
this._request.get("https://steamcommunity.com/my/inventory", function(err, response, body) {
|
||||
if(!callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(err || response.statusCode != 200) {
|
||||
callback(err.message || "HTTP error " + response.statusCode);
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
SteamCommunity.prototype._checkCommunityError = function(html, callback) {
|
||||
if(html.match(/<h1>Sorry!<\/h1>/)) {
|
||||
var match = html.match(/<h3>(.+)<\/h3>/);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "steamcommunity",
|
||||
"version": "1.0.2",
|
||||
"version": "2.0.0",
|
||||
"description": "Provides an interface for logging into and interacting with the Steam Community website",
|
||||
"keywords": ["steam", "steam community"],
|
||||
"homepage": "https://github.com/DoctorMcKay/node-steamcommunity",
|
||||
@@ -10,7 +10,7 @@
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Doctor_McKay/node-steamcommunity.git"
|
||||
"url": "https://github.com/DoctorMcKay/node-steamcommunity.git"
|
||||
},
|
||||
"dependencies": {
|
||||
"request": "2.51.x",
|
||||
|
||||
Reference in New Issue
Block a user