Warzone 2100 Resurrection

Network code

From WarzoneWiki

Jump to: navigation, search

The network code in Warzone uses TCP to implement a peer-to-peer decision making network with a central hub or server that redistributes messages from other hosts (in lib/netplay/netplay.c). Each host has responsibility for its own droids and structures, and sends decisions about them to other hosts (primarily in src/multistruct.c) and checks that they have the same data as it does (in src/multisync.c). Features are owned by the first player.

Projectiles are not sent on the network. Instead, each player processes each game object and figures out on its own where it would fire and sends a projectile in that direction. Since they have the same code and, hopefully, the same data, they will fire at the same targets. The player who owns the object being targetted checks for hit and damage, and if damaged, sends an object update packet over the network to the other players.

Warzone is designed to be very relaxed about getting things right on the first try, and does absolutely no data locking or permission queries before sending decisions to other hosts. Errors are expected and corrected during the checking phase.

There are many things that need to be improved in the network code:

  • The TCP hub connections model is not very efficient, and means that if the host goes down, everyone else go down with it, too. Instead, everyone should try to connect to everyone else, and continue with anoter hub if the old “hub” goes down.
  • The use of TCP instead of UDP makes the implementation a lot easier, but most games that use a peer-to-peer distributed decision making system also use UDP for the lower overhead and faster transmission times.
  • The checking code only checks and corrects data about droids, structures, power and scores. It does not check and correct other states like research, visibility, the map and templates.
  • There should be a way for players to reconnect if they are dropped during the game.