View Single Post
Old 06-15-2006, 10:45 PM   #1 (permalink)
Redline
PHP Student
 
Join Date: Oct 2004
Location: Forest Grove, OR
Posts: 150
Redline is on a distinguished road
Send a message via AIM to Redline Send a message via MSN to Redline
socket based CS server query

I've been pulling my hair out trying to figure out how to do info queries on counter-strike servers.

I ended up having to use Ethereal to catch UDP packets and find out exactly what I send to the counter-strike server when I do a refresh. The initial query is always the same. It's a padded string which basically says "Source Engine Query.":
Quote:
\377\377\377\377\124\123\157\165\162\143\145\40\10 5\156\147\151\156\145\40\121\165\145\162\171\0
After sending that message, I get back some basic server info. The address, name, current/max players, etc. Here's a sample response converted to ascii:

Quote:
0. ÿÿÿÿm69.90.60.125:27015
1. [euphNET] Pub #1
2. de_nuke
3. cstrike
4. Counter-Strike
5. /dl
6. www.counter-strike.net
7.
Now in order to get the list of players and scores, I have to send a response to this. It's different for each server, but every time it's a 9 byte string consisting of a static 5 byte header. Only the following 4 bytes are different per server. Here is the key for this particular server:

"\377\377\377\377\125\247\304\302\72"

So far, this 4 byte key hasn't changed the the server I've been testing on over the last few days.

The key is not calculated on the server name, map name, or number of players as far as I can tell, otherwise the key I've been using for the test server wouldn't be valid anymore. Maybe it's based on the server address? If it is, I haven't been able to figure out how it's derived.

I spent most of the day today coming up with a regular expression to extract player id's, names and scores from this mess of octal values. As soon as I figure out how to generate "callback" keys, I'll start turning this into a class, and work on rcon. This is just a project to help me learn socket programming. I'd never touched them before; there was a bit of a stigma around the concept for me.
__________________
Current Project
Redline is offline   Reply With Quote