RCON
Send and receive remote console commands via RCON.
Overview
RCON allows you to send and receive console commands by interfacing with the server over a remote connection. RCON is secured using a password and a port (typically changed from the default 25575
). RCON is dangerous because it allows you to execute commands with unrestricted privilege, such as if you were an operator on the server.
Workflow
const client = new util.RCON();
await client.connect(host, port);
await client.login('mypassword');
await client.run('time query daytime');
Wait for a response from the server
await client.close()
Examples
Multiple Responses
Single Response
Methods
new util.RCON()
new util.RCON()
This method creates a new RCON client and returns its class. You will need to connect and login before you can start running commands.
client.connect()
client.connect()
Connects to the specified server using the host and port provided in the arguments.
client.login()
client.login()
Logs into the server by using the password specified by the server. You will need to call client.connect()
and wait for it to resolve before trying to log in.
client.run()
client.run()
This method will execute the command on the server and return without waiting for a response. This is typically used if the server sends more than one response for the specified command you are trying to run. You will need to connect then login before trying to run any commands. The return value is the request ID, an incremented counter for identifying what responses from the server are associated with the command request. You can use this request ID to identify what messages returning from the server are a response to this command.
client.execute()
client.execute()
This method is the same as client.run()
, except it will wait to return until it receives a message from the server about the output from the command. If the command you are running outputs more than one message, or you are missing some of the output, please use client.run()
instead and use the client events to read all the messages.
client.close()
client.close()
This will close the connection to the server. Make sure that you wait until you receive a response from the server for any queued executed commands before closing, as you will not receive them if closed before receiving the response.
Events
client.on('message')
client.on('message')
This event is emitted whenever there is a message returned from the server after executing an RCON command. A single command may output multiple messages depending on the plugin or command used, so the first message received may not be the entire output.
Last updated