Giter Site home page Giter Site logo

node-srcds-rcon's Introduction

node-srcds-rcon

Node.JS high-level wrapper for SRCDS's remote console (RCON) https://developer.valvesoftware.com/wiki/RCON

Install

npm install srcds-rcon

If you think the npm version is outdated, you may install from github

npm install randunel/node-srcds-rcon

Introduction

This is a node driver for SRCDS's RCON. While it should work on all SRCDS versions, it has only been tested against the Source 2009 (orangebox) protocol. Development uses the latest CS:GO server build.

The current version 2.x requires node.js version 4.x or newer. For older node.js versions including 0.8, install srcds-rcon 1.1.7. All development uses node.js 5.x.

Testing

Install dev dependencies (npm install does that by default). Set up a csgo server and bind it to 127.0.0.1:27015, run it with -usercon and rcon_password test. Then run make test.

Alternatively, set up a different server and edit test/integration.test.js getIntegrationAuth to return login details to the desired test server.

Usage

First establish connection

let Rcon = require('srcds-rcon');
let rcon = Rcon({
    address: '192.168.1.10',
    password: 'test'
});
rcon.connect().then(() => {
    console.log('connected');
}).catch(console.error);

Run commands

let rcon = require('srcds-rcon')({
    address: '192.168.1.10',
    password: 'test'
});

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'))
).then(
    () => rcon.disconnect()
).catch(err => {
    console.log('caught', err);
    console.log(err.stack);
});

Specify command timeout

rcon.command('cvarlist', 1000).then(console.log, console.error);

Disconnect once finished

rcon.disconnect();

Errors

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.

node-srcds-rcon's People

Contributors

bitdeli-chef avatar petschekr avatar randunel avatar thesupremecommander avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-srcds-rcon's Issues

How can i know if the rcon is correct?

I'm trying to connect a node instance to multiple servers, and i need to test the rcon before starting to make the commands.

How can i know if the rcon is the correct for that server?

Command Lost on cvarlist

Error happens when a multi packet response is caused with gmod server.

Error: Command lost at handleUnexpectedData (C:\Users\Khris\Documents\Git\krak-bot2\node_modules\srcds-rcon\index.js:127:39) at dataHandler (C:\Users\Khris\Documents\Git\krak-bot2\node_modules\srcds-rcon\index.js:106:32) at Socket.dataHandler (C:\Users\Khris\Documents\Git\krak-bot2\node_modules\srcds-rcon\lib\connection.js:77:22) at Socket.emit (events.js:315:20) at addChunk (_stream_readable.js:295:12) at readableAddChunk (_stream_readable.js:271:9) at Socket.Readable.push (_stream_readable.js:212:10) at TCP.onStreamRead (internal/stream_base_commons.js:186:23) caught Error: Command lost at handleUnexpectedData (C:\Users\Khris\Documents\Git\krak-bot2\node_modules\srcds-rcon\index.js:127:39) at dataHandler (C:\Users\Khris\Documents\Git\krak-bot2\node_modules\srcds-rcon\index.js:106:32) at Socket.dataHandler (C:\Users\Khris\Documents\Git\krak-bot2\node_modules\srcds-rcon\lib\connection.js:77:22) at Socket.emit (events.js:315:20) at addChunk (_stream_readable.js:295:12) at readableAddChunk (_stream_readable.js:271:9) at Socket.Readable.push (_stream_readable.js:212:10) at TCP.onStreamRead (internal/stream_base_commons.js:186:23) { details: { reqId: 2, partialResponse: 'cvar list\n' + '--------------\n' + '_autosave : cmd : : Autosave\n' + '_autosavedangerous : cmd : : AutoSaveDangerous\n' + '_bugreporter_restart : cmd : : Restarts bug reporter .dll\n' + '_deathrec : cmd : : \n' + '_resetgamestats : cmd : : Erases current game stats and writes out a blank stats file\n' + '_restart : cmd : : Shutdown and restart the engine.\n' + '_ttt_radio_send : cmd : : \n' + '_ttt_request_rolelist : cmd : : \n' + '_ttt_request_serverlang : cmd : : \n' + '_u : cmd : : \n' + '_xgui : cmd : : \n' + 'achievement_debug : 0 : , "sv", "cheat", "rep" : Turn on achievement debug msgs.\n' + 'act : cmd : : \n' + 'addip : cmd : : Add an IP address to the ban list.\n' + 'adsp_alley_min : 122 : : \n' + 'ai_debug_expressions : 0 : , "sv" : Show random expression decisions for NPCs.\n' + 'ai_debug_follow : 0 : , "sv" : \n' + 'ai_debug_loners : 0 : , "sv" : \n' + 'ai_debug_looktargets : 0 : , "sv" : \n' + ai_debug_los : 0 : , "sv", "cheat" : NPC Line-Of-Sight debug mode. If 1, solid entities that block NPC LOC will be highlighted with white bounding boxes. If 2, it'l\n + 'ai_debug_nav : 0 : , "sv" : \n' + 'ai_debug_node_connect : cmd : : Debug the attempted connection between two nodes\n' + 'ai_debug_ragdoll_magnets : 0 : , "sv" : \n' + 'ai_debug_readiness : 0 : , "sv" : \n' + 'ai_debug_shoot_positions : 0 : , "sv", "cheat", "rep" : \n' + 'ai_debug_speech : 0 : , "sv" : \n' + 'ai_debug_squads : 0 : , "sv" : \n' + 'ai_debug_think_ticks : 0 : , "sv" : \n' + 'ai_debugscriptconditions : 0 : , "sv" : \n' + 'ai_default_efficient : 0 : , "sv" : \n' + 'ai_disable ' } } Error: Command lost at handleUnexpectedData (C:\Users\Khris\Documents\Git\krak-bot2\node_modules\srcds-rcon\index.js:127:39) at dataHandler (C:\Users\Khris\Documents\Git\krak-bot2\node_modules\srcds-rcon\index.js:106:32) at Socket.dataHandler (C:\Users\Khris\Documents\Git\krak-bot2\node_modules\srcds-rcon\lib\connection.js:77:22) at Socket.emit (events.js:315:20) at addChunk (_stream_readable.js:295:12) at readableAddChunk (_stream_readable.js:271:9) at Socket.Readable.push (_stream_readable.js:212:10) at TCP.onStreamRead (internal/stream_base_commons.js:186:23)

command was used as suggested by #9

Wrong rcon password timeout

When attempting to connect with the wrong rcon password, the server does not reply. A timeout must be set.

typescript definition?

I was hoping to find typescript definition with no luck, does anyone know if it exists?

Or would you be open to porting this to typescript? I'd try and contribute. Shouldn't take too long to do it.

does this work with local csgo client?

I'm doing some aim practice now a days and I'd like to set some variables, get number of kills etc every once in a while, and later I want to save this data somewhere and track my progress.

I was wondering how to connect to my local instance, I wasn't able to figure this out. At the end, I want to start a map, I want to set mp_roundtime 10, mp_restartgame 1 and then in 10 mins, I want to query how many kills I did and save this somewhere, but when I try to connect to 127.0.0.1:27015, it throws connection refused, I made a mistake, how do we set this up?

Cannot connect to local server

I'm trying to connect to a local server (running the server on my own PC), and receiving this error:

{ [Error: connect ECONNREFUSED 10.0.0.4:27015]
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect',
  address: '10.0.0.4',
  port: 27015 }

Working well, but...

Hi!

This package is working well, but sometimes, I try to send a rcon command to a server and it doesn't work. I try again seconds later, it still fails, and at third, or fourth attempt, it sends the command to the server.
No error caught on the cath instruction, no message returned from the command() function...

Thx for reading!

TypeError: r.createConnection is not a function

Hi, I keep getting this error on connection, if I log the object there is no pproblem, maybe I'm missing some dependencies?

Here is my code:

let Rcon = require('srcds-rcon')
let rcon = Rcon({
address: this.servers[index].ip,
port: this.servers[index].port,
password: this.servers[index].rcon_password
})
console.log(rcon)
rcon.connect().then(() => {
console.log('connected')
}).catch(console.error)

Fix hang on startup when displaying console

When starting up, the "cvarlist" command is run.

If the user has the server's console open, timeout is thrown by srcds's watchdog due to the slowness of the command display.

This can be fixed by storing the value of sv_logecho, running sv_logecho 0 before cvarlist, and restoring sv_logecho when cvarlist is done.

Incorrect protocol information in readme

Hello!

In the last paragraph of the readme, The protocol uses udp and the packets sometimes get lost. RCON uses TCP. It is true that sometimes TCP packets get lost, so a partial response is still possible, but it is less likely than if this were a UDP thing since TCP will keep trying to resend the packet until either the received acknowledges that it was received, or a timeout happens.

The code is correct, just not the one line in the docs.

Thanks for a useful library! :)

Error Installing

I get this error installing:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/nodejs',
1 verbose cli '/usr/bin/npm',
1 verbose cli 'install',
1 verbose cli 'randunel/node-srcds-rcon' ]
2 info using [email protected]
3 info using [email protected]
4 verbose cache add [ 'randunel/node-srcds-rcon', null ]
5 verbose cache add name=undefined spec="randunel/node-srcds-rcon" args=["randunel/node-srcds-rcon", null]
6 verbose parsed url { protocol: null,
6 verbose parsed url slashes: null,
6 verbose parsed url auth: null,
6 verbose parsed url host: null,
6 verbose parsed url port: null,
6 verbose parsed url hostname: null,
6 verbose parsed url hash: null,
6 verbose parsed url search: null,
6 verbose parsed url query: null,
6 verbose parsed url pathname: 'randunel/node-srcds-rcon',
6 verbose parsed url path: 'randunel/node-srcds-rcon',
6 verbose parsed url href: 'randunel/node-srcds-rcon' }
7 silly lockFile 662164de-randunel-node-srcds-rcon randunel/node-srcds-rcon
8 verbose lock randunel/node-srcds-rcon /root/.npm/662164de-randunel-node-srcds-rcon.lock
9 info maybeGithub Attempting randunel/node-srcds-rcon from git://github.com/randunel/node-srcds-rcon
10 silly lockFile bdb83ecc-hub-com-randunel-node-srcds-rcon git://github.com/randunel/node-srcds-rcon
11 verbose lock git://github.com/randunel/node-srcds-rcon /root/.npm/bdb83ecc-hub-com-randunel-node-srcds-rcon.lock
12 verbose addRemoteGit [ 'git://github.com/randunel/node-srcds-rcon', 'master' ]
13 silly lockFile bdb83ecc-hub-com-randunel-node-srcds-rcon git://github.com/randunel/node-srcds-rcon
14 silly lockFile bdb83ecc-hub-com-randunel-node-srcds-rcon git://github.com/randunel/node-srcds-rcon
15 info maybeGithub Attempting randunel/node-srcds-rcon from git+ssh://[email protected]:randunel/node-srcds-rcon
16 silly lockFile 58b1587a-hub-com-randunel-node-srcds-rcon git+ssh://[email protected]:randunel/node-srcds-rcon
17 verbose lock git+ssh://[email protected]:randunel/node-srcds-rcon /root/.npm/58b1587a-hub-com-randunel-node-srcds-rcon.lock
18 verbose addRemoteGit [ '[email protected]:randunel/node-srcds-rcon', 'master' ]
19 silly lockFile cbff231c-hub-com-randunel-node-srcds-rcon [email protected]:randunel/node-srcds-rcon
20 silly lockFile 662164de-randunel-node-srcds-rcon randunel/node-srcds-rcon
21 silly lockFile 662164de-randunel-node-srcds-rcon randunel/node-srcds-rcon
22 error addLocal Could not install randunel/node-srcds-rcon
23 error Error: ENOENT, stat 'randunel/node-srcds-rcon'
24 error If you need help, you may report this log at:
24 error http://github.com/isaacs/npm/issues
24 error or email it to:
24 error [email protected]
25 error System Linux 3.13.0-85-generic
26 error command "/usr/bin/nodejs" "/usr/bin/npm" "install" "randunel/node-srcds-rcon"
27 error cwd /root
28 error node -v v0.10.25
29 error npm -v 1.3.10
30 error path randunel/node-srcds-rcon
31 error code ENOENT
32 error errno 34
33 verbose exit [ 34, true ]

Need a little bit of help

I am currently working on a project and require the execution of commands on a remote tf2 server.

When I try to execute commands in the same way the example suggests, I don't have any command executed. But it seems to connect, well I don't get an error.

I am not quite sure what I am doing wrong. I am sure I have the correct password.

I would appreciate any help or guidance, here is my code.

var Rcon = require('srcds-rcon');

var rcon = new Rcon('iphidden', 'passwordhidden');

rcon.connect(function() {
    console.log('connected');
    rcon.kick('pmk010', function(err, res) {
        console.log('kicked player pmk010', res);
    });
});

Use in function

HI I have following code in module.exports and want to get the awnser from the server returned by the function. How can I do that? I tried to put the return in front of the connect but that did gave me the state of the connection.

  status: function () {
    rcon.connect().then(() => {
        rcon.command('status').then(() => {
            console.log('status check');
        });
    }).then(
        () => rcon.disconnect()
    ).catch(err => {
        console.log('caught', err);
        console.log(err.stack);
    });
  },

application crashing when requiring package

Hello,

My application is crashing the moment I put in in the 'require'. It seems to be something with the use strict in your code. let is not allowed to be used when you are using strict mode.

Removing the strict mode I get an 'unexpected identifier on the first word: Connection.

Unable to get rcon.command(cmd).then working

Here's my code:

rcon.connect().then(() => {
    socket.emit(id,{msg:"Command sent", success:true})
    rcon.command(cmd).then(() => {
        console.log('ran command!');
    });
}).catch(err => {
    socket.emit(id,{msg:"Command failed, server may be offline or starting up", success:false})
})

I want to move the socket.emit(id,{msg:"Command sent", success:true}) bit inside the command.then bit but it doesn't seem to be called. If I understand it correctly that section with the console.log('ran command!'); should be called after the command is successfully run on the server - but even though the command is run it doesn't seem to call the function.

I'm using latest GitHub version of course.

Is it possible to do something with rcon status and playercounters?

I know this package is old, But i was wondering if it was possible with this package, Since there are not much package out there that do allows you to do such things as this package can. But to make the situation a bit clearer, In my application, I'm using it for ark rcons, But there are no commands for status or playerlists. Thank you in advance.

Connection hangs on auth and commands.

For some reason when connecting to my RCON server the authorization hangs forever.

I narrowed it down to lines 53-55 of the index.js. For some reason that promise is hanging forever and it just ends up timing out at some point. I pulled the _init out of there and commented out the promise and it connects instantly and runs commands without any issue.
return connection.getData(dataHandler).then(() => { _init(connection); });

I also found that if I don't provide a timeout for the rcon.command function it also just sits there and hangs for at least 5-10 seconds and then returns the buffer. If I provide at least a 1000ms timeout it runs instantly.

Node version: 6.2.2
Node-srcds-rcon version: latest
RCON Game: Ark Survival Evolved

Code being used,
rcon.connect().then(function(){ console.log("Connected!"); rcon.command('getchat',1000).then((test) => { console.log("chat ",test); }); });

Update: Did a little more digging because I started having more issues and found a packet getting thrown in with my rcon request. Found these on lines 87-92 and 100-102 of the index.js causing issues.

let ackId = _getNextPacketId(); let ack = packet.request({ id: ackId, type: packet.SERVERDATA_EXECCOMMAND, body: '' });
and
if (res.id === ackId) { return false; } else if (res.id === reqId) {

Seems like every time the "getData" function gets sent a false variable it just hangs terribly as well. I've since commented out the first part and the first if statement. Everything connects/returns within less than a second now, both on my local server and my remote server.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.