feat: add support for source 2

This commit is contained in:
2023-10-22 19:33:42 +02:00
parent 24e44a346d
commit 14ace4cd49
6 changed files with 106 additions and 59 deletions

View File

@@ -1,6 +1,6 @@
import express from 'express';
import { connect } from 'working-rcon';
import module from './modules/index.js';
import SourceRcon from '@hellz.fr/sourcecon';
const app = express();
@@ -30,16 +30,17 @@ app.get('/metrics', async (req, res) => {
return;
}
if (!['csgo', 'cstrike', 'gmod'].includes(config.game)) {
if (!['csgo', 'cstrike', 'gmod', 'cs2'].includes(config.game)) {
res.send('Incorrect game value, currently supported games are : csgo, gmod, cstrike');
return;
}
try {
const client = await connect(config.ip, config.port, config.rconPassword, 5000);
const client = new SourceRcon.default(config.ip, Number.parseInt(config.port));
await client.connect();
await client.auth(config.rconPassword);
const response = await module.request(config, client);
await module.send(config, response, res);
await client.disconnect();
} catch (e) {
if (e.code === 'EHOSTUNREACH') {
console.error(`Unreachable host : ${e.address}:${e.port}`);