Tech share

I was asked by some people how i fetch that sierra racelist info. Instead of answering everyone seperatly, i'm just gonna share the info here, for everyone to view. The way i got this info was by analysing network packages, and trying to figure out what they mean. You'll see, when you read further, that alot of the info still isn't clear to me. This is because most of the interaction between your pc and the racelist servers is purely binary. What i mean with that is that most of the info can't be "read", they are no ASCII characters. So it took alot of "trial and error" to see if some stuff works, without really knowing what you're sending / receiving :P. Btw, English isn't my native language, so there _will_ be mistakes in this text. Sry about that...

First thing i'll be handling is the fetching of the racelist info itself. What server to contact, ports to use, what to send, ... After that i will discuss the format of the received racelist info. A last part will cover pinging the servers. This isn't done by a normal ICMP message, but using UDP. More about it in that part.


Fetching the racelist

The sierra servers that handle the racelist can be found at one of the following URLs:
These servers can be found in the core.ini file (part of the Nascar 2003 installation). The part before the ":" is the DNS name (which you have to translate to an ip), and the part after the ":" is the port at which you have to connect to the server.
 
You can connect to the server using TCP protocoltype. When connected, you have to send the following bytes (don't know what they mean, but nascar uses these too to give the command to the racelist server to retrieve the list):
 
(hexadecimal notation, read left to right, top to bottom)
 
0x3a 0x00 0x00 0x00 0x05 0x02 0x00 0x67
0x00 0x8a 0x06 0x00 0x06 0x00 0x00 0x07
0x00 0x2f 0x00 0x4e 0x00 0x52 0x00 0x32
0x00 0x30 0x00 0x30 0x00 0x33 0x00 0x03
0x00 0x09 0x63 0x68 0x61 0x74 0x5f 0x72
0x6f 0x6f 0x6d 0x04 0x68 0x6f 0x73 0x74
0x09 0x73 0x76 0x5f 0x73 0x74 0x61 0x74
0x75 0x73
 
When you've sent this bytearray, the server will start sending you racelist info. This info is in a semi-readable format. I'll be covering this in the next part.


Interpreting the racelist info

The received data consists of a number of "server lines", with a header and footer added. I believe each of these server lines begins with the following byte array (i believe this is readable, but i'll just use byte arrays for everything, to make sure no confusion rises about the used encoding of text):

0x4e 0x00 0x52 0x00 0x32 0x00 0x30 0x00
0x30 0x00 0x33

So when you find this byte array in the received data (should be there as many times as there are servers), thats the beginning of a server line.
 
After this byte array, there are 9 bytes of which i don't know the meaning. I just skip them while processing the line.
 
The next bytes, until you find a 0x00 byte, is the first usefull info. The amount of bytes you'll find can be from 7 to 12. The ip info can be found in this byte array, at place 3,4,5 and 6 (starting count at 0). IP format is pretty clear i think, <byte3>.<byte4>.<byte5>.<byte6> .
 
After this field, there's some stuff that is of no importance. For the next usefull info, you have to search for the following byte array:
 
0x00 0x04 0x68 0x6F 0x73 0x74
 
After this, 2 more bytes seem variable, but i don't know the meaning of them. So just skip them, they won't be missed...
 
Here we can now find the host name from the server. This uses basic ASCII encoding, 1 byte = 1 ASCII sign. The end of this host name can be found by looking for the 0x00 byte.
 
The next bytes are the following:
 
0x73 0x76 0x5f 0x73 0x74 0x61 0x74 0x75
0x73
 
This is just the byte representation of the "sv_status" string. After these bytes there's 1 variable byte, of which i don't know the meaning, and a 0x00 byte.
 
Now the hardest part is over. The next sequence of bytes, till the next 0x00 consists of a couple of fields, which are seperated by a 0x01 byte. These fields use ASCII encoding. 
 
I'll just go over these fields now.
 
Game version Version of the game the server is running.
Race port The port the game uses to connect to the server (to join the game).
Ping port The port used for pinging (+ fetching update info?) the server (UDP ping).
Server name Name of the server (duh :P).
Location Well... the location of the server.
Connection What kinda connection the server has.
Track Current track running on the server.
Series The series (mod) the server is running.
Players The current and maximum amount of players on the server (seperated by "/" or 0x2f).
#laps + more There are a couple of bytes which i don't know the meaning of (haven't searched for it yet, doesn't seem to be that hard. But i don't need the info, so...). Sample: "4P3600SQ2LP300SR179L". The only info i'm using from this atm is the value after "SR", this is the amount of laps.
Race options 

Here you can find various info about the server settings. Sample: "3Y----D--L-2".

Meanings:

1st "0" = no damage, "2" = medium damage, "3" = realistic damage
2nd "Y" = yellow flag, "-" = no yellow flag
3rd "F" = fixed setup, "-" = no fixed setup
4th "A" = arcade, "-" = simulation
5th "I" = computer opponents, "-" = no computer opponents
6th Nothing found yet with this value something other then "-"
7th Not always "-", but haven't found the meaning yet
8th "-" = no hardcore mode, "D" = driving aids disabled, "V" = driving view disabled, "B" = both hardcore modes
9th Nothing found yet with this value something other then "-"
10th Not always "-", but haven't found the meaning yet
11th Not always "-", but haven't found the meaning yet
12th Pit stop frequency
Setup This is a single byte which says if the server is in the setup status, or not. Options are "y" or 0x79 for yes and "n" or 0x6e for no.
State This is an ASCII number (from 0 - 3) which says what state the server is in when its not in setup. 0 = practice, 1 = qualify, 2 = warmup and 3 = race.
Progress in session When the state is practice, warmup or race, this field tells how far we are in this session. When the field starts with an "S", the number after it is the time in seconds thats left. If it starts with "L", its the number of laps left.
y/n A "y" or "n" value, don't know what it means.
y/n Another "y" or "n" value, don't know what it means too.
Password "y" or "n" value, which tells if the server is password-protected.
Maximum latency The maximum latency for this server
Rating and LPI restrictions Rating and LPI restrictions for this server. This given in pairs of bytes for each value (ASCII encoded, but a hex meaning). When no rating is specified, "ff" is used (ASCII encoded). The format is as follows: [RC set rating][RC max rating][ST set rating][ST max rating][SW set rating][SW max rating][SS set rating][SS max rating][LPI minimum]. Every value between brackets represent 2 bytes. When no rating is specified, "ff" is used.
 
Thats it for the server line. There are a couple of bytes more on this line, but with no significant info it seems. As you can see, there's still some stuff i don't know the meaning of. This is mostly because i search for the meaning of the field when i need a particular one. But if you might find a meaning for one of the fields, feel free to mail.


Pinging the server
 
The game doesn't ping servers by using the conventional ICMP protocol. It uses UDP packages, with some info encapsulated. It also receives an UDP package from the server (if not, its a "ping" timeout). This received package also contains some info. I haven't done much research on this though, as this is pure byte info (no ASCII) and its very hard to find a meaning for the bytes. I do think however an update from the server state must be in there. Cause, as i stated in the readme of the serverlist program, the info fetched by contacting the sierra servers doesn't seem to update very often. Only when players join/leave and when a server switches its session (i think). In the game you _can_ see more frequent updates however, and thats why i think that info is in the data received by the UDP packages from the server. If someone has more info about this, i'd appreciate it ;).
 
But back to the ping now. Its pretty easy, you just have to send an UDP package to the server, with the following content (when analysing the packages from/to the server, it appears this info which gets sent to the game server isn't static. Again i don't know the meaning of the bytes, so i just use a static message to encapsulate in the UDP package. This doesn't seem to be a problem as i can ping the servers. The static message is this:
 
0x50 0x00 0x03 0x5e 0x53 0x00 0x00


The end

So, thats it. I hope its been usefull for someone.
 
If you have questions, remarks or corrections, please don't hesitate to mail me.

Donny Tytgat