mirror of
https://github.com/Sithranduil/srcds_exporter.git
synced 2025-07-23 17:28:00 +02:00
Découpage en module
This commit is contained in:
32
utils/utils.js
Normal file
32
utils/utils.js
Normal file
@@ -0,0 +1,32 @@
|
||||
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');
|
||||
},
|
||||
};
|
Reference in New Issue
Block a user