Coder Social home page Coder Social logo

enriqcg / rcon-srcds Goto Github PK

View Code? Open in Web Editor NEW
57.0 2.0 20.0 61 KB

A zero-dependency Typescript library for the Source/Minecraft RCON Protocol

Home Page: https://www.npmjs.com/package/rcon-srcds

License: MIT License

TypeScript 100.00%
nodejs typescript rcon rcon-protocol rcon-client csgo-server minecraft-server promise async-await

rcon-srcds's Introduction

RCON library for NodeJS

According to Valve's RCON specification

Install

npm install rcon-srcds --save

Usage

// ES5 import
const server = new Rcon(options);

// ES5+ import
import Rcon from 'rcon-srcds';

Options

These are the default values.

{
    host: '127.0.0.1',          // Host
    port: 27015,                // Port
    maximumPacketSize: 0,       // Maximum packet bytes (0 = no limit)
    encoding: 'ascii',          // Packet encoding (ascii, utf8)
    timeout: 1000               // in ms
}

The maximum possible value of packet size is 4096 bytes: https://developer.valvesoftware.com/wiki/Source_RCON_Protocol#Packet_Size

Minecraft Compatibility

Although the package name implies exclusive compatibility with Source games, Minecraft servers also use Valve's RCON implementation, so there should not be any issues using this package for your Minecraft projects!

Examples

Using async/await:

import Rcon from 'rcon-srcds';
const server = new Rcon({ host: '127.0.0.1', port: 25010 });
try {
    await server.authenticate('your_rcon_password');
    console.log('authenticated');
    let status = await server.execute('status'); // You can read `status` reponse
    server.execute('mp_autokick 0'); // no need to read the response
} catch(e) {
    console.error(e);
}

Using (native) promises:

import Rcon from 'rcon-srcds';
const server = new Rcon({ port: 25010 });

server.authenticate('rcon_password')
    .then(() => {
        console.log('authenticated');
        return server.execute('status');
    })
    .then(console.log)
    .catch(console.error);

rcon-srcds's People

Contributors

c43721 avatar dependabot[bot] avatar enriqcg avatar taraman17 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

Watchers

 avatar  avatar

rcon-srcds's Issues

Server Connection Timeout Config

Is there a way to configure a connection timeout to the server? Since setting the constructor's timeout parameter doesn't seem to take care of this, I'm thinking it's probably specifically a command response timeout? If there's a connection issue to the server, the request seems to hang there for a while. If this isn't currently a feature, I think it'd be really nice to have.

code: 'ETIMEDOUT' on authentication

Hi, I'm using this to try connect to a left 4 dead 2 server.

Using the code exactly in the docs is giving me a ETIMEDOUT error code. Am I doing something wrong here?

import Rcon from "rcon-srcds";
const server = new Rcon({ host: "IP", port: 27015 });
      server
        .authenticate("RCON_PASS")
        .then(() => {
          console.log("authenticated");
          return server.execute("status");
        })
        .then(console.log)
        .catch(console.error);`

Response I'm getting

Error: connect ETIMEDOUT IP:27015
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16) {
  errno: -4039,
  code: 'ETIMEDOUT',
  syscall: 'connect',
  address: 'IP',
  port: 27015
}

Possible EventEmitter memory leak detected

Hello,

I've been using a fork of this repository, however, this issue seems to be inherited from here.

I am using the repository to poll a server once every so often to get player count details. After around 9 .execute() calls, the following warning is thrown:

(node:12752) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 data listeners added. Use emitter.setMaxListeners() to increase limit

It looks as if your code is not removing listeners after the returning the response. To test this I editted your write function to remove the .on('data', onData) just before the promise is resolved. This seems to have prevented the warning, however, I am not sure on what effect it will have on multi-packet responses. Is this something that you could look into?

Thanks in advance.

Can this be used with CS:GO

Hi

I am new to RCON, but if I run my own CS:GO server can I use this to get realtime game info from my game? aka player stats, health, kill rate etc

Thanks

Rcon is not a constructor

Not sure if I'm doing something wrong... but copying and pasting either example and running it gives me an error saying Rcon is not a constructor.

Not all commands give a response & another EventEmitter memory leak

It seems that only responses following this if-condition will return a message. This has some issues though:

server.execute('woof').then(console.log) // Unknown command "woof"
server.execute('echo hello').then(console.log) // Nothing?

Furthermore if you keep repeating the commands that don't respond, it will create a memory leak.

setInterval(() => server.execute('echo hello'), 1000)
// After 10 seconds: 
// Possible EventEmitter memory leak detected. 11 data listeners added to [Socket]. Use emitter.setMaxListeners() to increase limit

Authentication sometimes fails

I have a problem, that sometimes (meanwhile close to 50%) the authentication fails. No answer is sent from the module.

Logging whats happening, I found that sometimes the 2 Authentication packets are sent by the server (or at least received by rcon-srcds) as 1:

writing packet
packet written.
received packet:
<Buffer 0a 00 00 00 99 09 00 00 00 00 00 00 00 00 0a 00 00 00 99 09 00 00 02 00 00 00 00 00>
decoded packet:
{
  size: 10,
  id: 2457,
  type: 0,
  body: '\u0000\u0000\n\u0000\u0000\u0000\u0019\t\u0000\u0000\u0002\u0000\u0000\u0000'
}

a correct set of packets looks like this:

writing packet
packet written.
received packet:
<Buffer 0a 00 00 00 99 09 00 00 00 00 00 00 00 00>
decoded packet:
{ size: 10, id: 2457, type: 0, body: '' }
received packet
<Buffer 0a 00 00 00 99 09 00 00 02 00 00 00 00 00>
decoded packet:
{ size: 10, id: 2457, type: 2, body: '' }
Auth response is success

Add localAddress option

It would be great to see localAddress option when creating rcon object or in authenticate.

It would allow connecting from different ip addresses of the local machine.

Changes with CS2

It shows, that in the CS2 Dedicated server, the behaviour of rcon answers is different than in CS:GO

  1. On authentication, only one packet is sent as answer and the first empty packet is not there anymore.
  2. There are no multipacket responses anymore - all answers are sent as single packet.

So it will be necessary to do some changes and it must be discussed, if that is done as if condition within this library or if it is better to fork it.

Rcon is not defined.

Getting an error telling me that Rcon is not defined. Im new to javascript, so I have not been able to figure out what I did wrong.

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.