mirror of
https://github.com/Sithranduil/srcds_exporter.git
synced 2025-07-22 23:28:26 +02:00
43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
import got from 'got';
|
|
import jsdom from 'jsdom';
|
|
|
|
export default {
|
|
parseCvar(value) {
|
|
const cvar = this.getLine(value);
|
|
const cvarRegex = RegExp('^\\"(.*)\\" = \\"([^\\"]*)\\"(.*)$');
|
|
const res = cvarRegex.exec(cvar);
|
|
return {
|
|
name: res[1],
|
|
value: res[2],
|
|
extra: res[3],
|
|
};
|
|
},
|
|
getLine(value, line = 1) {
|
|
return value.split('\n', line)[line - 1];
|
|
},
|
|
searchLine(value, stringToSearch) {
|
|
const lines = value.split('\n');
|
|
return lines.filter((line) => line.includes(stringToSearch));
|
|
},
|
|
async rconCommand(client, command) {
|
|
try {
|
|
console.log(`[${client.host}:${client.port}] rcon command :`, command);
|
|
const res = await client.send(command);
|
|
console.log(`[${client.host}:${client.port}] rcon commands result: ${command}`);
|
|
console.log(res);
|
|
return res;
|
|
} catch (err) {
|
|
|
|
throw err;
|
|
}
|
|
return null;
|
|
},
|
|
isValidResponse(response) {
|
|
return !response.includes('Unknown');
|
|
},
|
|
async requestGameTracker(ip, port) {
|
|
const response = await got(`https://www.gametracker.com/server_info/${ip}:${port}`);
|
|
return new jsdom.JSDOM(response.body);
|
|
},
|
|
};
|