Skip to main content

Manually Sending Commands

The IRCONClient, RCONClientV2, and RCONClientV1 classes all implement their own manager-oriented APIs that cover 100% of the RCON APIs. If you dont want to use these and would prefer to write the commands yourself, that can be done just as easily and without having to worry about managing the underlying protocol.


Manually Sending RCONv1 Commands​

To queue a message in RCONv1, use the following syntax:

await RCONClientV2._send(message, options);

Parameters​

NameDescriptionTypeRequired
messageThe command to send.stringTrue
optionsSee below.ObjectFalse

Options​

NameDescriptionTypeDefault Value
encryptThe command to send.stringTrue
inactivityTimeoutHow long in milliseconds to wait for a new packet to be received for
the message sequence to be considered complete.
number1_000
shortResponseIf the command returns SUCCESS or FAIL.booleanFalse
note

For shortResponse to take effect, RCONClientV1._expediteShortResponses must be true, this value is set in the class' constructor method.

shortResponse Was implemented to fix the problem of having to wait additional time for additional packets for commands that will likely never return more than 1 packet of data. This was mostly added to make commands that return SUCCESS or FAIL resolve much quicker. Theoretically, it can also be used for commands that return small packets of data such as getting the server name or open slots, but the default behavior of this library only enables this feature on commands that return SUCCESS or FAIL.

Returns​

Promise<string>


Manually Sending RCONv2 Commands​

To send messages in RCONv2, you must use the RequestMessage constructor, pass that to RCONClientV2._send, which returns a ResponseMessage.

RequestMessage Constructor​

new RequestMessage(client, commandName, contentBody);

Parameters​

NameDescriptionTypeRequired
clientThe RCONv2 client.RCONClientV2True
commandNameThe command name.stringTrue
contentBodyThe ContentBody if necessary.object | stringFalse

Sending the RequestMessage Object​

const response = await RCONClientV2._send(requestMessage);

Returns​

ResponseMessage

ResponseMessage Object​

{
client: RCONClientV2,
index: number,
statusCode: number,
statusMessage: string,
version: number,
name: string,
contentBody: object | string
}

Examples​

Below are examples for RCONClientV2 and RCONClientV1 which both fetch all players in the server and then get detailed information about each. client is assumed to be a logged in instance of the IRCONClient class.

tip

As you can see from the RCONv1 results, the shortResponse property can be very powerful, even nearly rivaling the efficiency of the RCONv2 protocol. However, its important to use it only when you are sure the response will be short, usually <1000 bytes. In my experience testing this, the maximum incoming packet length is anywhere from 1460 to 14600, inconsistent in other words and therefore dangerous.


RCONv1 Without Expedition​

console.time("Duration");

const allPlayers = await client.v1.players.fetchPlayerIds();
for (const player of allPlayers) {
const response = await client.v1._send(`PlayerInfo ${player.playerName}`);
console.log(response);
}

console.log(`Traversed ${allPlayers.length} players.`);
console.timeEnd("Duration");

Output​

...
Traversed 99 players.
Duration: 1:55.499 (m:ss.mmm)

RCONv1 With Expedition​

console.time("Duration");

const allPlayers = await client.v1.players.fetchPlayerIds();
for (const player of allPlayers) {
const response = await client.v1._send(`PlayerInfo ${player.playerName}`, { shortResponse: true });
console.log(response);
}

console.log(`Traversed ${allPlayers.length} players.`);
console.timeEnd("Duration");

Output​

...
Traversed 100 players.
Duration: 16.519s

RCONv2​

console.time("Duration");

const allPlayers = await client.v2.players.fetch();

for (const player of allPlayers.players) {
const requestMessage = new RequestMessage(client.v2, "ServerInformation", {
Name: "player",
Value: player.iD
});

const response = await client.v2._send(requestMessage);

console.log(response);
}

console.log(`Traversed ${allPlayers.players.length} players.`);
console.timeEnd("Duration");

Output​

...
Traversed 99 players.
Duration: 16.111s