-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.js
100 lines (92 loc) · 2.6 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/** Took some inspiration from Dinnerbone's code (https://gist.github.com/Dinnerbone/fa3152176653398b312e) **/
var http = require('http');
var fs = require("fs");
var config = require('./config.json');
var torAgent = undefined;
if (config.tor) {
var Socks = require('socks');
torAgent = new Socks.Agent({
proxy: {
ipaddress: config.tor && config.tor.host ? config.tor.host : '127.0.0.1',
port: config.tor && config.tor.port ? config.tor.port : 9150,
type: 5,
}
}, false, false);
}
function tryPassword(password, app, callback) {
var req = http.request({
hostname: 'store.steampowered.com',
agent: torAgent,
path: '/actions/clues?key=' + encodeURIComponent(password) + '&_=' + (new Date().getTime()),
headers: {
Referer: 'http://store.steampowered.com/app/' + app + '/'
}
}, function(res) {
res.on('data', function(data) {
req.response = (req.response || '') + data.toString();
}).on('end', function() {
if (res.statusCode !== 200) {
return callback({error: 'Status code !== 200 (' + res.statusCode + '). Rate limited?', response: req.response}, undefined);
}
var result = undefined;
try {
result = JSON.parse(req.response);
if (result && Array.isArray(result) && result.length === 0) {
return callback(undefined, undefined);
} else {
return callback(undefined, result);
}
} catch (e) {
return callback(e, undefined);
}
});
});
req.on('error', function(err) {
setTimeout(function() {
tryPassword(password, app, callback);
}, 2000);
});
req.end();
}
function tryWintercomic(password, callback) {
var req = http.request({
hostname: 'store.steampowered.com',
agent: torAgent,
path: '/wintercomic/' + encodeURIComponent(password)
}, function(res) {
res.on('data', function(data) {
req.response = (req.response || '') + data.toString();
}).on('end', function() {
if (res.statusCode === 200) {
return callback(undefined, undefined);
} else {
return callback(undefined, {
url: res.headers.location ? res.headers.location : undefined,
headers: res.headers,
statusCode: res.statusCode,
body: req.response
});
}
});
});
req.on('error', function(err) {
setTimeout(function() {
tryWintercomic(password, callback);
}, 2000);
});
req.end();
}
function ensureValid(callback) {
tryPassword('94050999014715', 6900, function(err, result) {
if (!err && result && result.response && result.response === 'ic/4f21ca7') {
return callback(true);
} else {
return callback(false);
}
});
}
module.exports = {
tryPassword: tryPassword,
tryWintercomic: tryWintercomic,
ensureValid: ensureValid
};