📦 Add a Trails service to execute rcon comands
This package is an implementation of node-srcds-rcon in Trails framework.
With yo :
npm install -g yo generator-trails
yo trails:trailpack trailpack-srcdsrcon
With npm (you will have to create config file manually) :
npm install --save trailpack-srcdsrcon
Enable SrcdsRcon
// config/main.js
packs: [
...
require('trailpack-srcdsrcon')
],
Check that srcds config is loaded on index.js
// config/index.js
...
exports.srcds = require('./srcds')
Configure
// config/srdcs.js
module.exports = {
// List of servers that use SRCDS services
servers: [{
name: 'myServer',
address: '123.123.123.123', //this could be (ip or ip:port)
password: 'my-rcon-password'
}],
/*
* Default server the service will connect if there is no args
*/
defaultServer: 'myServer'
}
let rcon = this.app.services.SrcdsRconService.get("myServer")
rcon.connect().then(() => {
console.log('connected');
}).catch(console.error);
let rcon = this.app.services.SrcdsRconService.get("myServer")
rcon.connect().then(() => {
return rcon.command('sv_airaccelerate 10').then(() => {
console.log('changed sv_airaccelerate');
});
}).then(
() => rcon.command('status').then(status => console.log(`got status ${status}`))
).then(
() => rcon.command('cvarlist').then(cvarlist => console.log(`cvarlist is \n${cvarlist}`))
).then(
() => rcon.command('changelevel de_dust2').then(() => console.log('changed map'))
).catch(err => {
console.log('caught', err);
console.log(err.stack);
});
rcon.command('cvarlist', 1000).then(console.log, console.error);
Some errors may contain partial command output. That indicates that the command was run, but reply packets have been lost.
rcon.command('cvarlist').then(() => {}).catch(err => {
console.log(`Command error: ${err.message}`);
if (err.details && err.details.partialResponse) {
console.log(`Got partial response: ${err.details.partialResponse}`);
}
});
When an error is returned, even if it doesn't contain a partial output, there is no guarantee the command was not run. The protocol uses udp and the packets sometimes get lost. The only guarantee the command did run is when the error contains a partial output.
A part of this docs are owned by Mihai Ene the creator of node-srcds-rcon package.