here: <django.conf.LazySettings object at 0x917134c>

About Starcraft networking model

by treeform on

About Starcraft networking model

Starcaft is the most popular RTS of all time. It might not be the best but it is the most popular. Just recently I got into an discussion on how StarCraft implements networking. We where talking about two types of networking which are lock step networking model and server correcting model.

In lock step model every thing happens on all the clients at once and only the client commands player commands are exchanged between the players. This requires 100% deterministic simulation so that each client simulates the game exactly the same.

In the server correcting model the clients also try to simulate the game world. But they don't have to be exact. Some clients can use GPU for physics while other use CPU. Some clients might not even have access to the whole game state just what server gives them. Server periodically corrects the clients.

Starcarft definitely uses lock step model of networking.

Starcarft packets are divided into 2 main groups. The Command1 group and the Command2 group. Command1 groups packets handles with joining or leaving the game while Command2 group handles what happens during the game.

Command Group 1

Each command one packets stars with a Command1 packet header. This includes check-sum to verify the packet is correct. Thats odd considering the network software/hardware already should do that for you even when you are using UDP. Then it also contains flags to verify and resend lost packets. Does not appears that there is a notion of unimportant packets - probably no need to since this is using lock step model. Then it has sent and receive counters - so that packets stay in order. The flags and ordering combined nicely make the packet loss-less TCP type connection work over UDP.

The commands in this group includes Join Requests, Ping, Pick Player position, team, and race, Get Game state, Get Map and Map options, and some Leave Messages.

The random seed is also generate at game start. Even though random numbers are random they sequence they come in is not. And this sequence is picket at game start and is used for the duration of the game.

Command Group 2

This command group is more interesting because its where the real time messages happen. They are very similar to the command 1 group. The messages are sent about 4 a second. Avg time between messages is not quite 250ms but is 219ms probably because the speed constant is easy to tweak. The interesting thing is that every time step a command group 2 packet is sent. Each command group 2 packet contains N sub packets or a special NULL packet if there isn't any. This is how starcaft knows when to start a new simulation turn I guess when it has gotten all packets for that time step from all connected clients.

The type sub packets are a lot like what 2aw has. There is player selected units packet and a player selected units to add. Kind of odd considering you can select up to 12 units any ways.

The is order packet which is used for all the orders. There is lots of different orders in starcaft even if you don't realize it.

Then there is a lot of packets which just active deactivate abilities. I find this odd because there is ton of abilities in starcaft and i would have though that having just use ability and stop ability with and ability ID inside the order would have been enough. If they wanted to optimize and move the ability ID into the space of packets why didn't they do that for orders too?

There is no order queues in starcaft. Some thing that was one of the 1st features to make it in 2aw because i love it so much.

There is also some messages commands - interesting to note that both command1 and command2 has sending message packet, one in the game lobby and one in game. Its interesting that game lobby is handled by the local game server rather then the battle net lobby - which I would have though be more logical.

Note there is no unit positions, health, or stats updates ever. Even when they get build or die. Only what player clicks and orders - that is because using lock step networking model all of that can be derived.

RTS Networking

Talking about RTS networking always deserves a metnio of the "1,500 Archers" paper about networking in Age of Empires. It looks like starcaft does it nearly the same. I wonder what the modern RTS like SupCom, WC3, Wic, and SoSE doe for networking. Do they jump on flexibility of server correcting model or do they still stick with tried and true lock stepping model.

See more info here:

blog comments powered by Disqus