Git Product home page Git Product logo

rcon-ts's Introduction

rcon-ts

A modern RCON client implementation written in TypeScript (targeting ES2015) and is async/await friendly.

(Originally node-modern-rcon.)

Installation

npm install rcon-ts --save

API

Initialization

Creates a new Rcon object.

import Rcon from 'rcon-ts';
const rcon = new Rcon({
  host: "host-path",
  port: 25575 /*default*/, 
  password: "required",
  timeout: 5000 /*default (5 seconds)*/
});

Connecting

Connects with the credentials provided in the constructor. Can be awaited on.

rcon.connect();

Sending

Executes the provided command on the active connection and returns the response.

let response = await rcon.send("[rcon request]");

Disconnecting

Ends the current socket and subsequently signals to any pending request that the connection was disconnected.

rcon.disconnect();

Sessions

To simplify the usage, you can use the session method.

// Single command:
rcon
  .session(c => c.send("one")) // connects, sends, and then disconnects.
  .then(()=>console.log("first session complete"), console.error);
  
// Multiple commands:
rcon
  .session(async c => {
    await c.send("two");
    await c.send("three");
  })
  .then(()=>console.log("second session complete"), console.error);

Any number of conccurrent sessions can be active on a single connection and once they've all completed the connection will end.

session takes a promise factory as a parameter and passes the current Rcon instance as the first param (optional) to the factory.

Usage Examples

async function sendHelp()
{
  rcon.connect();
  // safe to immediately setup requests without waiting.
  console.log(await rcon.send('/help'));
  rcon.disconnect();
}

sendHelp().finally(() =>
{
  const errors = rcon.errors;
  if(errors.length) console.warn("Errors:",errors);
});

Or simply...

rcon
  .session(c => c.send('/help'))
  .then(console.log, console.error);

Factorio

Setup:

For usage or testing, make sure you are starting the game from command line or connecting to an rcon configured remote instance.

factorio.exe --start-server [save-name].zip --rcon-port [port] --rcon-password [password]

Verifying it's working:

Try either one of the examples above.

rcon-ts's People

Contributors

levrik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

macil

rcon-ts's Issues

Can't connect via localhost

I know this is a long-shot, but figured I'd ask...

I had a working RCON connection to a Hyper-V server (Win10 [aka not Steam] Ark) and everything worked great...
I've rebuilt my system using Linux and VirtualBox, and for some reason I cannot get it to connect to localhost.

I can connect from another system on the LAN, as well as port forwarding via the WAN, but for the life of me localhost is timing out on me. If it were the opposite, obviously a firewall or NAT transfer is the issue, but connecting to localhost/127.0.0.1 results in timeouts.

As a test, I put an HTTP server on the same port as attempting to run RCON and I observed 2 things:

  1. It worked as expected locally and remote.
  2. While Ark/RCON are running/listening, my HTTP server did not barf out complaining the port was in-use.

I've:

  • Tested HTTP on the same port as described
  • Disabled ALL firewalls, even put my VM in DMZ for testing (why not?)
  • Disabled ALL antivirus on the network (hey let's get all the hackers in here!)
  • Restarted every.single.system.... Including routers/switches because also "why not"
  • Tested with the system air-gapped from my network (no network enabled)
  • Tried pre-packaged RCON tools (same results)
  • Reinstalled Windows and Ark 3x (because pulling my hair out once wasn't enough)
  • Purged and hand-inserted manual routes in the routing table
  • Felt like I'm crazy

Has anyone come across this, and what is the issue!?

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.