Skip to main content
2 of 2
Clarifying
John McDonald
  • 6.8k
  • 2
  • 33
  • 46

Timing. The other answers don't mention the timing of events on the server and the different clients. Depending on the game, this could be something to watch out for. Latency (aka Lag) introduces a variable delay between when a packet is sent and when it is received. Time can be tricky, but I'll try to explain the potential issues as best I can. There are some games that can get by without worrying about this, but here's a simple example of where it can cause problems.

Assume that everyone acts on packets as soon as they arrive.

@ Time 0 (wall time), Player 1 puts up a shield   (Message has been sent, but not received by anyone)
@ Time 1, Player 2 shoots player 1   (Message has been sent, but not received by anyone)

Assume Time 0 (T0) and T1 are close together.

What happens next depends on who is looking at this, and on the order in which the packets arrive on the server. The server should always have the final say. IF the server receives the packets in the order given above, then the server will apply the shield before the shot and player 1 (P1) will survive. From P1's perspective, having put up the shield himself, he will see the shield before the shot and survive. But what about P2? They will see the shot right away because they shot it, but will they see the shield first? If (T0 + latency between P1 and the server + the latency between the server and P2) > T1, the shield will come up after the shot, and P2 will think their shot has killed P1. The server will have to correct this situation somehow.

If however, the server receives the packets in the reverse order (which is quite possible, even if T0 < T1), then the opposite occurs. P1 is wrong (and dead), while P2 is correct (and victorious).

There are a few ways to deal with situations like this, but the easiest is to let the server do everything. You can attempt to simulate this on the client, but don't allow any permanent actions, like death. The players will have to wait for important game-changing confirmations from the server.

Sending a timestamp with actions can be beneficial. IF you mostly trust the clients, then you can use these timestamps can be used to determine which action happened first, instead of following our first assumption. This can be tricky, because receiving messages from the past usually means you need to be able to reverse time.

Time is fun eh? No matter what you end up doing, it's helpful to be aware of these time issues.

John McDonald
  • 6.8k
  • 2
  • 33
  • 46