So, I forgot to commit the entire time I was working on this
This commit is contained in:
parent
15de9151ee
commit
0b5509b3de
130
.gitignore
vendored
Normal file
130
.gitignore
vendored
Normal file
|
@ -0,0 +1,130 @@
|
||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
.pnpm-debug.log*
|
||||||
|
|
||||||
|
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||||
|
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||||
|
|
||||||
|
# Runtime data
|
||||||
|
pids
|
||||||
|
*.pid
|
||||||
|
*.seed
|
||||||
|
*.pid.lock
|
||||||
|
|
||||||
|
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||||
|
lib-cov
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
coverage
|
||||||
|
*.lcov
|
||||||
|
|
||||||
|
# nyc test coverage
|
||||||
|
.nyc_output
|
||||||
|
|
||||||
|
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||||
|
.grunt
|
||||||
|
|
||||||
|
# Bower dependency directory (https://bower.io/)
|
||||||
|
bower_components
|
||||||
|
|
||||||
|
# node-waf configuration
|
||||||
|
.lock-wscript
|
||||||
|
|
||||||
|
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||||
|
build/Release
|
||||||
|
|
||||||
|
# Dependency directories
|
||||||
|
node_modules/
|
||||||
|
jspm_packages/
|
||||||
|
|
||||||
|
# Snowpack dependency directory (https://snowpack.dev/)
|
||||||
|
web_modules/
|
||||||
|
|
||||||
|
# TypeScript cache
|
||||||
|
*.tsbuildinfo
|
||||||
|
|
||||||
|
# Optional npm cache directory
|
||||||
|
.npm
|
||||||
|
|
||||||
|
# Optional eslint cache
|
||||||
|
.eslintcache
|
||||||
|
|
||||||
|
# Optional stylelint cache
|
||||||
|
.stylelintcache
|
||||||
|
|
||||||
|
# Microbundle cache
|
||||||
|
.rpt2_cache/
|
||||||
|
.rts2_cache_cjs/
|
||||||
|
.rts2_cache_es/
|
||||||
|
.rts2_cache_umd/
|
||||||
|
|
||||||
|
# Optional REPL history
|
||||||
|
.node_repl_history
|
||||||
|
|
||||||
|
# Output of 'npm pack'
|
||||||
|
*.tgz
|
||||||
|
|
||||||
|
# Yarn Integrity file
|
||||||
|
.yarn-integrity
|
||||||
|
|
||||||
|
# dotenv environment variable files
|
||||||
|
.env
|
||||||
|
.env.development.local
|
||||||
|
.env.test.local
|
||||||
|
.env.production.local
|
||||||
|
.env.local
|
||||||
|
|
||||||
|
# parcel-bundler cache (https://parceljs.org/)
|
||||||
|
.cache
|
||||||
|
.parcel-cache
|
||||||
|
|
||||||
|
# Next.js build output
|
||||||
|
.next
|
||||||
|
out
|
||||||
|
|
||||||
|
# Nuxt.js build / generate output
|
||||||
|
.nuxt
|
||||||
|
dist
|
||||||
|
|
||||||
|
# Gatsby files
|
||||||
|
.cache/
|
||||||
|
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||||
|
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||||
|
# public
|
||||||
|
|
||||||
|
# vuepress build output
|
||||||
|
.vuepress/dist
|
||||||
|
|
||||||
|
# vuepress v2.x temp and cache directory
|
||||||
|
.temp
|
||||||
|
.cache
|
||||||
|
|
||||||
|
# Docusaurus cache and generated files
|
||||||
|
.docusaurus
|
||||||
|
|
||||||
|
# Serverless directories
|
||||||
|
.serverless/
|
||||||
|
|
||||||
|
# FuseBox cache
|
||||||
|
.fusebox/
|
||||||
|
|
||||||
|
# DynamoDB Local files
|
||||||
|
.dynamodb/
|
||||||
|
|
||||||
|
# TernJS port file
|
||||||
|
.tern-port
|
||||||
|
|
||||||
|
# Stores VSCode versions used for testing VSCode extensions
|
||||||
|
.vscode-test
|
||||||
|
|
||||||
|
# yarn v2
|
||||||
|
.yarn/cache
|
||||||
|
.yarn/unplugged
|
||||||
|
.yarn/build-state.yml
|
||||||
|
.yarn/install-state.gz
|
||||||
|
.pnp.*
|
215
index.js
Normal file
215
index.js
Normal file
|
@ -0,0 +1,215 @@
|
||||||
|
const Steam = require("steam-server-query")
|
||||||
|
const express = require('express');
|
||||||
|
const colors = require("colors");
|
||||||
|
const app = express();
|
||||||
|
const port = 3004;
|
||||||
|
|
||||||
|
BigInt.prototype.toJSON = function () {
|
||||||
|
return this.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
var removeDuplicates = function (nums) {
|
||||||
|
let length = nums.length;
|
||||||
|
for (let i = length - 1; i >= 0; i--) {
|
||||||
|
for (let j = i - 1; j >= 0; j--) {
|
||||||
|
if (nums[i] == nums[j]) {
|
||||||
|
nums.splice(j, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nums;
|
||||||
|
};
|
||||||
|
servers = [];
|
||||||
|
|
||||||
|
// Keyword split to version, dlcs, tps
|
||||||
|
function splitKeyword(keyword) {
|
||||||
|
data = keyword.split("-")
|
||||||
|
switch (data[1]) {
|
||||||
|
case "0":
|
||||||
|
dlcString = "None"
|
||||||
|
break;
|
||||||
|
case "1":
|
||||||
|
dlcString = "Weapons"
|
||||||
|
break;
|
||||||
|
case "2":
|
||||||
|
dlcString = "Arid"
|
||||||
|
break;
|
||||||
|
case "3":
|
||||||
|
dlcString = "Both"
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
"version": data[0],
|
||||||
|
dlcString,
|
||||||
|
dlc: data[1],
|
||||||
|
"tps": data[2]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const latestVer = "v1.6.7"
|
||||||
|
|
||||||
|
// Check version and set console log color if outdated
|
||||||
|
function checkVersion(version) {
|
||||||
|
if (version == latestVer) {
|
||||||
|
return colors.green(version)
|
||||||
|
} else {
|
||||||
|
return colors.red(version)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// checkServer function
|
||||||
|
function checkServer(address) {
|
||||||
|
Steam.queryGameServerInfo(address).then(data => {
|
||||||
|
data.keywords.split("-")
|
||||||
|
data.address = address.split(":");
|
||||||
|
data.serverInfo = splitKeyword(data.keywords);
|
||||||
|
|
||||||
|
output = {
|
||||||
|
"name": data.name,
|
||||||
|
"address": data.address[0],
|
||||||
|
"port": data.address[1],
|
||||||
|
"version": data.serverInfo.version,
|
||||||
|
"dlc": data.serverInfo.dlc,
|
||||||
|
"dlcString": data.serverInfo.dlcString,
|
||||||
|
"tps": data.serverInfo.tps,
|
||||||
|
"players": data.bots,
|
||||||
|
"maxPlayers": data.maxPlayers,
|
||||||
|
"map": data.map,
|
||||||
|
"gameId": data.gameId,
|
||||||
|
"lastUpdated": new Date()
|
||||||
|
}
|
||||||
|
serverList.servers[address] = output;
|
||||||
|
return output;
|
||||||
|
}).catch((err) => {
|
||||||
|
output = {
|
||||||
|
"error": "Could not connect to server",
|
||||||
|
"name": "Unknown",
|
||||||
|
"address": address.split(":")[0],
|
||||||
|
"port": address.split(":")[1],
|
||||||
|
"version": "Unknown",
|
||||||
|
"dlc": null,
|
||||||
|
"dlcString": "Unknown",
|
||||||
|
"tps": 0,
|
||||||
|
"players": 0,
|
||||||
|
"maxPlayers": 0,
|
||||||
|
"map": "Unknown",
|
||||||
|
"gameId": "573090"
|
||||||
|
}
|
||||||
|
serverList.errored[address] = output;
|
||||||
|
return output;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var masterList = {
|
||||||
|
lastUpdated: new Date(),
|
||||||
|
servers: []
|
||||||
|
};
|
||||||
|
|
||||||
|
var serverList = {
|
||||||
|
lastUpdated: new Date(),
|
||||||
|
servers: {},
|
||||||
|
errored: {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// updateMasterList function
|
||||||
|
function updateMasterList() {
|
||||||
|
// Get master list
|
||||||
|
console.log(`${colors.cyan(`[INFO ${new Date()}]`)} Getting master list...`);
|
||||||
|
Steam.queryMasterServer('hl2master.steampowered.com:27011', Steam.REGIONS.ALL, {
|
||||||
|
appid: 573090,
|
||||||
|
game: "Stormworks",
|
||||||
|
}, 1000, 400).then(servers => {
|
||||||
|
servers = removeDuplicates(servers);
|
||||||
|
console.log(`${colors.cyan(`[INFO ${new Date()}]`)} Got master list!`);
|
||||||
|
masterList.servers = servers;
|
||||||
|
masterList.lastUpdated = new Date();
|
||||||
|
updateServerList();
|
||||||
|
}).catch((err) => {
|
||||||
|
console.log(`${colors.red(`[ERROR ${new Date()}]`)} Error updating master list: ${err}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// updateServerList function
|
||||||
|
function updateServerList() {
|
||||||
|
// Get every server in master list
|
||||||
|
console.log(`${colors.cyan(`[INFO ${new Date()}]`)} Getting server list...`);
|
||||||
|
for (let i = 0; i < masterList.servers.length; i++) {
|
||||||
|
// Get server info
|
||||||
|
checkServer(masterList.servers[i]);
|
||||||
|
serverList.lastUpdated = new Date();
|
||||||
|
}
|
||||||
|
console.log(`${colors.cyan(`[INFO ${new Date()}]`)} Got server list!`);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Update master list every 5 minutes
|
||||||
|
setInterval(updateMasterList, 30 * 1000);
|
||||||
|
updateMasterList();
|
||||||
|
|
||||||
|
app.get('/check', (req, res) => {
|
||||||
|
// Check that all required parameters are present
|
||||||
|
if (!req.query.address) {
|
||||||
|
res.send({
|
||||||
|
"error": "Missing required parameter: address"
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
// Regex for IP address : port
|
||||||
|
const ipRegex = /(?:[0-9]{1,3}\.){3}[0-9]{1,3}:[0-9]{1,5}/;
|
||||||
|
// Check ip argument is valid
|
||||||
|
if (ipRegex.test(req.query.address)) {
|
||||||
|
console.log(`${colors.cyan(`[INFO ${new Date()}]`)} ${req.headers["user-agent"]}@${req.ip} requested check server ${req.query.address}`);
|
||||||
|
console.log(`${colors.cyan(`[INFO ${new Date()}]`)} Checking server ${req.query.address}`);
|
||||||
|
Steam.queryGameServerInfo(req.query.address).then(data => {
|
||||||
|
data.keywords.split("-")
|
||||||
|
data.address = req.query.address.split(":");
|
||||||
|
data.serverInfo = splitKeyword(data.keywords);
|
||||||
|
|
||||||
|
output = {
|
||||||
|
"name": data.name,
|
||||||
|
"address": data.address[0],
|
||||||
|
"port": data.address[1],
|
||||||
|
"version": data.serverInfo.version,
|
||||||
|
"dlc": data.serverInfo.dlc,
|
||||||
|
"dlcString": data.serverInfo.dlcString,
|
||||||
|
"tps": data.serverInfo.tps,
|
||||||
|
"players": data.bots,
|
||||||
|
"maxPlayers": data.maxPlayers,
|
||||||
|
"map": data.map,
|
||||||
|
"gameId": data.gameId,
|
||||||
|
"lastUpdated": new Date()
|
||||||
|
}
|
||||||
|
serverList.servers[req.query.address] = output;
|
||||||
|
res.setHeader("Content-Type", "application/json").send(JSON.stringify(output));
|
||||||
|
}).catch(err => {
|
||||||
|
console.log(err)
|
||||||
|
res.status(500).send(`Could not query server: ${err}`);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
res.status(400).send("Invalid Server Address, must be in the format IP:PORT")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/masterList', (req, res) => {
|
||||||
|
res.setHeader("Content-Type", "application/json").send(JSON.stringify(masterList));
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/serverList', (req, res) => {
|
||||||
|
res.setHeader("Content-Type", "application/json").send(JSON.stringify(serverList));
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/', (req, res) => {
|
||||||
|
// Send list of all endpoints
|
||||||
|
res.setHeader("Content-Type", "application/json").send(JSON.stringify({
|
||||||
|
"endpoints": [
|
||||||
|
"/check?address=IP:PORT",
|
||||||
|
"/masterList",
|
||||||
|
"/serverList"
|
||||||
|
]
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
app.listen(port, () => console.log(`Listening on port ${port}!`));
|
1043
package-lock.json
generated
Normal file
1043
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -7,5 +7,10 @@
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC"
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"colors": "^1.4.0",
|
||||||
|
"express": "^4.18.2",
|
||||||
|
"steam-server-query": "^1.1.3"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
1
servers.json
Normal file
1
servers.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
[]
|
89
test.js
Normal file
89
test.js
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
const Steam = require("steam-server-query")
|
||||||
|
const colors = require("colors");
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
var removeDuplicates = function (nums) {
|
||||||
|
let length = nums.length;
|
||||||
|
for (let i = length - 1; i >= 0; i--) {
|
||||||
|
for (let j = i - 1; j >= 0; j--) {
|
||||||
|
if (nums[i] == nums[j]) {
|
||||||
|
nums.splice(j, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nums;
|
||||||
|
};
|
||||||
|
servers = [];
|
||||||
|
|
||||||
|
// Keyword split to version, dlcs, tps
|
||||||
|
function splitKeyword(keyword) {
|
||||||
|
data = keyword.split("-")
|
||||||
|
switch (data[1]) {
|
||||||
|
case "0":
|
||||||
|
dlcString = "None"
|
||||||
|
break;
|
||||||
|
case "1":
|
||||||
|
dlcString = "Weapons"
|
||||||
|
break;
|
||||||
|
case "2":
|
||||||
|
dlcString = "Arid"
|
||||||
|
break;
|
||||||
|
case "3":
|
||||||
|
dlcString = "Both"
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return {"version": data[0], dlcString, dlc: data[1] ,"tps": data[2]}
|
||||||
|
};
|
||||||
|
|
||||||
|
const latestVer ="v1.6.7"
|
||||||
|
|
||||||
|
// Check version and set console log color if outdated
|
||||||
|
function checkVersion(version) {
|
||||||
|
if (version == latestVer) {
|
||||||
|
return colors.green(version)
|
||||||
|
} else {
|
||||||
|
return colors.red(version)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Color Server TPS
|
||||||
|
function colorTPS(tps) {
|
||||||
|
if (tps < 45) {
|
||||||
|
return colors.red(tps)
|
||||||
|
} else if (tps > 40 && tps < 60) {
|
||||||
|
return colors.yellow(tps)
|
||||||
|
} else if (tps > 65) {
|
||||||
|
return colors.magenta(tps)
|
||||||
|
} else {
|
||||||
|
return colors.green(tps)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Steam.queryMasterServer('hl2master.steampowered.com:27011', Steam.REGIONS.ALL, {
|
||||||
|
appid: 573090,
|
||||||
|
game: "Stormworks",
|
||||||
|
}, 1000, 400).then(servers => {
|
||||||
|
servers = removeDuplicates(servers);
|
||||||
|
for (let i = 0; i < servers.length; i++) {
|
||||||
|
Steam.queryGameServerInfo(servers[i]).then(data => {
|
||||||
|
if(!data.name.includes("SetSail")) return;
|
||||||
|
// console.log(data); //Debug
|
||||||
|
|
||||||
|
data.keywords.split("-")
|
||||||
|
console.log(`${data.name} @ ${servers[i]} - DLC: ${splitKeyword(data.keywords).dlcString} - TPS: ${colorTPS(splitKeyword(data.keywords).tps)} - Version: ${checkVersion(splitKeyword(data.keywords).version)}`)
|
||||||
|
servers.push(data);
|
||||||
|
}).catch(err => {
|
||||||
|
console.log(`Couldn't connect to ${servers[i]}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
//sortServers();
|
||||||
|
}).catch((err) => {});
|
||||||
|
|
||||||
|
function sortServers() {
|
||||||
|
servers.forEach(server => {
|
||||||
|
Steam.queryGameServerInfo
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue