From wiki.vg
Revision as of 10:04, 29 May 2021 by EnriqCG (talk | contribs) (Updated Javascript Example Implementations. Removed the RingoJS one since it was not updated since 2012. Added rcon-client as a more modern example.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

RCON is a protocol that allows server administrators to remotely execute Minecraft commands. Introduced in 1.9pre4, it's basically an implementation of the Source RCON protocol for Minecraft.

Server Config

   rcon.password=<your password>

The default port is 25575.

Packet Format

Integers are little-endian, in contrast with the Minecraft protocol.

Responses are sent back with the same Request ID that you send. In the event of an auth failure (i.e. your login is incorrect, or you're trying to send commands without first logging in), request ID will be set to -1.

Field name Field type Notes
Length int Length of remainder of packet
Request ID int Client-generated ID
Type int 3 for login, 2 to run a command, 0 for a multi-packet response
Payload byte[] NULL-terminated ASCII text
1-byte pad byte NULL

Note on ASCII text: Some servers reply with color codes prefixed by a section sign in their replies. (For example Craftbukkit for Minecraft 1.4.7 does this)

The section sign is sent by those servers as byte 0xA7 or 167. This is not part of the US-ASCII charset and will cause errors for clients that strictly use the US-ASCII charset.

Using the ISO-LATIN-1/ISO-8859_1 charset instead of the US-ASCII charset yields much better results for those servers.

Alternatively removeing byte 167 and one subsequent byte from the payload will remove all color tokens makeing the text more human readable for clients that do not subsequently colorize those tokens.


3: Login

Outgoing payload: password.

If the server returns a packet with the same request ID, auth was successful (note: packet type is 2, not 3). If you get a request ID of -1, auth failed (wrong password).

2: Command

Outgoing payload should be the command to run, e.g. time set 0

0: Command response

Incoming payload is the output of the command, though many commands return nothing, and there's no way of detecting unknown commands.

The output of the command may be split over multiple packets, each containing 4096 bytes (less for the last packet). Each packet contains part of the payload (and the two-byte padding). The last packet sent is the end of the output.


Maximum C->S packet payload length: 1446 (total: 1460) - outdated?

Maximum S->C packet payload length: 4096 (total: 4110)

The minecraft server can fragment responses across multiple packets. There's no simple way to know when the last response packet has been received; approaches include:

  1. Wait until we receive a packet with a payload length < 4096 (not 100% reliable!)
  2. Wait for n seconds
  3. Send two command packets; the second command triggers a response from the server with the same Request ID, and from this we know that we've already received the full response to the first command.
    • The second packet should use a command that will not produce fragmented output
    • An alternative is for the second C->S packet to use an invalid type (say, 100); the server will respond with a 'Command response' packet with its payload set to 'Unknown request 100'.

Example implementations