Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
77 lines (66 loc) · 2.06 KB
/
Copy pathindex.js
File metadata and controls
77 lines (66 loc) · 2.06 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
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
const exec = require("child_process").exec;
const vdf = require('vdf');
const express = require('express');
const app = express();
const port = 3000;
const regex = new RegExp(/AppID\s+:\s+\d+,\s+change\s+number\s+:\s+\d+\/\d+,\s+last\s+change\s+:\s+\w+\s+\w+\s+\d+\s+\d+:\d+:\d+\s+\d+\s+([\W\w]+).*/);
let steamCmdProcess;
function updateSteamInfo() {
if (steamCmdProcess && !steamCmdProcess.killed) {
steamCmdProcess.kill();
}
steamCmdProcess = exec("/home/steam/steamcmd/steamcmd.sh +login anonymous +app_info_print 258550 +exit");
steamCmdProcess.stdin.setEncoding('utf-8');
steamCmdProcess.stdout.on('data', chunk => outputBuffer.push(chunk.toString()));
steamCmdProcess.on('exit', (code, signal) => {
LogMessage(`Steam Exited: ${code} ${signal}`);
parseOutput();
setTimeout(updateSteamInfo, 15000);
});
}
let outputBuffer = [];
let parseString = "";
let lastUpdateInfo = {};
function parseOutput() {
parseString = outputBuffer.join(' ');
outputBuffer.length = 0;
let matches = parseString.match(regex);
if (matches && matches.length > 1) {
LogMessage("Matched Regex");
try {
lastUpdateInfo = vdf.parse(matches[1]);
LogMessage("Updated Info");
} catch (e) {
console.error(e);
}
}
}
function LogMessage(message) {
const date = new Date();
console.log('[' + date.toISOString() + '] ' + message);
}
app.listen(port, function () {
LogMessage("HTTP Server is running on " + port + " port");
updateSteamInfo();
});
app.use(function (err, req, res, next) {
console.error(err.stack);
res.status(500).send();
})
app.get('/', function (req, res) {
res.json(lastUpdateInfo);
});
app.get('/public', function (req, res) {
try {
res.json(lastUpdateInfo["258550"]["depots"]["branches"]["public"]);
} catch {
res.status(500);
}
});
app.get('/staging', function (req, res) {
try {
res.json(lastUpdateInfo["258550"]["depots"]["branches"]["staging"]);
} catch {
res.status(500);
}
});