forked from DoctorMcKay/node-steam-user
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprepublish.js
More file actions
40 lines (32 loc) · 1.2 KB
/
prepublish.js
File metadata and controls
40 lines (32 loc) · 1.2 KB
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
// This file is run by npm prior to the package being published to the registry
// Update the CM list
download("https://api.steampowered.com/ISteamDirectory/GetCMList/v1/?format=json&cellid=0", function(data) {
var json = JSON.parse(data);
if (!json.response || json.response.result != 1) {
throw new Error("Cannot get CM list");
}
var servers = {
"tcp_servers": json.response.serverlist,
"websocket_servers": json.response.serverlist_websockets,
"time": Date.now()
};
console.log("Got list of " + servers.tcp_servers.length + " TCP CMs and " + servers.websocket_servers.length + " WebSocket CMs from WebAPI");
require('fs').writeFileSync(__dirname + '/../resources/servers.json', JSON.stringify(servers, null, "\t"));
});
// Helper functions
function download(url, callback) {
var reqData = require('url').parse(url);
reqData.servername = reqData.hostname;
reqData.headers = {"User-Agent": "node-steam-user data parser"};
reqData.method = "GET";
// This will crash if there's an error. But that's fine.
require('https').request(reqData, function(res) {
var data = "";
res.on('data', function(chunk) {
data += chunk;
});
res.on('end', function() {
callback(data);
});
}).end();
}