🕹️ Game Tech

Updated at 2014-12-25 20:20

This note is about networking and multiplayer in video games.

Keep logic on the server. Run everything that affects gameplay on the server. When in doubt, server is always right.

Revert to last known valid position on conflicts.

Clients send only actions. That is the safest way, actions like "jump" or "move forward".

Servers respond with absolute values. Send absolute information from server to client. They might have missed a package. Not "HP -20" but "now HP 80".

Keep networking minimal. Compact your data and send as few bits as possible.

Leave update responsibility to the client. Have a timeout after which disconnect the client. Ping first if only idling.

Have a small buffer time that you wait for actions.

Each 100ms - 200ms is a "turn". On turn 1002, execute actions from turn 1000 so all have been gathered.

Simply calculating required bandwidth for a multiplayer game server.

B = k * n^2

B = consumed bandwidth k = input rate n = number of players ^ 2 = propagates to other players

Ensure n is small, don't do MMO. Region of interest management, limiting n. Throttling, limiting k.

There will always be lag.

How to manage data consistency:

Synchronous An entity that syncs the game state. Slow, more input lag. Easy to manage. Asynchronous Multiple asynchronous entities that form the game state. Fast, less input lag. Hard to manage.

Single master server. Lock-step sync.


Dead-reckoning with correction. Process inputs in any order as soon as they are received. Take input, apply it, estimate. When new input comes, estimate and correct previous estimates.

Local perception filters. Process inputs in causal order.

Master replication.