|
|
|
|
@@ -4,63 +4,55 @@ var SteamTotp = require('steam-totp');
|
|
|
|
|
var Async = require('async');
|
|
|
|
|
|
|
|
|
|
var CConfirmation = require('../classes/CConfirmation.js');
|
|
|
|
|
var EConfirmationType = require('../resources/EConfirmationType.js');
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a list of your account's currently outstanding confirmations.
|
|
|
|
|
* @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 "conf" (this key can be reused)
|
|
|
|
|
* @param {string} key - The confirmation key that was generated using the preceeding time and the tag 'conf' (this key can be reused)
|
|
|
|
|
* @param {SteamCommunity~getConfirmations} callback - Called when the list of confirmations is received
|
|
|
|
|
*/
|
|
|
|
|
SteamCommunity.prototype.getConfirmations = function(time, key, callback) {
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
// Ugly hack to maintain backward compatibility
|
|
|
|
|
var tag = 'conf';
|
|
|
|
|
if (typeof key == 'object') {
|
|
|
|
|
tag = key.tag;
|
|
|
|
|
key = key.key;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The official Steam app uses the tag 'list', but 'conf' still works so let's use that for backward compatibility.
|
|
|
|
|
request(this, 'getlist', key, time, tag, null, true, function(err, body) {
|
|
|
|
|
if (err) {
|
|
|
|
|
callback(err);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var $ = Cheerio.load(body);
|
|
|
|
|
var empty = $('#mobileconf_empty');
|
|
|
|
|
if(empty.length > 0) {
|
|
|
|
|
if(!$(empty).hasClass('mobileconf_done')) {
|
|
|
|
|
// An error occurred
|
|
|
|
|
callback(new Error(empty.find('div:nth-of-type(2)').text()));
|
|
|
|
|
} else {
|
|
|
|
|
callback(null, []);
|
|
|
|
|
if (!body.success) {
|
|
|
|
|
if (body.needauth) {
|
|
|
|
|
var err = new Error('Not Logged In');
|
|
|
|
|
self._notifySessionExpired(err);
|
|
|
|
|
callback(err);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback(new Error(body.message || body.detail || 'Failed to get confirmation list'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We have something to confirm
|
|
|
|
|
var confirmations = $('#mobileconf_list');
|
|
|
|
|
if(!confirmations) {
|
|
|
|
|
callback(new Error("Malformed response"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var confs = [];
|
|
|
|
|
Array.prototype.forEach.call(confirmations.find('.mobileconf_list_entry'), function(conf) {
|
|
|
|
|
conf = $(conf);
|
|
|
|
|
|
|
|
|
|
var img = conf.find('.mobileconf_list_entry_icon img');
|
|
|
|
|
confs.push(new CConfirmation(self, {
|
|
|
|
|
"id": conf.data('confid'),
|
|
|
|
|
"type": conf.data('type'),
|
|
|
|
|
"creator": conf.data('creator'),
|
|
|
|
|
"key": conf.data('key'),
|
|
|
|
|
"title": conf.find('.mobileconf_list_entry_description>div:nth-of-type(1)').text().trim(),
|
|
|
|
|
"receiving": conf.find('.mobileconf_list_entry_description>div:nth-of-type(2)').text().trim(),
|
|
|
|
|
"time": conf.find('.mobileconf_list_entry_description>div:nth-of-type(3)').text().trim(),
|
|
|
|
|
"icon": img.length < 1 ? '' : $(img).attr('src')
|
|
|
|
|
}));
|
|
|
|
|
});
|
|
|
|
|
var confs = (body.conf || []).map(conf => new CConfirmation(self, {
|
|
|
|
|
id: conf.id,
|
|
|
|
|
type: conf.type,
|
|
|
|
|
creator: conf.creator_id,
|
|
|
|
|
key: conf.nonce,
|
|
|
|
|
title: `${conf.type_name || 'Confirm'} - ${conf.headline || ''}`,
|
|
|
|
|
receiving: conf.type == EConfirmationType.Trade ? ((conf.summary || [])[1] || '') : '',
|
|
|
|
|
sending: (conf.summary || [])[0] || '',
|
|
|
|
|
time: (new Date(conf.creation_time * 1000)).toISOString(), // for backward compatibility
|
|
|
|
|
timestamp: new Date(conf.creation_time * 1000),
|
|
|
|
|
icon: conf.icon || ''
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
callback(null, confs);
|
|
|
|
|
});
|
|
|
|
|
@@ -76,22 +68,23 @@ SteamCommunity.prototype.getConfirmations = function(time, key, callback) {
|
|
|
|
|
* Get the trade offer ID associated with a particular confirmation
|
|
|
|
|
* @param {int} confID - The ID of the confirmation in question
|
|
|
|
|
* @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 "details" (this key can be reused)
|
|
|
|
|
* @param {string} key - The confirmation key that was generated using the preceeding time and the tag "detail" (this key can be reused)
|
|
|
|
|
* @param {SteamCommunity~getConfirmationOfferID} callback
|
|
|
|
|
*/
|
|
|
|
|
SteamCommunity.prototype.getConfirmationOfferID = function(confID, time, key, callback) {
|
|
|
|
|
request(this, "details/" + confID, key, time, "details", null, true, function(err, body) {
|
|
|
|
|
if(err) {
|
|
|
|
|
// The official Steam app uses the tag 'detail', but 'details' still works so let's use that for backward compatibility
|
|
|
|
|
request(this, 'detailspage/' + confID, key, time, 'details', null, false, function(err, body) {
|
|
|
|
|
if (err) {
|
|
|
|
|
callback(err);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!body.success) {
|
|
|
|
|
if (typeof body != 'string') {
|
|
|
|
|
callback(new Error("Cannot load confirmation details"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var $ = Cheerio.load(body.html);
|
|
|
|
|
var $ = Cheerio.load(body);
|
|
|
|
|
var offer = $('.tradeoffer');
|
|
|
|
|
if(offer.length < 1) {
|
|
|
|
|
callback(null, null);
|
|
|
|
|
@@ -118,31 +111,39 @@ SteamCommunity.prototype.getConfirmationOfferID = function(confID, time, key, ca
|
|
|
|
|
* @param {SteamCommunity~genericErrorCallback} callback - Called when the request is complete
|
|
|
|
|
*/
|
|
|
|
|
SteamCommunity.prototype.respondToConfirmation = function(confID, confKey, time, key, accept, callback) {
|
|
|
|
|
request(this, (confID instanceof Array) ? "multiajaxop" : "ajaxop", key, time, accept ? "allow" : "cancel", {
|
|
|
|
|
"op": accept ? "allow" : "cancel",
|
|
|
|
|
"cid": confID,
|
|
|
|
|
"ck": confKey
|
|
|
|
|
// Ugly hack to maintain backward compatibility
|
|
|
|
|
var tag = accept ? 'allow' : 'cancel';
|
|
|
|
|
if (typeof key == 'object') {
|
|
|
|
|
tag = key.tag;
|
|
|
|
|
key = key.key;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The official app uses tags reject/accept, but cancel/allow still works so use these for backward compatibility
|
|
|
|
|
request(this, (confID instanceof Array) ? 'multiajaxop' : 'ajaxop', key, time, tag, {
|
|
|
|
|
op: accept ? 'allow' : 'cancel',
|
|
|
|
|
cid: confID,
|
|
|
|
|
ck: confKey
|
|
|
|
|
}, true, function(err, body) {
|
|
|
|
|
if(!callback) {
|
|
|
|
|
if (!callback) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
callback(err);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(body.success) {
|
|
|
|
|
if (body.success) {
|
|
|
|
|
callback(null);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(body.message) {
|
|
|
|
|
if (body.message) {
|
|
|
|
|
callback(new Error(body.message));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback(new Error("Could not act on confirmation"));
|
|
|
|
|
callback(new Error('Could not act on confirmation'));
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
@@ -179,7 +180,8 @@ SteamCommunity.prototype.acceptConfirmationForObject = function(identitySecret,
|
|
|
|
|
function doConfirmation() {
|
|
|
|
|
var offset = self._timeOffset;
|
|
|
|
|
var time = SteamTotp.time(offset);
|
|
|
|
|
self.getConfirmations(time, SteamTotp.getConfirmationKey(identitySecret, time, "conf"), function(err, confs) {
|
|
|
|
|
var confKey = SteamTotp.getConfirmationKey(identitySecret, time, 'list');
|
|
|
|
|
self.getConfirmations(time, {tag: 'list', key: confKey}, function(err, confs) {
|
|
|
|
|
if (err) {
|
|
|
|
|
callback(err);
|
|
|
|
|
return;
|
|
|
|
|
@@ -187,7 +189,7 @@ SteamCommunity.prototype.acceptConfirmationForObject = function(identitySecret,
|
|
|
|
|
|
|
|
|
|
var conf = confs.filter(function(conf) { return conf.creator == objectID; });
|
|
|
|
|
if (conf.length == 0) {
|
|
|
|
|
callback(new Error("Could not find confirmation for object " + objectID));
|
|
|
|
|
callback(new Error('Could not find confirmation for object ' + objectID));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -204,7 +206,8 @@ SteamCommunity.prototype.acceptConfirmationForObject = function(identitySecret,
|
|
|
|
|
self._usedConfTimes.splice(0, self._usedConfTimes.length - 60); // we don't need to save more than 60 entries
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
conf.respond(time, SteamTotp.getConfirmationKey(identitySecret, time, "allow"), true, callback);
|
|
|
|
|
confKey = SteamTotp.getConfirmationKey(identitySecret, time, 'accept');
|
|
|
|
|
conf.respond(time, {tag: 'accept', key: confKey}, true, callback);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
@@ -244,7 +247,7 @@ SteamCommunity.prototype.acceptAllConfirmations = function(time, confKey, allowK
|
|
|
|
|
|
|
|
|
|
function request(community, url, key, time, tag, params, json, callback) {
|
|
|
|
|
if (!community.steamID) {
|
|
|
|
|
throw new Error("Must be logged in before trying to do anything with confirmations");
|
|
|
|
|
throw new Error('Must be logged in before trying to do anything with confirmations');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
params = params || {};
|
|
|
|
|
@@ -252,16 +255,16 @@ function request(community, url, key, time, tag, params, json, callback) {
|
|
|
|
|
params.a = community.steamID.getSteamID64();
|
|
|
|
|
params.k = key;
|
|
|
|
|
params.t = time;
|
|
|
|
|
params.m = "android";
|
|
|
|
|
params.m = 'react';
|
|
|
|
|
params.tag = tag;
|
|
|
|
|
|
|
|
|
|
var req = {
|
|
|
|
|
"method": url == 'multiajaxop' ? 'POST' : 'GET',
|
|
|
|
|
"uri": "https://steamcommunity.com/mobileconf/" + url,
|
|
|
|
|
"json": !!json
|
|
|
|
|
method: url == 'multiajaxop' ? 'POST' : 'GET',
|
|
|
|
|
uri: 'https://steamcommunity.com/mobileconf/' + url,
|
|
|
|
|
json: !!json
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (req.method == "GET") {
|
|
|
|
|
if (req.method == 'GET') {
|
|
|
|
|
req.qs = params;
|
|
|
|
|
} else {
|
|
|
|
|
req.form = params;
|
|
|
|
|
@@ -274,7 +277,7 @@ function request(community, url, key, time, tag, params, json, callback) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback(null, body);
|
|
|
|
|
}, "steamcommunity");
|
|
|
|
|
}, 'steamcommunity');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Confirmation checker
|
|
|
|
|
|