mirror of
https://github.com/Sithranduil/srcds_exporter.git
synced 2025-07-23 17:28:00 +02:00
33 lines
678 B
JavaScript
33 lines
678 B
JavaScript
import { TimeoutError } from 'working-rcon';
|
|
|
|
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];
|
|
},
|
|
async rconCommand(client, command) {
|
|
try {
|
|
return client.command(command);
|
|
} catch (err) {
|
|
if (err instanceof TimeoutError) {
|
|
console.error('request timed out');
|
|
} else {
|
|
throw err;
|
|
}
|
|
}
|
|
return null;
|
|
},
|
|
isValidResponse(response) {
|
|
return !response.includes('Unknown');
|
|
},
|
|
};
|