Compare commits

..

1 Commits

Author SHA1 Message Date
Alexander Corn
6144ee1909 Added parsing of discussion data in a JS VM 2016-01-21 17:38:46 -05:00
24 changed files with 439 additions and 653 deletions

View File

@@ -1,35 +0,0 @@
# Contributing to SteamCommunity
Thanks for your interest in making `SteamCommunity` better! I'd appreciate it if you read over this document quickly
before you submit your issue or pull request. It'll make things go much smoother.
# Issues
Submitting an issue?
- If you're **reporting a bug**, please include all relevant details.
- A descriptive title helps for one. Titles of just "Error" or "It doesn't work" really don't help.
- Please describe what you're trying to do, what actually happens, and what you can do to reproduce the problem.
- If you have an error message or a crash, please include the full text of the error message and the stack trace.
- Include the relevant snippet of your code. Wrap it in \`\`\`js /* code */ \`\`\` and GitHub [will format it nicely for you](https://help.github.com/articles/github-flavored-markdown/#syntax-highlighting).
- If you're **requesting a feature**, please be descriptive and understanding.
- A good title makes a difference. Please briefly describe what you're requesting in the title.
- Be descriptive in the issue body, too. Say what you want to do, and ideally what the method should be named.
- Be understanding if I don't think that your feature request falls within the scope of this module.
- If you're **asking a question** or **requesting support**, please don't submit a GitHub issue.
- Issues are only for problems directly relating to the module's code.
- Please [post a thread in the dedicated forum](https://dev.doctormckay.com/forum/8-node-steamcommunity/) instead.
# Pull Requests
Submitting a pull request? Great! Thanks for contributing your time and code! Please keep the following in mind.
- Please follow the existing code style.
- Tabs for indentation
- camelCase for variables and functions
- Opening braces on the same line as the if/for/while statement
- etc.
- Please avoid breaking changes. If you make a breaking change that can be done in a backwards-compatible manner, I won't accept it.
- Please don't increment the version number in `package.json`. I'll do that myself when I publish it to npm.
- Please include a brief description of your change in the pull request if it's not immediately apparent from the code.
- Be understanding if I don't think that your change falls within the scope of this module.

View File

@@ -9,15 +9,12 @@ This module provides an easy interface for the Steam Community website. This mod
It supports Steam Guard and CAPTCHAs.
**Have a question about the module or coding in general? *Do not create a GitHub issue.* GitHub issues are for feature
requests and bug reports. Instead, post in the [dedicated forum](https://dev.doctormckay.com/forum/8-node-steamcommunity/).
Such issues may be ignored!**
# Installation
Install it from npm:
$ npm install steamcommunity
# Documentation
Documentation is available on the [GitHub wiki](https://github.com/DoctorMcKay/node-steamcommunity/wiki).
# Support
Report bugs on the [issue tracker](https://github.com/DoctorMcKay/node-steamcommunity/issues) or ask questions
on the [dedicated forum](https://dev.doctormckay.com/forum/8-node-steamcommunity/).
As of version 1.0.0, documentation is on the [GitHub wiki](https://github.com/DoctorMcKay/node-steamcommunity/wiki).

View File

View File

@@ -1,15 +1,10 @@
var SteamCommunity = require('../index.js');
var Cheerio = require('cheerio');
SteamCommunity.prototype.getMarketItem = function(appid, hashName, currency, callback) {
if (typeof currency == "function") {
callback = currency;
currency = 1;
}
SteamCommunity.prototype.getMarketItem = function(appid, hashName, callback) {
var self = this;
this.httpRequest("https://steamcommunity.com/market/listings/" + appid + "/" + encodeURIComponent(hashName), function(err, response, body) {
if (err) {
callback(err);
this.request("https://steamcommunity.com/market/listings/" + appid + "/" + encodeURIComponent(hashName), function(err, response, body) {
if(self._checkHttpError(err, response, callback)) {
return;
}
@@ -18,21 +13,23 @@ SteamCommunity.prototype.getMarketItem = function(appid, hashName, currency, cal
callback(new Error("There are no listings for this item."));
return;
}
var item = new CMarketItem(appid, hashName, self, body, $);
item.updatePrice(currency, function(err) {
if(err) {
callback(err);
} else {
callback(null, item);
}
});
}, "steamcommunity");
var item = new CMarketItem(self, body, $);
if(item.commodity) {
item.updatePrice(function(err) {
if(err) {
callback(err);
} else {
callback(null, item);
}
});
} else {
callback(null, item);
}
});
};
function CMarketItem(appid, hashName, community, body, $) {
this._appid = appid;
this._hashName = hashName;
function CMarketItem(community, body, $) {
this._community = community;
this._$ = $;
@@ -41,12 +38,6 @@ function CMarketItem(appid, hashName, community, body, $) {
if(match) {
this._country = match[1];
}
this._language = "english";
match = body.match(/var g_strLanguage = "([^"]+)";/);
if(match) {
this._language = match[1];
}
this.commodity = false;
var match = body.match(/Market_LoadOrderSpread\(\s*(\d+)\s*\);/);
@@ -71,45 +62,37 @@ function CMarketItem(appid, hashName, community, body, $) {
// ignore
}
}
this.firstAsset = null;
this.assets = null;
match = body.match(/var g_rgAssets = (.*);/);
if (match) {
try {
this.assets = JSON.parse(match[1]);
this.assets = this.assets['730']['2'];
this.firstAsset = this.assets[Object.keys(this.assets)[0]];
} catch (e) {
// ignore
}
}
this.quantity = 0;
this.lowestPrice = 0;
if(!this.commodity) {
var total = $('#searchResults_total');
if(total) {
this.quantity = parseInt(total.text().replace(/[^\d]/g, '').trim(), 10);
}
var lowest = $('.market_listing_price.market_listing_price_with_fee');
if(lowest[0]) {
this.lowestPrice = parseInt($(lowest[0]).text().replace(/[^\d]/g, '').trim(), 10);
}
}
// TODO: Buying listings and placing buy orders
}
CMarketItem.prototype.updatePrice = function (currency, callback) {
if (this.commodity) {
this.updatePriceForCommodity(currency, callback);
} else {
this.updatePriceForNonCommodity(currency, callback);
}
};
CMarketItem.prototype.updatePriceForCommodity = function(currency, callback) {
CMarketItem.prototype.updatePrice = function(callback) {
if(!this.commodity) {
throw new Error("Cannot update price for non-commodity item");
}
// TODO: Currency option maybe?
var self = this;
this._community.httpRequest({
"uri": "https://steamcommunity.com/market/itemordershistogram?country=US&language=english&currency=" + currency + "&item_nameid=" + this.commodityID,
"json": true
this._community.request({
"uri": "https://steamcommunity.com/market/itemordershistogram?country=US&language=english&currency=1&item_nameid=" + this.commodityID,
"json": true,
}, function(err, response, body) {
if (err) {
callback(err);
if(self._community._checkHttpError(err, response, callback)) {
return;
}
@@ -139,50 +122,5 @@ CMarketItem.prototype.updatePriceForCommodity = function(currency, callback) {
if(callback) {
callback(null);
}
}, "steamcommunity");
};
CMarketItem.prototype.updatePriceForNonCommodity = function (currency, callback) {
if(this.commodity) {
throw new Error("Cannot update price for commodity item");
}
var self = this;
this._community.httpRequest({
"uri": "https://steamcommunity.com/market/listings/" +
this._appid + "/" +
encodeURIComponent(this._hashName) +
"/render/?query=&start=0&count=10&country=US&language=english&currency=" + currency,
"json": true
}, function(err, response, body) {
if (err) {
callback(err);
return;
}
if (body.success != 1) {
callback && callback(new Error("Error " + body.success));
return;
}
var match = body.total_count;
if (match) {
self.quantity = parseInt(match, 10);
}
var lowestPrice;
var $ = Cheerio.load(body.results_html);
match = $(".market_listing_price.market_listing_price_with_fee");
if (match) {
for (var i = 0; i < match.length; i++) {
lowestPrice = parseFloat($(match[i]).text().replace(",", ".").replace(/[^\d.]/g, ''));
if (!isNaN(lowestPrice)) {
self.lowestPrice = lowestPrice;
break;
}
}
}
callback && callback(null);
}, "steamcommunity");
});
};

View File

@@ -27,7 +27,7 @@ SteamCommunity.prototype.marketSearch = function(options, callback) {
qs.count = 100;
qs.sort_column = 'price';
qs.sort_dir = 'asc';
performSearch.call(this, this.httpRequest, qs, [], callback);
performSearch.call(this, this.request, qs, [], callback);
};
function performSearch(request, qs, results, callback) {
@@ -40,8 +40,7 @@ function performSearch(request, qs, results, callback) {
},
"json": true
}, function(err, response, body) {
if (err) {
callback(err);
if(self._checkHttpError(err, response, callback)) {
return;
}
@@ -72,7 +71,7 @@ function performSearch(request, qs, results, callback) {
qs.start += body.pagesize;
performSearch.call(self, request, qs, results, callback);
}
}, "steamcommunity");
});
}
function CMarketSearchResult(row) {

View File

@@ -1,10 +1,9 @@
var SteamCommunity = require('../index.js');
var Helpers = require('../components/helpers.js');
var SteamID = require('steamid');
var xml2js = require('xml2js');
SteamCommunity.prototype.getSteamGroup = function(id, callback) {
if(typeof id !== 'string' && !Helpers.isSteamID(id)) {
if(typeof id !== 'string' && !(typeof id === 'object' && id.__proto__ === SteamID.prototype)) {
throw new Error("id parameter should be a group URL string or a SteamID object");
}
@@ -13,9 +12,12 @@ SteamCommunity.prototype.getSteamGroup = function(id, callback) {
}
var self = this;
this.httpRequest("https://steamcommunity.com/" + (typeof id === 'string' ? "groups/" + id : "gid/" + id.toString()) + "/memberslistxml/?xml=1", function(err, response, body) {
if (err) {
callback(err);
this.request("https://steamcommunity.com/" + (typeof id === 'string' ? "groups/" + id : "gid/" + id.toString()) + "/memberslistxml/?xml=1", function(err, response, body) {
if(self._checkHttpError(err, response, callback)) {
return;
}
if(self._checkCommunityError(body, callback)) {
return;
}
@@ -27,7 +29,7 @@ SteamCommunity.prototype.getSteamGroup = function(id, callback) {
callback(null, new CSteamGroup(self, result.memberList));
});
}, "steamcommunity");
});
};
function CSteamGroup(community, groupData) {

View File

@@ -1,10 +1,9 @@
var SteamCommunity = require('../index.js');
var Helpers = require('../components/helpers.js');
var SteamID = require('steamid');
var xml2js = require('xml2js');
SteamCommunity.prototype.getSteamUser = function(id, callback) {
if(typeof id !== 'string' && !Helpers.isSteamID(id)) {
if(typeof id !== 'string' && !(typeof id === 'object' && id.__proto__ === SteamID.prototype)) {
throw new Error("id parameter should be a user URL string or a SteamID object");
}
@@ -13,9 +12,12 @@ SteamCommunity.prototype.getSteamUser = function(id, callback) {
}
var self = this;
this.httpRequest("http://steamcommunity.com/" + (typeof id === 'string' ? "id/" + id : "profiles/" + id.toString()) + "/?xml=1", function(err, response, body) {
if (err) {
callback(err);
this.request("http://steamcommunity.com/" + (typeof id === 'string' ? "id/" + id : "profiles/" + id.toString()) + "/?xml=1", function(err, response, body) {
if(self._checkHttpError(err, response, callback)) {
return;
}
if(self._checkCommunityError(body, callback)) {
return;
}
@@ -46,7 +48,7 @@ SteamCommunity.prototype.getSteamUser = function(id, callback) {
callback(null, new CSteamUser(self, result.profile, customurl));
});
}, "steamcommunity");
});
};
function CSteamUser(community, userData, customurl) {
@@ -88,7 +90,7 @@ function CSteamUser(community, userData, customurl) {
var self = this;
if(userData.groups && userData.groups[0] && userData.groups[0].group) {
this.groups = userData.groups[0].group.map(function(group) {
if(group['$'] && group['$'].isPrimary === "1") {
if(group['$'] && group['$'].isPrimary) {
self.primaryGroup = new SteamID(group.groupID64[0]);
}

View File

@@ -48,7 +48,7 @@ SteamCommunity.prototype.chatLogon = function(interval, uiMode) {
return;
}
self.httpRequestPost({
self.request.post({
"uri": "https://api.steampowered.com/ISteamWebUserPresenceOAuth/Logon/v1",
"form": {
"ui_mode": uiMode,
@@ -82,7 +82,7 @@ SteamCommunity.prototype.chatLogon = function(interval, uiMode) {
self.chatState = SteamCommunity.ChatState.LoggedOn;
self.emit('chatLoggedOn');
self._chatPoll();
}, "steamcommunity");
});
});
};
@@ -103,7 +103,7 @@ SteamCommunity.prototype.chatMessage = function(recipient, text, type, callback)
type = type || 'saytext';
var self = this;
this.httpRequestPost({
this.request.post({
"uri": "https://api.steampowered.com/ISteamWebUserPresenceOAuth/Message/v1",
"form": {
"access_token": this._chat.accessToken,
@@ -118,8 +118,7 @@ SteamCommunity.prototype.chatMessage = function(recipient, text, type, callback)
return;
}
if (err) {
callback(err);
if(self._checkHttpError(err, response, callback)) {
return;
}
@@ -128,12 +127,12 @@ SteamCommunity.prototype.chatMessage = function(recipient, text, type, callback)
} else {
callback(null);
}
}, "steamcommunity");
});
};
SteamCommunity.prototype.chatLogoff = function() {
var self = this;
this.httpRequestPost({
this.request.post({
"uri": "https://api.steampowered.com/ISteamWebUserPresenceOAuth/Logoff/v1",
"form": {
"access_token": this._chat.accessToken,
@@ -150,14 +149,14 @@ SteamCommunity.prototype.chatLogoff = function() {
delete self.chatFriends;
self.chatState = SteamCommunity.ChatState.Offline;
}
}, "steamcommunity");
});
};
SteamCommunity.prototype._chatPoll = function() {
this.emit('debug', 'Doing chat poll');
var self = this;
this.httpRequestPost({
this.request.post({
"uri": "https://api.steampowered.com/ISteamWebUserPresenceOAuth/Poll/v1",
"form": {
"umqid": self._chat.umqid,
@@ -212,13 +211,13 @@ SteamCommunity.prototype._chatPoll = function() {
self.emit('debug', 'Unhandled chat message type: ' + message.type);
}
});
}, "steamcommunity");
});
};
SteamCommunity.prototype._chatUpdatePersona = function(steamID) {
this.emit('debug', 'Updating persona data for ' + steamID);
var self = this;
this.httpRequest({
this.request({
"uri": "https://steamcommunity.com/chat/friendstate/" + steamID.accountid,
"json": true
}, function(err, response, body) {
@@ -243,5 +242,5 @@ SteamCommunity.prototype._chatUpdatePersona = function(steamID) {
self.emit('chatPersonaState', steamID, persona);
self.chatFriends[steamID.getSteamID64()] = persona;
}, "steamcommunity");
});
};

View File

@@ -16,11 +16,6 @@ SteamCommunity.prototype.getConfirmations = function(time, key, callback) {
request(this, "conf", key, time, "conf", null, false, function(err, body) {
if(err) {
if (err.message == "Invalid protocol: steammobile:") {
err.message = "Not Logged In";
self._notifySessionExpired(err);
}
callback(err);
return;
}
@@ -153,25 +148,24 @@ function request(community, url, key, time, tag, params, json, callback) {
params.m = "android";
params.tag = tag;
community.httpRequestGet({
community.request.get({
"uri": "https://steamcommunity.com/mobileconf/" + url,
"qs": params,
"json": !!json
}, function(err, response, body) {
if (err) {
callback(err);
if(community._checkHttpError(err, response, callback)) {
return;
}
callback(null, body);
}, "steamcommunity");
});
}
// Confirmation checker
/**
* Start automatically polling our confirmations for new ones. The `confKeyNeeded` event will be emitted when we need a confirmation key, or `newConfirmation` when we get a new confirmation
* @param {int} pollInterval - The interval, in milliseconds, at which we will poll for confirmations. This should probably be at least 10,000 to avoid rate-limits.
* @param {int} pollInterval - The interval, in milliseconds, at which we will poll for confirmations. This shouldn't be any less than 10,000 probably.
* @param {Buffer|string|null} [identitySecret=null] - Your identity_secret. If passed, all confirmations will be automatically accepted and nothing will be emitted.
*/
SteamCommunity.prototype.startConfirmationChecker = function(pollInterval, identitySecret) {

61
components/discussions.js Normal file
View File

@@ -0,0 +1,61 @@
var SteamCommunity = require('../index.js');
var Cheerio = require('cheerio');
var VM = require('vm');
SteamCommunity.prototype.getDiscussion = function(url, callback) {
var self = this;
this.request.get({
"uri": url,
"followRedirect": false
}, function(err, response, body) {
if(self._checkHttpError(err, response, callback)) {
return;
}
if(self._checkCommunityError(body, callback)) {
return;
}
if(response.statusCode >= 300 && response.statusCode <= 399) {
callback(new Error("Topic Not Found"));
return
}
var $ = Cheerio.load(body);
var scripts = $('#group_tab_content_discussions').find('script');
if(scripts.length < 2) {
callback(new Error("Malformed response"));
return;
}
var context = VM.createContext({
"ForumTopic": {},
"CommentThread": {},
"$J": function(input) {
if(typeof input === 'function') {
input();
}
},
"InitializeForumTopic": function(board, boardUrl, topicID, topic) {
context.ForumTopic.board = board;
context.ForumTopic.topicID = topicID;
context.ForumTopic.topic = topic;
},
"InitializeCommentThread": function(type, name, commentData, url, quoteBoxHeight) {
context.CommentThread.type = type;
context.CommentThread.name = name;
context.CommentThread.commentData = commentData;
context.CommentThread.url = url;
context.CommentThread.quoteBoxHeight = quoteBoxHeight;
}
});
console.log(context);
VM.runInContext($(scripts[0]).html(), context);
VM.runInContext($(scripts[1]).html(), context);
console.log(context);
});
};

View File

@@ -38,9 +38,8 @@ SteamCommunity.prototype.getGroupMembers = function(gid, callback, members, link
}
var self = this;
this.httpRequest(options, function(err, response, body) {
if (err) {
callback(err);
this.request(options, function(err, response, body) {
if (self._checkHttpError(err, response, callback)) {
return;
}
@@ -61,7 +60,7 @@ SteamCommunity.prototype.getGroupMembers = function(gid, callback, members, link
callback(null, members);
}
});
}, "steamcommunity");
});
};
SteamCommunity.prototype.getGroupMembersEx = function(gid, addresses, callback) {
@@ -74,7 +73,7 @@ SteamCommunity.prototype.joinGroup = function(gid, callback) {
}
var self = this;
this.httpRequestPost({
this.request.post({
"uri": "https://steamcommunity.com/gid/" + gid.getSteamID64(),
"form": {
"action": "join",
@@ -85,8 +84,17 @@ SteamCommunity.prototype.joinGroup = function(gid, callback) {
return;
}
callback(err || null);
}, "steamcommunity");
if(err || response.statusCode >= 400) {
callback(err || new Error("HTTP error " + response.statusCode));
return;
}
if(self._checkCommunityError(body, callback)) {
return;
}
callback(null);
});
};
SteamCommunity.prototype.leaveGroup = function(gid, callback) {
@@ -104,7 +112,16 @@ SteamCommunity.prototype.leaveGroup = function(gid, callback) {
return;
}
callback(err || null);
if(err || response.statusCode >= 400) {
callback(err || new Error("HTTP error " + response.statusCode));
return;
}
if(self._checkCommunityError(body, callback)) {
return;
}
callback(null);
});
};
@@ -119,11 +136,15 @@ SteamCommunity.prototype.getAllGroupAnnouncements = function(gid, time, callback
}
var self = this;
this.httpRequest({
this.request({
"uri": "https://steamcommunity.com/gid/" + gid.getSteamID64() + "/rss/"
}, function(err, response, body) {
if (err) {
callback(err);
if(self._checkHttpError(err, response, callback)) {
return;
}
if(self._checkCommunityError(body, callback)) {
return;
}
@@ -151,7 +172,7 @@ SteamCommunity.prototype.getAllGroupAnnouncements = function(gid, time, callback
return callback(null, announcements);
});
}, "steamcommunity");
});
}
SteamCommunity.prototype.postGroupAnnouncement = function(gid, headline, content, callback) {
@@ -160,7 +181,7 @@ SteamCommunity.prototype.postGroupAnnouncement = function(gid, headline, content
}
var self = this;
this.httpRequestPost({
this.request.post({
"uri": "https://steamcommunity.com/gid/" + gid.getSteamID64() + "/announcements",
"form": {
"sessionID": this.getSessionID(),
@@ -175,8 +196,16 @@ SteamCommunity.prototype.postGroupAnnouncement = function(gid, headline, content
return;
}
callback(err || null);
}, "steamcommunity");
if(self._checkHttpError(err, response, callback)) {
return;
}
if(self._checkCommunityError(body, callback)) {
return;
}
callback(null);
})
};
SteamCommunity.prototype.editGroupAnnouncement = function(gid, aid, headline, content, callback) {
@@ -198,15 +227,23 @@ SteamCommunity.prototype.editGroupAnnouncement = function(gid, aid, headline, co
"languages[0][body]": content,
"languages[0][updated]": 1
}
};
}
this.httpRequestPost(submitData, function(err, response, body) {
this.request.post(submitData, function(err, response, body) {
if(!callback) {
return;
}
callback(err || null);
}, "steamcommunity");
if(self._checkHttpError(err, response, callback)) {
return;
}
if(self._checkCommunityError(body, callback)) {
return;
}
callback(null);
})
};
SteamCommunity.prototype.deleteGroupAnnouncement = function(gid, aid, callback) {
@@ -217,16 +254,24 @@ SteamCommunity.prototype.deleteGroupAnnouncement = function(gid, aid, callback)
var self = this;
var submitData = {
"uri": "https://steamcommunity.com/gid/" + gid.getSteamID64() + "/announcements/delete/" + aid + "?sessionID=" + this.getSessionID()
};
"uri": "https://steamcommunity.com/gid/" + gid.getSteamID64() + "/announcements/delete/" + aid + "?sessionID=" + this.getSessionID(),
}
this.httpRequestGet(submitData, function(err, response, body) {
this.request.get(submitData, function(err, response, body) {
if(!callback) {
return;
}
callback(err || null);
}, "steamcommunity");
if(self._checkHttpError(err, response, callback)) {
return;
}
if(self._checkCommunityError(body, callback)) {
return;
}
callback(null);
})
};
SteamCommunity.prototype.scheduleGroupEvent = function(gid, name, type, description, time, server, callback) {
@@ -274,7 +319,7 @@ SteamCommunity.prototype.scheduleGroupEvent = function(gid, name, type, descript
}
var self = this;
this.httpRequestPost({
this.request.post({
"uri": "https://steamcommunity.com/gid/" + gid.toString() + "/eventEdit",
"form": form
}, function(err, response, body) {
@@ -282,8 +327,17 @@ SteamCommunity.prototype.scheduleGroupEvent = function(gid, name, type, descript
return;
}
callback(err || null);
}, "steamcommunity");
if(err || response.statusCode >= 400) {
callback(err || new Error("HTTP error " + response.statusCode));
return;
}
if(self._checkCommunityError(body, callback)) {
return;
}
callback(null);
});
};
SteamCommunity.prototype.setGroupPlayerOfTheWeek = function(gid, steamID, callback) {
@@ -296,7 +350,7 @@ SteamCommunity.prototype.setGroupPlayerOfTheWeek = function(gid, steamID, callba
}
var self = this;
this.httpRequestPost({
this.request.post({
"uri": "https://steamcommunity.com/gid/" + gid.getSteamID64() + "/potwEdit",
"form": {
"xml": 1,
@@ -326,7 +380,7 @@ SteamCommunity.prototype.setGroupPlayerOfTheWeek = function(gid, steamID, callba
callback(new Error(results.response.results[0]));
}
});
}, "steamcommunity");
});
};
SteamCommunity.prototype.kickGroupMember = function(gid, steamID, callback) {
@@ -339,7 +393,7 @@ SteamCommunity.prototype.kickGroupMember = function(gid, steamID, callback) {
}
var self = this;
this.httpRequestPost({
this.request.post({
"uri": "https://steamcommunity.com/gid/" + gid.getSteamID64() + "/membersManage",
"form": {
"sessionID": this.getSessionID(),
@@ -352,8 +406,17 @@ SteamCommunity.prototype.kickGroupMember = function(gid, steamID, callback) {
return;
}
callback(err || null);
}, "steamcommunity");
if(err || response.statusCode >= 400) {
callback(err || new Error("HTTP error " + response.statusCode));
return;
}
if(self._checkCommunityError(body, callback)) {
return;
}
callback(null);
});
};
SteamCommunity.prototype.getGroupHistory = function(gid, page, callback) {
@@ -367,9 +430,12 @@ SteamCommunity.prototype.getGroupHistory = function(gid, page, callback) {
}
var self = this;
this.httpRequest("https://steamcommunity.com/gid/" + gid.getSteamID64() + "/history?p=" + page, function(err, response, body) {
if (err) {
callback(err);
this.request("https://steamcommunity.com/gid/" + gid.getSteamID64() + "/history?p=" + page, function(err, response, body) {
if(self._checkHttpError(err, response, callback)) {
return;
}
if(self._checkCommunityError(body, callback)) {
return;
}
@@ -433,5 +499,5 @@ SteamCommunity.prototype.getGroupHistory = function(gid, page, callback) {
});
callback(null, output);
}, "steamcommunity");
});
};

View File

@@ -1,13 +0,0 @@
exports.isSteamID = function(input) {
var keys = Object.keys(input);
if (keys.length != 4) {
return false;
}
// Make sure it has the keys we expect
keys = keys.filter(function(item) {
return ['universe', 'type', 'instance', 'accountid'].indexOf(item) != -1;
});
return keys.length == 4;
};

View File

@@ -1,138 +0,0 @@
var SteamCommunity = require('../index.js');
SteamCommunity.prototype.httpRequest = function(uri, options, callback, source) {
if (typeof uri === 'object') {
source = callback;
callback = options;
options = uri;
uri = options.url || options.uri;
} else if (typeof options === 'function') {
source = callback;
callback = options;
options = {};
}
options.url = options.uri = uri;
if (this._httpRequestConvenienceMethod) {
options.method = this._httpRequestConvenienceMethod;
delete this._httpRequestConvenienceMethod;
}
var requestID = ++this._httpRequestID;
source = source || "";
var self = this;
var continued = false;
if (!this.onPreHttpRequest || !this.onPreHttpRequest(requestID, source, options, continueRequest)) {
// No pre-hook, or the pre-hook doesn't want to delay the request.
continueRequest(null);
}
function continueRequest(err) {
if (continued) {
return;
}
continued = true;
if (err) {
if (callback) {
callback(err);
}
return;
}
self.request(options, function (err, response, body) {
var hasCallback = !!callback;
var httpError = options.checkHttpError !== false && self._checkHttpError(err, response, callback);
var communityError = !options.json && options.checkCommunityError !== false && self._checkCommunityError(body, httpError ? function () {} : callback); // don't fire the callback if hasHttpError did it already
var tradeError = !options.json && options.checkTradeError !== false && self._checkTradeError(body, httpError || communityError ? function () {} : callback); // don't fire the callback if either of the previous already did
self.emit('postHttpRequest', requestID, source, options, httpError || communityError || tradeError || null, response, body, {
"hasCallback": hasCallback,
"httpError": httpError,
"communityError": communityError,
"tradeError": tradeError
});
if(hasCallback && !(httpError || communityError || tradeError)) {
callback.apply(self, arguments);
}
});
}
};
SteamCommunity.prototype.httpRequestGet = function() {
this._httpRequestConvenienceMethod = "GET";
return this.httpRequest.apply(this, arguments);
};
SteamCommunity.prototype.httpRequestPost = function() {
this._httpRequestConvenienceMethod = "POST";
return this.httpRequest.apply(this, arguments);
};
SteamCommunity.prototype._notifySessionExpired = function(err) {
this.emit('sessionExpired', err);
};
SteamCommunity.prototype._checkHttpError = function(err, response, callback) {
if(err) {
callback(err);
return err;
}
if(response.statusCode >= 300 && response.statusCode <= 399 && response.headers.location.indexOf('/login') != -1) {
err = new Error("Not Logged In");
callback(err);
this._notifySessionExpired(err);
return err;
}
if(response.statusCode >= 400) {
err = new Error("HTTP error " + response.statusCode);
err.code = response.statusCode;
callback(err);
return err;
}
return false;
};
SteamCommunity.prototype._checkCommunityError = function(html, callback) {
var err;
if(typeof html === 'string' && html.match(/<h1>Sorry!<\/h1>/)) {
var match = html.match(/<h3>(.+)<\/h3>/);
err = new Error(match ? match[1] : "Unknown error occurred");
callback(err);
return err;
}
if (typeof html === 'string' && html.match(/g_steamID = false;/) && html.match(/<h1>Sign In<\/h1>/)) {
err = new Error("Not Logged In");
callback(err);
this._notifySessionExpired(err);
return err;
}
return false;
};
SteamCommunity.prototype._checkTradeError = function(html, callback) {
if (typeof html !== 'string') {
return false;
}
var match = html.match(/<div id="error_msg">\s*([^<]+)\s*<\/div>/);
if (match) {
var err = new Error(match[1].trim());
callback(new Error(err));
return err;
}
return false;
};

View File

@@ -13,7 +13,7 @@ SteamCommunity.prototype.getInventoryHistory = function(options, callback) {
options.page = options.page || 1;
this.httpRequest("https://steamcommunity.com/my/inventoryhistory?l=english&p=" + options.page, function(err, response, body) {
this.request("https://steamcommunity.com/my/inventoryhistory?l=english&p=" + options.page, function(err, response, body) {
if(err) {
callback(err);
return;
@@ -122,7 +122,7 @@ SteamCommunity.prototype.getInventoryHistory = function(options, callback) {
} else {
callback(null, output);
}
}, "steamcommunity");
});
};
function resolveVanityURL(vanityURL, callback) {

View File

@@ -3,12 +3,10 @@ var Cheerio = require('cheerio');
SteamCommunity.prototype.getMarketApps = function(callback) {
var self = this;
this.httpRequest('https://steamcommunity.com/market/', function (err, response, body) {
if (err) {
callback(err);
this.request('https://steamcommunity.com/market/', function (err, response, body) {
if(self._checkHttpError(err, response, callback)) {
return;
}
var $ = Cheerio.load(body);
if ($('.market_search_game_button_group')) {
apps = {};
@@ -23,5 +21,5 @@ SteamCommunity.prototype.getMarketApps = function(callback) {
} else {
callback(new Error("Malformed response"));
}
}, "steamcommunity");
};
});
}

View File

@@ -114,10 +114,6 @@ SteamCommunity.prototype.editProfile = function(settings, callback) {
}
self._myProfile("edit", values, function(err, response, body) {
if (values.customURL) {
delete self._profileURL;
}
if(err || response.statusCode != 200) {
if(callback) {
callback(err || new Error("HTTP error " + response.statusCode));
@@ -224,7 +220,7 @@ SteamCommunity.prototype.uploadAvatar = function(image, format, callback) {
if(image instanceof Buffer) {
doUpload(image);
} else if(image.match(/^https?:\/\//)) {
this.httpRequestGet({
this.request.get({
"uri": image,
"encoding": null
}, function(err, response, body) {
@@ -241,7 +237,7 @@ SteamCommunity.prototype.uploadAvatar = function(image, format, callback) {
}
doUpload(body);
}, "steamcommunity");
})
} else {
if(!format) {
format = image.match(/\.([^\.]+)$/);
@@ -304,7 +300,7 @@ SteamCommunity.prototype.uploadAvatar = function(image, format, callback) {
return;
}
self.httpRequestPost({
self.request.post({
"uri": "https://steamcommunity.com/actions/FileUploader",
"formData": {
"MAX_FILE_SIZE": buffer.length,
@@ -358,6 +354,6 @@ SteamCommunity.prototype.uploadAvatar = function(image, format, callback) {
if(callback) {
callback(null, body.images.full);
}
}, "steamcommunity");
});
}
};

View File

@@ -16,7 +16,7 @@ SteamCommunity.prototype.enableTwoFactor = function(callback) {
return;
}
self.httpRequestPost({
self.request.post({
"uri": "https://api.steampowered.com/ITwoFactorService/AddAuthenticator/v1/",
"form": {
"steamid": self.steamID.getSteamID64(),
@@ -28,8 +28,7 @@ SteamCommunity.prototype.enableTwoFactor = function(callback) {
},
"json": true
}, function(err, response, body) {
if (err) {
callback(err);
if(self._checkHttpError(err, response, callback)) {
return;
}
@@ -46,7 +45,7 @@ SteamCommunity.prototype.enableTwoFactor = function(callback) {
}
callback(null, body.response);
}, "steamcommunity");
});
});
};
@@ -61,21 +60,13 @@ SteamCommunity.prototype.finalizeTwoFactor = function(secret, activationCode, ca
return;
}
SteamTotp.getTimeOffset(function(err, offset, latency) {
if (err) {
callback(err);
return;
}
diff = offset;
finalize(token);
});
finalize(token);
});
function finalize(token) {
var code = SteamTotp.generateAuthCode(secret, diff);
self.httpRequestPost({
self.request.post({
"uri": "https://api.steampowered.com/ITwoFactorService/FinalizeAddAuthenticator/v1/",
"form": {
"steamid": self.steamID.getSteamID64(),
@@ -86,8 +77,7 @@ SteamCommunity.prototype.finalizeTwoFactor = function(secret, activationCode, ca
},
"json": true
}, function(err, response, body) {
if (err) {
callback(err);
if(self._checkHttpError(err, response, callback)) {
return;
}
@@ -114,7 +104,7 @@ SteamCommunity.prototype.finalizeTwoFactor = function(secret, activationCode, ca
} else {
callback(null);
}
}, "steamcommunity");
});
}
};
@@ -127,7 +117,7 @@ SteamCommunity.prototype.disableTwoFactor = function(revocationCode, callback) {
return;
}
self.httpRequestPost({
self.request.post({
"uri": "https://api.steampowered.com/ITwoFactorService/RemoveAuthenticator/v1/",
"form": {
"steamid": self.steamID.getSteamID64(),
@@ -137,8 +127,7 @@ SteamCommunity.prototype.disableTwoFactor = function(revocationCode, callback) {
},
"json": true
}, function(err, response, body) {
if (err) {
callback(err);
if(self._checkHttpError(err, response, callback)) {
return;
}
@@ -152,8 +141,14 @@ SteamCommunity.prototype.disableTwoFactor = function(revocationCode, callback) {
return;
}
// success = true means it worked
callback(null);
}, "steamcommunity");
if(body.response.status == 1) {
callback(null);
return;
}
var error = new Error("Cannot remove authenticator (" + body.response.status + ")");
error.eresult = body.response.status;
callback(error);
});
});
};

View File

@@ -8,7 +8,7 @@ SteamCommunity.prototype.addFriend = function(userID, callback) {
}
var self = this;
this.httpRequestPost({
this.request.post({
"uri": "https://steamcommunity.com/actions/AddFriendAjax",
"form": {
"accept_invite": 0,
@@ -21,8 +21,7 @@ SteamCommunity.prototype.addFriend = function(userID, callback) {
return;
}
if (err) {
callback(err);
if(self._checkHttpError(err, response, callback)) {
return;
}
@@ -31,7 +30,7 @@ SteamCommunity.prototype.addFriend = function(userID, callback) {
} else {
callback(new Error("Unknown error"));
}
}, "steamcommunity");
});
};
SteamCommunity.prototype.acceptFriendRequest = function(userID, callback) {
@@ -40,7 +39,7 @@ SteamCommunity.prototype.acceptFriendRequest = function(userID, callback) {
}
var self = this;
this.httpRequestPost({
this.request.post({
"uri": "https://steamcommunity.com/actions/AddFriendAjax",
"form": {
"accept_invite": 1,
@@ -52,8 +51,12 @@ SteamCommunity.prototype.acceptFriendRequest = function(userID, callback) {
return;
}
callback(err || null);
}, "steamcommunity");
if(self._checkHttpError(err, response, callback)) {
return;
}
callback(null);
});
};
SteamCommunity.prototype.removeFriend = function(userID, callback) {
@@ -62,7 +65,7 @@ SteamCommunity.prototype.removeFriend = function(userID, callback) {
}
var self = this;
this.httpRequestPost({
this.request.post({
"uri": "https://steamcommunity.com/actions/RemoveFriendAjax",
"form": {
"sessionID": this.getSessionID(),
@@ -73,8 +76,12 @@ SteamCommunity.prototype.removeFriend = function(userID, callback) {
return;
}
callback(err || null);
}, "steamcommunity");
if(self._checkHttpError(err, response, callback)) {
return;
}
callback(null);
});
};
SteamCommunity.prototype.blockCommunication = function(userID, callback) {
@@ -83,7 +90,7 @@ SteamCommunity.prototype.blockCommunication = function(userID, callback) {
}
var self = this;
this.httpRequestPost({
this.request.post({
"uri": "https://steamcommunity.com/actions/BlockUserAjax",
"form": {
"sessionID": this.getSessionID(),
@@ -94,8 +101,12 @@ SteamCommunity.prototype.blockCommunication = function(userID, callback) {
return;
}
callback(err || null);
}, "steamcommunity");
if(self._checkHttpError(err, response, callback)) {
return;
}
callback(null);
});
};
SteamCommunity.prototype.unblockCommunication = function(userID, callback) {
@@ -126,7 +137,7 @@ SteamCommunity.prototype.postUserComment = function(userID, message, callback) {
}
var self = this;
this.httpRequestPost({
this.request.post({
"uri": "https://steamcommunity.com/comment/Profile/post/" + userID.toString() + "/-1",
"form": {
"comment": message,
@@ -139,8 +150,7 @@ SteamCommunity.prototype.postUserComment = function(userID, message, callback) {
return;
}
if (err) {
callback(err);
if(self._checkHttpError(err, response, callback)) {
return;
}
@@ -151,7 +161,7 @@ SteamCommunity.prototype.postUserComment = function(userID, message, callback) {
} else {
callback(new Error("Unknown error"));
}
}, "steamcommunity");
});
};
SteamCommunity.prototype.inviteUserToGroup = function(userID, groupID, callback) {
@@ -160,7 +170,7 @@ SteamCommunity.prototype.inviteUserToGroup = function(userID, groupID, callback)
}
var self = this;
this.httpRequestPost({
this.request.post({
"uri": "https://steamcommunity.com/actions/GroupInvite",
"form": {
"group": groupID.toString(),
@@ -175,8 +185,7 @@ SteamCommunity.prototype.inviteUserToGroup = function(userID, groupID, callback)
return;
}
if (err) {
callback(err);
if(self._checkHttpError(err, response, callback)) {
return;
}
@@ -187,7 +196,7 @@ SteamCommunity.prototype.inviteUserToGroup = function(userID, groupID, callback)
} else {
callback(new Error("Unknown error"));
}
}, "steamcommunity");
});
};
SteamCommunity.prototype.getUserInventoryContexts = function(userID, callback) {
@@ -206,9 +215,8 @@ SteamCommunity.prototype.getUserInventoryContexts = function(userID, callback) {
}
var self = this;
this.httpRequest("https://steamcommunity.com/profiles/" + userID.getSteamID64() + "/inventory/", function(err, response, body) {
if (err) {
callback(err);
this.request("https://steamcommunity.com/profiles/" + userID.getSteamID64() + "/inventory/", function(err, response, body) {
if(self._checkHttpError(err, response, callback)) {
return;
}
@@ -227,7 +235,7 @@ SteamCommunity.prototype.getUserInventoryContexts = function(userID, callback) {
}
callback(null, data);
}, "steamcommunity");
});
};
SteamCommunity.prototype.getUserInventory = function(userID, appID, contextID, tradableOnly, callback) {
@@ -241,7 +249,7 @@ SteamCommunity.prototype.getUserInventory = function(userID, appID, contextID, t
get([], []);
function get(inventory, currency, start) {
self.httpRequest({
self.request({
"uri": "https://steamcommunity.com" + endpoint + "/inventory/json/" + appID + "/" + contextID,
"qs": {
"start": start,
@@ -249,18 +257,12 @@ SteamCommunity.prototype.getUserInventory = function(userID, appID, contextID, t
},
"json": true
}, function(err, response, body) {
if (err) {
callback(err);
if(self._checkHttpError(err, response, callback)) {
return;
}
if(!body || !body.success || !body.rgInventory || !body.rgDescriptions || !body.rgCurrency) {
if(body) {
callback(new Error(body.Error || "Malformed response"));
} else {
callback(new Error("Malformed response"));
}
callback(new Error(body.Error || "Malformed response"));
return;
}
@@ -291,6 +293,6 @@ SteamCommunity.prototype.getUserInventory = function(userID, appID, contextID, t
} else {
callback(null, inventory, currency);
}
}, "steamcommunity");
});
}
};

View File

@@ -2,12 +2,11 @@ var SteamCommunity = require('../index.js');
SteamCommunity.prototype.getWebApiKey = function(domain, callback) {
var self = this;
this.httpRequest({
this.request({
"uri": "https://steamcommunity.com/dev/apikey",
"followRedirect": false
}, function(err, response, body) {
if (err) {
callback(err);
if(self._checkHttpError(err, response, callback)) {
return;
}
@@ -21,7 +20,7 @@ SteamCommunity.prototype.getWebApiKey = function(domain, callback) {
callback(null, match[1]);
} else {
// We need to register a new API key
self.httpRequestPost('https://steamcommunity.com/dev/registerkey', {
self.request.post('https://steamcommunity.com/dev/registerkey', {
"form": {
"domain": domain,
"agreeToTerms": "agreed",
@@ -29,15 +28,14 @@ SteamCommunity.prototype.getWebApiKey = function(domain, callback) {
"Submit": "Register"
}
}, function(err, response, body) {
if (err) {
callback(err);
if(self._checkHttpError(err, response, callback)) {
return;
}
self.getWebApiKey(domain, callback);
}, "steamcommunity");
});
}
}, "steamcommunity");
});
};
SteamCommunity.prototype.getWebApiOauthToken = function(callback) {
@@ -48,9 +46,12 @@ SteamCommunity.prototype.getWebApiOauthToken = function(callback) {
}
// Pull an oauth token from the webchat UI
this.httpRequest("https://steamcommunity.com/chat", function(err, response, body) {
if (err) {
callback(err);
this.request("https://steamcommunity.com/chat", function(err, response, body) {
if(self._checkHttpError(err, response, callback)) {
return;
}
if(self._checkCommunityError(body, callback)) {
return;
}
@@ -61,5 +62,5 @@ SteamCommunity.prototype.getWebApiOauthToken = function(callback) {
}
callback(null, match[1]);
}, "steamcommunity");
});
};

View File

@@ -1,61 +0,0 @@
var SteamCommunity = require('../index.js');
var ReadLine = require('readline');
var fs = require('fs');
var community = new SteamCommunity();
var rl = ReadLine.createInterface({
"input": process.stdin,
"output": process.stdout
});
rl.question("Username: ", function(accountName) {
rl.question("Password: ", function(password) {
rl.question("Two-Factor Auth Code: ", function(authCode) {
rl.question("Revocation Code: R", function(rCode) {
doLogin(accountName, password, authCode, "", rCode);
});
});
});
});
function doLogin(accountName, password, authCode, captcha, rCode) {
community.login({
"accountName": accountName,
"password": password,
"twoFactorCode": authCode,
"captcha": captcha
}, function(err, sessionID, cookies, steamguard) {
if(err) {
if(err.message == 'SteamGuard') {
console.log("This account does not have two-factor authentication enabled.");
process.exit();
return;
}
if(err.message == 'CAPTCHA') {
console.log(err.captchaurl);
rl.question("CAPTCHA: ", function(captchaInput) {
doLogin(accountName, password, authCode, captchaInput);
});
return;
}
console.log(err);
process.exit();
return;
}
console.log("Logged on!");
community.disableTwoFactor("R" + rCode, function(err) {
if(err) {
console.log(err);
process.exit();
return;
}
console.log("Two-factor authentication disabled!");
process.exit();
});
});
}

View File

@@ -14,13 +14,12 @@ rl.question("Username: ", function(accountName) {
});
});
function doLogin(accountName, password, authCode, twoFactorCode, captcha) {
function doLogin(accountName, password, authCode, twoFactorCode) {
community.login({
"accountName": accountName,
"password": password,
"authCode": authCode,
"twoFactorCode": twoFactorCode,
"captcha": captcha
"twoFactorCode": twoFactorCode
}, function(err, sessionID, cookies, steamguard) {
if(err) {
if(err.message == 'SteamGuardMobile') {
@@ -40,15 +39,6 @@ function doLogin(accountName, password, authCode, twoFactorCode, captcha) {
return;
}
if(err.message == 'CAPTCHA') {
console.log(err.captchaurl);
rl.question("CAPTCHA: ", function(captchaInput) {
doLogin(accountName, password, authCode, twoFactorCode, captchaInput);
});
return;
}
console.log(err);
process.exit();
return;

View File

@@ -14,12 +14,11 @@ rl.question("Username: ", function(accountName) {
});
});
function doLogin(accountName, password, authCode, captcha) {
function doLogin(accountName, password, authCode) {
community.login({
"accountName": accountName,
"password": password,
"authCode": authCode,
"captcha": captcha
"authCode": authCode
}, function(err, sessionID, cookies, steamguard) {
if(err) {
if(err.message == 'SteamGuardMobile') {
@@ -30,22 +29,13 @@ function doLogin(accountName, password, authCode, captcha) {
if(err.message == 'SteamGuard') {
console.log("An email has been sent to your address at " + err.emaildomain);
rl.question("Steam Guard Code: ", function (code) {
rl.question("Steam Guard Code: ", function(code) {
doLogin(accountName, password, code);
});
return;
}
if(err.message == 'CAPTCHA') {
console.log(err.captchaurl);
rl.question("CAPTCHA: ", function(captchaInput) {
doLogin(accountName, password, authCode, captchaInput);
});
return;
}
console.log(err);
process.exit();
return;

210
index.js
View File

@@ -16,7 +16,6 @@ function SteamCommunity(options) {
this._jar = Request.jar();
this._captchaGid = -1;
this._httpRequestID = 0;
this.chatState = SteamCommunity.ChatState.Offline;
var defaults = {
@@ -68,75 +67,82 @@ SteamCommunity.prototype.login = function(details, callback) {
this._jar.setCookie(Request.cookie("mobileClientVersion=0 (2.1.3)"), "https://steamcommunity.com");
this._jar.setCookie(Request.cookie("mobileClient=android"), "https://steamcommunity.com");
this.httpRequestPost("https://steamcommunity.com/login/getrsakey/", {
"form": {"username": details.accountName},
"headers": mobileHeaders,
"json": true
this.request.post("https://steamcommunity.com/login/getrsakey/", {
"form": {
"username": details.accountName
},
"headers": mobileHeaders
}, function(err, response, body) {
// Remove the mobile cookies
if (err) {
if(err) {
deleteMobileCookies();
callback(err);
return;
}
var json;
try {
json = JSON.parse(body);
} catch(e) {
deleteMobileCookies();
callback(e);
return;
}
if(!body.publickey_mod || !body.publickey_exp) {
if(!json.publickey_mod || !json.publickey_exp) {
deleteMobileCookies();
callback(new Error("Invalid RSA key received"));
return;
}
var key = new RSA();
key.setPublic(body.publickey_mod, body.publickey_exp);
key.setPublic(json.publickey_mod, json.publickey_exp);
self.httpRequestPost({
var form = {
"captcha_text": details.captcha || "",
"captchagid": self._captchaGid,
"emailauth": details.authCode || "",
"emailsteamid": "",
"password": hex2b64(key.encrypt(details.password)),
"remember_login": "true",
"rsatimestamp": json.timestamp,
"twofactorcode": details.twoFactorCode || "",
"username": details.accountName,
"oauth_client_id": "DE45CD61",
"oauth_scope": "read_profile write_profile read_client write_client",
"loginfriendlyname": "#login_emailauth_friendlyname_mobile"
};
self.request.post({
"uri": "https://steamcommunity.com/login/dologin/",
"json": true,
"form": {
"captcha_text": details.captcha || "",
"captchagid": self._captchaGid,
"emailauth": details.authCode || "",
"emailsteamid": "",
"password": hex2b64(key.encrypt(details.password)),
"remember_login": "true",
"rsatimestamp": body.timestamp,
"twofactorcode": details.twoFactorCode || "",
"username": details.accountName,
"oauth_client_id": "DE45CD61",
"oauth_scope": "read_profile write_profile read_client write_client",
"loginfriendlyname": "#login_emailauth_friendlyname_mobile",
"donotcache": Date.now()
},
"form": form,
"headers": mobileHeaders
}, function(err, response, body) {
deleteMobileCookies();
if (err) {
callback(err);
if(self._checkHttpError(err, response, callback)) {
return;
}
var error;
if(!body.success && body.emailauth_needed) {
// Steam Guard (email)
error = new Error("SteamGuard");
var error = new Error("SteamGuard");
error.emaildomain = body.emaildomain;
callback(error);
} else if(!body.success && body.requires_twofactor) {
// Steam Guard (app)
callback(new Error("SteamGuardMobile"));
} else if(!body.success && body.captcha_needed && body.message.match(/Please verify your humanity/)) {
error = new Error("CAPTCHA");
error.captchaurl = "https://steamcommunity.com/login/rendercaptcha/?gid=" + body.captcha_gid;
} else if(!body.success && body.captcha_needed) {
var error = new Error("CAPTCHA");
error.captchaurl = "https://steamcommunity.com/public/captcha.php?gid=" + body.captcha_gid;
self._captchaGid = body.captcha_gid;
callback(error);
} else if(!body.success) {
callback(new Error(body.message || "Unknown error"));
} else if(!body.oauth) {
callback(new Error("Malformed response"));
} else {
var sessionID = generateSessionID();
var oAuth = JSON.parse( body.oauth );
@@ -161,8 +167,8 @@ SteamCommunity.prototype.login = function(details, callback) {
callback(null, sessionID, cookies, steamguard, oAuth.oauth_token);
}
}, "steamcommunity");
}, "steamcommunity");
});
});
function deleteMobileCookies() {
var cookie = Request.cookie('mobileClientVersion=');
@@ -180,15 +186,14 @@ SteamCommunity.prototype.oAuthLogin = function(steamguard, token, callback) {
var steamID = new SteamID(steamguard[0]);
var self = this;
this.httpRequestPost({
this.request.post({
"uri": "https://api.steampowered.com/IMobileAuthService/GetWGToken/v1/",
"form": {
"access_token": token
},
"json": true
}, function(err, response, body) {
if (err) {
callback(err);
if(self._checkHttpError(err, response, callback)) {
return;
}
@@ -206,7 +211,7 @@ SteamCommunity.prototype.oAuthLogin = function(steamguard, token, callback) {
self.setCookies(cookies);
callback(null, self.getSessionID(), cookies);
}, "steamcommunity");
});
};
SteamCommunity.prototype.setCookies = function(cookies) {
@@ -240,9 +245,7 @@ function generateSessionID() {
}
SteamCommunity.prototype.parentalUnlock = function(pin, callback) {
var self = this;
this.httpRequestPost("https://steamcommunity.com/parental/ajaxunlock", {
this.request.post("https://steamcommunity.com/parental/ajaxunlock", {
"json": true,
"form": {
"pin": pin
@@ -252,30 +255,26 @@ SteamCommunity.prototype.parentalUnlock = function(pin, callback) {
return;
}
if (err) {
callback(err);
if(self._checkHttpError(err, response, callback)) {
return;
}
if(!body || typeof body.success !== 'boolean') {
callback("Invalid response");
return;
return callback("Invalid response");
}
if(!body.success) {
callback("Incorrect PIN");
return;
return callback("Incorrect PIN");
}
callback();
}.bind(this), "steamcommunity");
}.bind(this));
};
SteamCommunity.prototype.getNotifications = function(callback) {
var self = this;
this.httpRequestGet("https://steamcommunity.com/actions/RefreshNotificationArea", function(err, response, body) {
if (err) {
callback(err);
this.request.get("https://steamcommunity.com/actions/RefreshNotificationArea", function(err, response, body) {
if(self._checkHttpError(err, response, callback)) {
return;
}
@@ -305,26 +304,26 @@ SteamCommunity.prototype.getNotifications = function(callback) {
}
callback(null, notifications);
}, "steamcommunity");
});
};
SteamCommunity.prototype.resetItemNotifications = function(callback) {
var self = this;
this.httpRequestGet("https://steamcommunity.com/my/inventory", function(err, response, body) {
this.request.get("https://steamcommunity.com/my/inventory", function(err, response, body) {
if(!callback) {
return;
}
callback(err || null);
}, "steamcommunity");
if(self._checkHttpError(err, response, callback)) {
return;
}
callback(null);
});
};
SteamCommunity.prototype.loggedIn = function(callback) {
this.httpRequestGet({
"uri": "https://steamcommunity.com/my",
"followRedirect": false,
"checkHttpError": false
}, function(err, response, body) {
this.request("https://steamcommunity.com/my", {"followRedirect": false}, function(err, response, body) {
if(err || (response.statusCode != 302 && response.statusCode != 403)) {
callback(err || new Error("HTTP error " + response.statusCode));
return;
@@ -336,52 +335,58 @@ SteamCommunity.prototype.loggedIn = function(callback) {
}
callback(null, !!response.headers.location.match(/steamcommunity\.com(\/(id|profiles)\/[^\/]+)\/?/), false);
}, "steamcommunity");
});
};
SteamCommunity.prototype._checkCommunityError = function(html, callback) {
if(html.match(/<h1>Sorry!<\/h1>/)) {
var match = html.match(/<h3>(.+)<\/h3>/);
callback(new Error(match ? match[1] : "Unknown error occurred"));
return true;
}
return false;
};
SteamCommunity.prototype._myProfile = function(endpoint, form, callback) {
var self = this;
if (this._profileURL) {
completeRequest(this._profileURL);
} else {
this.httpRequest("https://steamcommunity.com/my", {"followRedirect": false}, function(err, response, body) {
if(err || response.statusCode != 302) {
callback(err || "HTTP error " + response.statusCode);
return;
}
var match = response.headers.location.match(/steamcommunity\.com(\/(id|profiles)\/[^\/]+)\/?/);
if(!match) {
callback(new Error("Can't get profile URL"));
return;
}
self._profileURL = match[1];
setTimeout(function () {
delete self._profileURL; // delete the cache
}, 60000);
completeRequest(match[1]);
}, "steamcommunity");
}
function completeRequest(url) {
var options = {
"uri": "https://steamcommunity.com" + url + "/" + endpoint,
"method": "GET"
};
if (form) {
options.method = "POST";
options.form = form;
this.request("https://steamcommunity.com/my", {"followRedirect": false}, function(err, response, body) {
if(err || response.statusCode != 302) {
callback(err || "HTTP error " + response.statusCode);
return;
}
self.httpRequest(options, callback, "steamcommunity");
}
var match = response.headers.location.match(/steamcommunity\.com(\/(id|profiles)\/[^\/]+)\/?/);
if(!match) {
callback(new Error("Can't get profile URL"));
return;
}
(form ? self.request.post : self.request)("https://steamcommunity.com" + match[1] + "/" + endpoint, form ? {"form": form} : {}, callback);
});
};
SteamCommunity.prototype._checkHttpError = function(err, response, callback) {
if(err) {
callback(err);
return true;
}
if(response.statusCode >= 300 && response.statusCode <= 399 && response.headers.location.indexOf('/login') != -1) {
callback(new Error("Not Logged In"));
return true;
}
if(response.statusCode >= 400) {
var error = new Error("HTTP error " + response.statusCode);
error.code = response.statusCode;
callback(error);
return true;
}
return false;
};
require('./components/http.js');
require('./components/chat.js');
require('./components/profile.js');
require('./components/market.js');
@@ -391,6 +396,7 @@ require('./components/inventoryhistory.js');
require('./components/webapi.js');
require('./components/twofactor.js');
require('./components/confirmations.js');
require('./components/discussions.js');
require('./classes/CMarketItem.js');
require('./classes/CMarketSearchResult.js');
require('./classes/CSteamGroup.js');

View File

@@ -1,6 +1,6 @@
{
"name": "steamcommunity",
"version": "3.19.7",
"version": "3.18.5",
"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",
@@ -15,13 +15,10 @@
"dependencies": {
"request": "^2.61.0",
"node-bignumber": "^1.2.1",
"steamid": "^1.0.0",
"steamid": "^0.3.1",
"xml2js": "^0.4.11",
"cheerio": "0.19.0",
"cheerio": "^0.19.0",
"async": "^1.4.2",
"steam-totp": "^1.3.0"
},
"engines": {
"node": ">=4.0.0"
}
}
}