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.
;;
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.
;
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 .sessionc.send"one" // connects, sends, and then disconnects. .thenconsole.log"first session complete", console.error; // Multiple commands:rcon .session .thenconsole.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
sendHelp.finally;
Or simply...
rcon .sessionc.send'/help' .thenconsole.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.