Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rcon-ts

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rcon-ts

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

  • 1.2.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
48
increased by14.29%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

FAQs

Package last updated on 24 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc