Giter Site home page Giter Site logo

timhuijgen / node-srcds-rcon Goto Github PK

View Code? Open in Web Editor NEW

This project forked from randunel/node-srcds-rcon

0.0 2.0 0.0 51 KB

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

Makefile 9.35% JavaScript 90.65%

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

randunel avatar thesupremecommander avatar bitdeli-chef avatar petschekr avatar

Watchers

James Cloos avatar Tim Huijgen avatar

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.