In the context of lag compensation, one needs to know when the command is instantiated on the client (this can be named as "command execution time" as well). AFAIK, there can be 2 methods for this:
- Client sends a timestamp with the command.
- Client doesn't send any timestamps, but server does a smart thing to calculate the command's instantiation time.
About #1:
- Is this safe in terms of cheating?
About #2:
According to Valve's paper, command execution time is as following:
Command Execution Time = Current Server Time - Packet Latency - Client View Interpolation
This means, server must know the packet latency.
Another paper from Valve confirms this and says:
Before executing a player's current user command, the server:
- Computes a fairly accurate latency for the player
- ...
- How can the server compute "fairly accurate latency for the player"?
Most naive and easiest approach would be sending pings regularly (less frequent than game commands and updates though) to find out an average of the latency and use it. Busy network traffic, latency fluctuation and naiveness of this method makes me feel there must be a more elegant way.
EDIT: Would UDP vs TCP change anything in this context?