Add counts to the serverList output

This commit is contained in:
Christopher Cookman 2022-11-23 11:08:19 -07:00
parent 44a52d2ba8
commit 7922796b7d
Signed by: ChrisChrome
GPG key ID: A023A26E42C33A42

View file

@ -59,6 +59,16 @@ function checkVersion(version) {
}
};
function objectLength(object) {
var length = 0;
for (var key in object) {
if (object.hasOwnProperty(key)) {
++length;
}
}
return length;
};
// checkServer function
function checkServer(address) {
Steam.queryGameServerInfo(address).then(data => {
@ -198,6 +208,8 @@ app.get('/check', (req, res) => {
// });
app.get('/serverList', (req, res) => {
serverList.serverCount = objectLength(serverList.servers);
serverList.erroredCount = objectLength(serverList.errored);
res.setHeader("Content-Type", "application/json").send(JSON.stringify(serverList));
});
@ -212,4 +224,4 @@ app.get('/', (req, res) => {
});
app.listen(port, () => console.log(`Listening on port ${port}!`));
app.listen(port, () => console.log(`Listening on port ${port}!`));