CS-Reloaded Banner
Welcome, Guest. Please Login or Register.
Download Third Map Pack!
Get more packs here

Home Help Search Login Register

CSReloaded Forums  |  General Category  |  CS: Source (Moderator: [Guardian] Alkali)  |  Topic: css protocol
Pages: [1] Reply Notify of replies
   Author  Topic: css protocol  (Read 89 times)
LeGrand
CSR Veteran
***
Karma: +12/-3

Offline

Gender: Male
Posts: 199

160796748 160796748 peter_nejsum
View Profile WWW E-Mail
css protocol
« on: March 02, 2006, 02:33:51 PM »
Reply with quote

Hey guys'n'gals!  it's been a while
well anyway I was thinking about making myself a lil' program in C++, that keeps me updated on the number of players on a given server and stuff like that...so I was thinking "I prolly need to take a look at the protocol" but I haven't really been able to find anything usefull...perhaps any of you ppl can help me?

-LeGrand

NB. Great to be back 
Logged

Terraji
Admin Team
CSR Connoisseur
*****
Karma: +35/-15

Offline

Gender: Male
Posts: 789

terraji@hotmail.com
View Profile E-Mail
Re:css protocol
« Reply #1 on: March 03, 2006, 09:03:47 AM »
Reply with quote

I would advise checking the Source SDK docs first.

There is probably already a bunch of tools that do this. You could check the source for them and see what they do.

If all else fails, you could get a network protocol analyiser and watch the payloads. I wouldn't imagine it too hard to reverse engineer and assemble the packets yourself.
Logged
Porter
[Wumpa]
Board Admin
*****
Karma: +176/--88

Offline

Gender: Male
Posts: 3910

Wumpa+Porter
View Profile WWW E-Mail
Re:css protocol
« Reply #2 on: March 04, 2006, 09:42:14 PM »
Reply with quote

A complete specification for the query protocol of any Source-based server, CS:S included. That should do ya.

http://dev.kquery.com/index.php?article=46


Also, you might want to check out the PHP code in my SourceForge project, HL Who's Online. There's a query class there that handles the protocol completely, and PHP is very similar in syntax to C so it might give you some implementation hints.

http://hlwhosonline.sf.net


Lastly, a program called qstat, which is written in C and has been ported to many many platforms, includes Source server query support. It would be far easier just to write a parser for its output than starting from scratch.

http://www.qstat.org/

Good luck! Let us know what you come up with!
Logged

[Wumpa] Porter
  --Silent, professional, lethal... sometimes.
Porter
[Wumpa]
Board Admin
*****
Karma: +176/--88

Offline

Gender: Male
Posts: 3910

Wumpa+Porter
View Profile WWW E-Mail
Re:css protocol
« Reply #3 on: March 04, 2006, 09:44:11 PM »
Reply with quote

Quote from: Terraji on March 03, 2006, 09:03:47 AM
If all else fails, you could get a network protocol analyiser and watch the payloads. I wouldn't imagine it too hard to reverse engineer and assemble the packets yourself.

That might be difficult only because for Source the query protocol is two-way. A client must request a challenge number, and use it in all subsequent queries. That would be easy to miss if you were only looking at incoming traffic.

Thankfully there's plenty of documentation on it out there, and plenty of apps already written to scratch this particular digital itch.
Logged

[Wumpa] Porter
  --Silent, professional, lethal... sometimes.
Terraji
Admin Team
CSR Connoisseur
*****
Karma: +35/-15

Offline

Gender: Male
Posts: 789

terraji@hotmail.com
View Profile E-Mail
Re:css protocol
« Reply #4 on: March 05, 2006, 11:56:29 AM »
Reply with quote

I would agree that the path of least resistance would be to use an existing solution, but to prove my point (and satisfy some curiousity) I used ethereal to sniff some traffic.

For a particular server I grabbed at random (68.105.95.92), I looked at the traffic sent to and from when examining it in the server browser. The protocol is UDP which makes sense when you think about it, with potentially zillions of requests, using TCP would be an invitation for a DoS.

The hex data is on the left, and the ascii equivalent on the right (non printable characters are dots).

1) just scanning for servers 1 request packet, 1 reply
request:
Code:
0000  00 13 46 4a c5 d8 00 0e  a6 45 bd 5a 08 00 45 00  ..FJ.... .E.Z..E.
0010  00 35 26 07 00 00 80 11  b0 41 c0 a8 00 02 44 69  .5&..... .A....Di
0020  5f 5c 04 35 69 87 00 21  6e c6 ff ff ff ff 54 53  _\.5i..! n.....TS
0030  6f 75 72 63 65 20 45 6e  67 69 6e 65 20 51 75 65  ource En gine Que
0040  72 79 00                                          ry.             

reply:
Code:
0000  00 0e a6 45 bd 5a 00 13  46 4a c5 d8 08 00 45 00  ...E.Z.. FJ....E.
0010  00 6b ee 3e 40 00 32 11  f5 d3 44 69 5f 5c c0 a8  .k.>@.2. ..Di_\..
0020  00 02 69 87 04 35 00 57  99 20 ff ff ff ff 49 07  ..i..5.W . ....I.
0030  5b 53 53 5d 47 61 6d 65  43 75 62 65 00 63 73 5f  [SS]Game Cube.cs_
0040  61 73 73 61 75 6c 74 00  63 73 74 72 69 6b 65 00  assault. cstrike.
0050  43 6f 75 6e 74 65 72 2d  53 74 72 69 6b 65 3a 20  Counter- Strike:
0060  53 6f 75 72 63 65 00 f0  00 05 09 05 64 6c 00 01  Source.. ....dl..
0070  31 2e 30 2e 30 2e 32 37  00                        1.0.0.27 . 

Containts the server name ([SS]GameCube), map, and type of game. The server size and amount of players inside are definitely in the last few bytes encoded as 4 or 8 byte integers.

When right-clicking and viewing server info: 2 requests and 2 replies.

request:
Code:
0000  00 13 46 4a c5 d8 00 0e  a6 45 bd 5a 08 00 45 00  ..FJ.... .E.Z..E.
0010  00 35 26 8b 00 00 80 11  af bd c0 a8 00 02 44 69  .5&..... ......Di
0020  5f 5c 04 35 69 87 00 21  6e c6 ff ff ff ff 54 53  _\.5i..! n.....TS
0030  6f 75 72 63 65 20 45 6e  67 69 6e 65 20 51 75 65  ource En gine Que
0040  72 79 00                                          ry.   

reply:
Code:
0000  00 0e a6 45 bd 5a 00 13  46 4a c5 d8 08 00 45 00  ...E.Z.. FJ....E.
0010  00 6b ee ba 40 00 32 11  f5 57 44 69 5f 5c c0 a8  .k..@.2. .WDi_\..
0020  00 02 69 87 04 35 00 57  99 20 ff ff ff ff 49 07  ..i..5.W . ....I.
0030  5b 53 53 5d 47 61 6d 65  43 75 62 65 00 63 73 5f  [SS]Game Cube.cs_
0040  61 73 73 61 75 6c 74 00  63 73 74 72 69 6b 65 00  assault. cstrike.
0050  43 6f 75 6e 74 65 72 2d  53 74 72 69 6b 65 3a 20  Counter- Strike:
0060  53 6f 75 72 63 65 00 f0  00 05 09 05 64 6c 00 01  Source.. ....dl..
0070  31 2e 30 2e 30 2e 32 37  00                        1.0.0.27 .     

This is the same query as above if you hadn't noticed.
request 2:
Code:
0000  00 13 46 4a c5 d8 00 0e  a6 45 bd 5a 08 00 45 00  ..FJ.... .E.Z..E.
0010  00 25 26 8f 00 00 80 11  af c9 c0 a8 00 02 44 69  .%&..... ......Di
0020  5f 5c 04 3e 69 87 00 11  d8 96 ff ff ff ff 55 ff  _\.>i... ......U.
0030  ff ff ff                                          ...             


reply 2:

Code:
0000  00 0e a6 45 bd 5a 00 13  46 4a c5 d8 08 00 45 00  ...E.Z.. FJ....E.
0010  00 68 ee d4 40 00 32 11  f5 40 44 69 5f 5c c0 a8  .h..@.2. .@Di_\..
0020  00 02 69 87 04 3e 00 54  ea 83 ff ff ff ff 44 05  ..i..>.T ......D.
0030  00 53 63 6f 74 74 00 11  00 00 00 00 00 80 bf 02  .Scott.. ........
0040  52 6f 6e 00 bd 00 00 00  00 00 80 bf 03 4b 65 76  Ron..... .....Kev
0050  69 6e 00 22 00 00 00 00  00 80 bf 04 45 72 69 6b  in.".... ....Erik
0060  00 2f 00 00 00 00 00 80  bf 08 44 61 6e 00 35 00  ./...... ..Dan.5.
0070  00 00 00 00 80 bf                                  ......   


There you go, a bunch of names (there were bots on this server) and a bit of data after each which obviously contains their score and possibly their ping.

Simple and elegant, just as one would expect.
I <3 the internet.
Logged
Porter
[Wumpa]
Board Admin
*****
Karma: +176/--88

Offline

Gender: Male
Posts: 3910

Wumpa+Porter
View Profile WWW E-Mail
Re:css protocol
« Reply #5 on: March 05, 2006, 01:36:06 PM »
Reply with quote

Insightful, definitely. Complete? Probably not. It would be a great start if the game developers kept the source code and protocol closed, but you'd still have a ton of work to do to reverse engineer the rest.

Having implemented the protocol myself (there were no existing PHP packages), I can tell you there is a bit more to it. For one thing, the protocol has to include packet ordering information since it's UDP based and because some Source query responses are larger than one packet. Strangely, that packet order information is ONLY included in the packet if there will be more than one packet in the current response. Reassembling them in order is a pain the butt in its own right since there's no way of knowing ahead of time how many packets will be included in a given response. And then there's the fact that there are actually 3 or 4 different queries commands you can send a Source server: one to request a challenge number (which as I said before is unique to the current connection and must be included in all subsequent queries), one for general information, one for player information, and one for rules.

I'm not saying it's not possible, but simply replicating the sniffed packets wouldn't get you very far because of the challenge number issue alone. Source servers silently ignored invalid requests, so right off the bat you'd be up against a continuous no-response scenario.



...I don't get to talk "code" with people very often. This is fun!
Logged

[Wumpa] Porter
  --Silent, professional, lethal... sometimes.
Pages: [1] Reply Notify of replies 
CSReloaded Forums  |  General Category  |  CS: Source (Moderator: [Guardian] Alkali)  |  Topic: css protocol
Jump to: 

Powered by PHP CSReloaded Forums | Powered by YaBB SE
© 2001-2003, YaBB SE Dev Team. All Rights Reserved.
Powered by MySQL
:[ Site Design by Ryo, scripts and backends by Porter and Ryo, banner by Supafly! Powered by PHP and MySQL ]:
Page created in 0.036 seconds.