views:

1550

answers:

5

I was wondering how the Half-Life 2 multiplayer protocol works in mods like Counter-Strike: Source or Day Of Defeat: Source. I believe that they use some kind of obfuscation and proprietary compression algorithm. I would like to know how different kinds of messages are encoded in a packet.

+4  A: 

This is a really complicated question, my suggestion would be to look at some of the open source network game engines:

You could also look at the source code for the quake series upon which the original half life engine is based.

jonnii
Focus on the branches of the Quake engine--some ended up building up to the point of compatability with Half-Life. Engines like FTEQuakeWorld or TomazQuake might be good jumping-off points.
A. Scagnelli
@A. Scagnelli, The Source engine (Half-Life 2's engine) is not based off the Quake engine. So while it would be good for learning basic client server concepts, it is not going to give you the exact code.
James McMahon
Nothing is going to give you the exact code, except for licensing the engine. And the Source Engine does have roots in the Quake Engine.
Aistina
@nemo: HL2 is supposed to be mostly new code, but AFAIK some Quake engine code still exists in there. The network code is probably different though.
abababa22
Quake engine is rock solid, I'd be looking to do what id did as much as possible.
Sneakyness
+32  A: 

Half-Life 2, Counter-Strike:Source etc all use Valves Source engine. Valve has a developer wiki which covers a lot of stuff (its pretty cool check it out!)...

These articles might interest you:

Latency Compensating Methods in Client/Server In-game Protocol, Design and Optimization

Source Multiplayer Networking

Chalkey
I wonder how much rep is needed to add links. It doesn't appear in the faq.
Copas
I think it might be something to do with me only making the account a few days ago :)
Chalkey
I'm mostly interested in the delta compression and structure of the packet headers and I wasn't able to find that information.
JtR
Just leave comments down here, not in the answer.
GMan
Edited by G-Man :), I wonder where the hell Dr. Freeman is right now...
Tamás Szelei
I fixed the second link, nice articles.
James McMahon
These links don't reveal how it encodes different kinds of messages in a packet.
JtR
+3  A: 

Though details might differ, the general framework is pretty old. Here's a quick overview:

In early fps games such as doom and Quake the player's position was updated only on the server's response to your move command. That is, you pressed the move-forward button and the client communicated that to the server, the server udpated your position on its memory and then relayed a new game-state to your client with your new position. This led to very laggy play: shooting, even moving in narrow corridors was a game of predicting lag.

Newer games let the client handle the player's shooting and movement by themselves. Though this led to lag-less movement and fire it opened more possibilities of cheating by hacking the client code. Now every player moves and fires independently on their own computer and communicates to the server what they have done. This only breaks down when two players bump into one another or try to catch a power up at the same time.

Now the server has this stream of client state coming from each player and has to sync them and make a coherent game out of them. The trick is to measure each player's latency. The ultimate goal is to be able to fire a very low latency weapon (such as sniper rifle or railgun) on an enemy moving sideways and have it hit correctly. If the latency from each player is know, suppose player A (latency 50ms) fires a gun on B (latency 60ms). To make a hit, the shot has to hit B where B was 60ms ago, from where A was 50ms ago.

That's a very rough overview but should give you the general idea.

Kristoffon
This doesn't explain how different kind of messages are encoded in a packet.
JtR
"Now every player moves and fires independently on their own computer and communicates to the server what they have done." This is not true, at least in Half-life 1. The client is just able to run the same simulation locally to create illusion of zero lag, but server still gets control inputs normally, not the full state. The server also still has the final word about what's happening, so clients can't use this to "break the game rules"
abababa22
+3  A: 

You should check out Luigi Auriemmas papers on Half-Life. You'll find a packet decoder and some disassembled algorithms there, too.

Reverse engineering information on Half-Life 2 may be hard to come by, because of its relevance for cheating. I'd guess boards like mpcforum are your best bet.

ko-dos
This is the best answer so far even if it doesn't contain the exact answer. At least I have a remote chance to find someone who would know about this from that forum, thank you!
JtR
+1  A: 

I suggest that you look into Quake 1-3 engines. They are available with source code. Half-life's protocol might be a bit different but most likely close enough.

abababa22