RCon Protocol

From BF2 Technical Information Wiki
Jump to navigation Jump to search

Basics

This document describes the RCON ("Remote Console") protocol spoken by the Battlefield 2 server; RCON is run as a TCP service, operating on port 4711 by default. The BF2 server implements the TCP listener and RCON protocol completely in Python, in the administrative module. A description of how the administrative module handles RCON can be found here.

Upon connecting, the client is sent a header from the server, ending with /n/n (two 0x0A characters). One of the lines is prefixed with the text (sans quotes), "### Digest seed: ". The value after the colon and space needs to be stored for the login sequence. An example banner:

### Battlefield 2 default RCON/admin ready.
### Digest seed: dOrdNsTRDWSvPWXi

Commands

All commands sent by the client have /n (0x0A) appended to indicate the end-of-line. An optional 0x02 character can be prefixed to the command - this instructs the server to append a 0x04 character on the output generated by the command to indicate the end of the data. However, its worth noting that the server does not send a 0x0A (newline) after the 0x04 (EOT) character, so you'll have to make sure your program can handle this. This is an optional part of the protocol that can be implemented if returning all of the output is important to your environment.

The sample remoteconsole.py script included with BF2 uses the 0x02 character on all commands by default. All examples below are shown without the 0x02 and 0x04 characters.

login

A digest of the password using the MD5 algorithm is calculated with the seed obtained from the banner and is represented in hexadecimal format (e.g. 106c9f3b52c173dc210e7ee612e689bb). Note that the seed isnt used in the "normal" seed manner. To get a working digest, you take the seed returned in the banner, concatenated with the password, and then send the returned digest to the server. For example lets say the returned seed is PXYHKqLrFfENvONV and the RCON password is password, the string to return the digest of would be PXYHKqLrFfENvONVpassword, which is this case whould yield a digest of bc3d874909af1404eec2765ef3613b19.

A login command may look like:

6c 6f 67 69 6e 20 62  64 32 39 39 37 39 30 64 64 login b d299790dd
33 37 37 34 36 62 32  31 66 32 32 33 65 33 34 37 37746b2 1f223e347
39 66 63 33 63 31 0a                             9fc3c1.

Possible responses on the standard BF2 RCON server are:

41 75 74 68 65 6e 74 69  63 61 74 69 6f 6e 20 66 Authenti cation f
61 69 6c 65 64 2e 0a                             ailed..
41 75 74 68 65 6e 74 69  63 61 74 69 6f 6e 20 73 Authenti cation s
75 63 63 65 73 73 66 75  6c 2c 20 72 63 6f 6e 20 uccessfu l, rcon
72 65 61 64 79 2e 0a                             ready..

You must have authenticated successfully before other commands are unlocked, or you will be met with:

65 72 72 6f 72 3a 20 6e  6f 74 20 61 75 74 68 65 error: n ot authe
6e 74 69 63 61 74 65 64  3a 20 79 6f 75 20 63 61 nticated : you ca
6e 20 6f 6e 6c 79 20 69  6e 76 6f 6b 65 20 27 6c n only i nvoke 'l
6f 67 69 6e 27 0a                                ogin'.

exec

This runs a command (such as a PB command) or gets/sets a value of a setting on the server. For example:

65 78 65 63 20 73 76  2e 74 69 63 6b 65 74 72 61 exec sv .ticketra
74 69 6f 0a                                      tio.

Response:

31 30 30 0a 100. 

Example PB command:

65 78 65 63 20 70 62  5f 73 76 5f 70 6c 69 73 74 exec pb _sv_plist
0a 

PunkBuster commands will not return any text due to a bug (or 'feature') in BF2/PB integration. Their output will be shown on the server console itself, or in the PB log files if required.

users

This shows the active users logged into the RCON system. Request:

75 73 65 72 73 0a users. 

I believe the response varies depending on which RCON method people are using (i.e. standalone client, in-game etc). Here is an example, with two remote standalone clients:

61 63 74 69 76 65 20 72  63 6f 6e 20 75 73 65 72 active r con user
73 3a 0a 74 63 70 3a 20  31 32 2e 33 34 2e 35 36 s:.tcp:  12.34.56
2e 37 38 3a 36 32 33 35  32 0a 74 63 70 3a 20 38 .78:6235 2.tcp: 8
37 2e 36 35 2e 34 33 2e  32 31 3a 36 32 32 34 38 7.65.43. 21:62248
0a 

Notes

If a command does not exist, you will receive this:

75 6e 6b 6e 6f 77 6e 20  63 6f 6d 6d 61 6e 64 3a unknown  command:
20 27 62 6c 61 68 27 0a                           'blah'.