mirror of
https://github.com/DoctorMcKay/node-steamcommunity.git
synced 2026-08-19 21:23:28 +08:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dd638df118 | ||
|
|
b937a05442 | ||
|
|
9c34d18cd9 | ||
|
|
02e3798124 | ||
|
|
5d9922cc33 | ||
|
|
153011e1c9 | ||
|
|
575c196cb7 | ||
|
|
47a24d19cf |
@@ -1,7 +1,7 @@
|
||||
module.exports = CConfirmation;
|
||||
|
||||
function CConfirmation(community, data) {
|
||||
this._community = community;
|
||||
Object.defineProperty(this, "_community", {"value": community});
|
||||
|
||||
this.id = data.id;
|
||||
this.key = data.key;
|
||||
|
||||
@@ -84,7 +84,8 @@ SteamCommunity.prototype.chatLogon = function(interval, uiMode) {
|
||||
"umqid": body.umqid,
|
||||
"message": body.message,
|
||||
"accessToken": token,
|
||||
"interval": interval
|
||||
"interval": interval,
|
||||
"uiMode": uiMode
|
||||
};
|
||||
|
||||
self.chatFriends = {};
|
||||
@@ -188,11 +189,19 @@ SteamCommunity.prototype._chatPoll = function() {
|
||||
|
||||
if(err || response.statusCode != 200) {
|
||||
self.emit('debug', 'Error in chat poll: ' + (err ? err.message : "HTTP error " + response.statusCode));
|
||||
if (err.message == "Not Logged On") {
|
||||
self._relogWebChat();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(!body || body.error != 'OK') {
|
||||
self.emit('debug', 'Error in chat poll: ' + (body && body.error ? body.error : "Malformed response"));
|
||||
if (body && body.error && body.error == "Not Logged On") {
|
||||
self._relogWebChat();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -225,6 +234,13 @@ SteamCommunity.prototype._chatPoll = function() {
|
||||
}, "steamcommunity");
|
||||
};
|
||||
|
||||
SteamCommunity.prototype._relogWebChat = function() {
|
||||
this.emit('debug', "Relogging web chat");
|
||||
clearTimeout(this._chat.timer);
|
||||
this.chatState = SteamCommunity.ChatState.Offline;
|
||||
this.chatLogon(this._chat.interval, this._chat.uiMode);
|
||||
};
|
||||
|
||||
SteamCommunity.prototype._chatUpdatePersona = function(steamID) {
|
||||
this.emit('debug', 'Updating persona data for ' + steamID);
|
||||
var self = this;
|
||||
|
||||
@@ -108,15 +108,15 @@ SteamCommunity.prototype.getConfirmationOfferID = function(confID, time, key, ca
|
||||
|
||||
/**
|
||||
* Confirm or cancel a given confirmation.
|
||||
* @param {int} confID - The ID of the confirmation in question
|
||||
* @param {string} confKey - The confirmation key associated with the confirmation in question (not a TOTP key, the `key` property of CConfirmation)
|
||||
* @param {int|int[]} confID - The ID of the confirmation in question, or an array of confirmation IDs
|
||||
* @param {string|string[]} confKey - The confirmation key associated with the confirmation in question (or an array of them) (not a TOTP key, the `key` property of CConfirmation)
|
||||
* @param {int} time - The unix timestamp with which the following key was generated
|
||||
* @param {string} key - The confirmation key that was generated using the preceeding time and the tag "allow" (if accepting) or "cancel" (if not accepting)
|
||||
* @param {boolean} accept - true if you want to accept the confirmation, false if you want to cancel it
|
||||
* @param {SteamCommunity~genericErrorCallback} callback - Called when the request is complete
|
||||
*/
|
||||
SteamCommunity.prototype.respondToConfirmation = function(confID, confKey, time, key, accept, callback) {
|
||||
request(this, "ajaxop", key, time, accept ? "allow" : "cancel", {
|
||||
request(this, (confID instanceof Array) ? "multiajaxop" : "ajaxop", key, time, accept ? "allow" : "cancel", {
|
||||
"op": accept ? "allow" : "cancel",
|
||||
"cid": confID,
|
||||
"ck": confKey
|
||||
@@ -144,6 +144,31 @@ SteamCommunity.prototype.respondToConfirmation = function(confID, confKey, time,
|
||||
});
|
||||
};
|
||||
|
||||
SteamCommunity.prototype.acceptAllConfirmations = function(time, confKey, allowKey, callback) {
|
||||
var self = this;
|
||||
|
||||
this.getConfirmations(time, confKey, function(err, confs) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (confs.length == 0) {
|
||||
callback(null, []);
|
||||
return;
|
||||
}
|
||||
|
||||
self.respondToConfirmation(confs.map(function(conf) { return conf.id; }), confs.map(function(conf) { return conf.key; }), time, allowKey, true, function(err) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
callback(err, confs);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
function request(community, url, key, time, tag, params, json, callback) {
|
||||
params = params || {};
|
||||
params.p = SteamTotp.getDeviceID(community.steamID);
|
||||
@@ -153,11 +178,19 @@ function request(community, url, key, time, tag, params, json, callback) {
|
||||
params.m = "android";
|
||||
params.tag = tag;
|
||||
|
||||
community.httpRequestGet({
|
||||
var req = {
|
||||
"method": url == 'multiajaxop' ? 'POST' : 'GET',
|
||||
"uri": "https://steamcommunity.com/mobileconf/" + url,
|
||||
"qs": params,
|
||||
"json": !!json
|
||||
}, function(err, response, body) {
|
||||
};
|
||||
|
||||
if (req.method == "GET") {
|
||||
req.qs = params;
|
||||
} else {
|
||||
req.form = params;
|
||||
}
|
||||
|
||||
community.httpRequest(req, function(err, response, body) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
|
||||
@@ -50,16 +50,22 @@ SteamCommunity.prototype.httpRequest = function(uri, options, callback, source)
|
||||
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
|
||||
var jsonError = options.json && !body ? new Error("Malformed JSON response") : null;
|
||||
|
||||
self.emit('postHttpRequest', requestID, source, options, httpError || communityError || tradeError || null, response, body, {
|
||||
self.emit('postHttpRequest', requestID, source, options, httpError || communityError || tradeError || jsonError || null, response, body, {
|
||||
"hasCallback": hasCallback,
|
||||
"httpError": httpError,
|
||||
"communityError": communityError,
|
||||
"tradeError": tradeError
|
||||
"tradeError": tradeError,
|
||||
"jsonError": jsonError
|
||||
});
|
||||
|
||||
if(hasCallback && !(httpError || communityError || tradeError)) {
|
||||
callback.apply(self, arguments);
|
||||
if (hasCallback) {
|
||||
if (jsonError) {
|
||||
callback.call(self, jsonError, response);
|
||||
} else if (!(httpError || communityError || tradeError)) {
|
||||
callback.apply(self, arguments);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "steamcommunity",
|
||||
"version": "3.22.0",
|
||||
"version": "3.23.2",
|
||||
"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",
|
||||
|
||||
Reference in New Issue
Block a user