PDA

View Full Version : CS:S Rcon Protocol using Sockets


pinkeye
12-11-2004, 10:14 PM
Could someone give me a high-level explaination of Source's rcon protocol? That is, what do I need to send if I'm using sockets (which create the packet for me and all I need to do is name the string to send -- I don't need to know about every part of the packet formation and such)?

I've tried to use the C/PHP examples as a guide, but I don't know either language and couldn't get anything out of them.

If it matters, I'm writing in mIRC script.

lart
12-12-2004, 09:27 AM
this was posted in one of the valve mailing lists by my fav valve programmer


Source Server RCON format

The protocol is based around command/response packets encapsulated in a
TCP/IP stream. The stream can have multiple outstanding commands and
can be extended to allow for multiple sub-channels of data.

The command packet format consists of:

packet size (int)
request id (int)
command (int)
string1 (null delimited string)
string2 (null delimited string)


The packet size is the number of bytes from the start of the requestid
to the end of string2 (including the null byte). It must be at least
10.

Request id can be any value except for -1 (0xffffffff), it is used by
the client to de-multiplex outstanding command responses.

Command must be:
SERVERDATA_EXECCOMMAND = 2
or SERVERDATA_AUTH = 3

The meaning of the string values depends upon the command issued.
SERVERDATA_AUTH:
string1 is the rcon_password for the server.
string2 must be null ("");

SERVERDATA_EXECCOMMAND:
string1 is the command to run.
string2 must be null ("");


For RCON connections the first command must be a SERVERDATA_AUTH
command. If a SERVERDATA_EXECCOMMAND command is sent prior to
successful authentication then a SERVERDATA_AUTH_RESPONSE response
packet with the failure condition is sent (see the response section for
details).


The response packet is the same as the command packet, which is:
packet size (int)
request id (int)
command response (int)
string1 (null delimited string)
string2 (null delimited string)

with valid command responses being:
SERVERDATA_RESPONSE_VALUE = 0
or SERVERDATA_AUTH_RESPONSE = 2


SERVERDATA_AUTH_RESPONSE is sent in response to a SERVERDATA_AUTH
command (or to a SERVERDATA_EXECCOMMAND command if the connection is
not successfully authenticated). Both strings are set to null. If the
request id is -1 (0xffffffff) then the authentication attempt failed
(due to a bad password). If the request id is the same value as sent in
the command (i.e the value was mirrored back) then authentication was
successful. Any other request id is an error and the SERVERDATA_AUTH
command should be resent.

SERVERDATA_RESPONSE_VALUE is sent in response to a
SERVERDATA_EXECCOMMAND command. string1 contains the response to the
command and string2 is null (""). string1 is at most 4096 characters, so
a single SERVERDATA_EXECCOMMAND command may result in multiple
SERVERDATA_RESPONSE_VALUE response packets.

I'm working on a java class for source rcon and the code to make the packet looks something like this

byte[] authpkt = new byte[pass.length()+14];
System.out.println("the length of authpacket is " + authpkt.length);
System.arraycopy(toByteArray(authpkt.length-4), 0, authpkt, 0, 4);
System.arraycopy(toByteArray(msgnum++), 0, authpkt, 4, 4);
System.arraycopy(toByteArray(3), 0, authpkt, 8, 4);

byte[] password = pass.getBytes();
System.arraycopy(password, 0, authpkt, 12, password.length);

authpkt[authpkt.length-2] = (byte) 0;
authpkt[authpkt.length-1] = (byte) 0;


private static byte[] toByteArray(long foo, byte[] array)
{
for (int iInd = 0; iInd < array.length; ++iInd)
{
array[iInd] = (byte) ((foo >> (iInd*8)) % 0xFF);
}
return array;
}

Megiddo
02-02-2005, 08:59 PM
How do you just ping the server? ( I'm checking to see if the server is up or down )

EDIT: Is there more protocol information anywhere?

Megiddo
02-03-2005, 06:00 AM
can anyone please help me?

Megiddo
02-03-2005, 08:52 PM
Please! I beg of you! Help me....