Regardless of the opinions regarding the approach, what you are looking for is a threshold of speed, which is considered a "hoax". Given the distance and the increment of time, you can trivially see if they have moved "too far" based on your fraud threshold.
time = thisTime - lastTime; speed = distance / time; If (speed > threshold) dudeIsCheating();
The time used for measurement is the time the packet was received. Although this seems trivial, it calculates the distance for each character movement, which can be very costly. The best route is to calculate the server location based on speed, and this is the character position. The client never associates a position or absolute speed; instead, the client sends a "percentage of maximum" speed.
To clarify: This was only for checking fraud. Your code has the ability to delay or lengthy processing on the server, affecting your result. The formula should be:
maxPlayerSpeed = 300; // = 300 pixels every 1 second if (maxPlayerSpeed < (distanceTraveled(oldPos, newPos) / (receiveNewest() - receiveLast())) { disconnect(player); //this is illegal! }
This compares the speed of the players with the maximum speed. Timestamps are determined when a packet is received, and not during data processing. You can use any method that you want to determine to send updates to clients, but for the threshold method that you want to determine fraud, the above will not be affected by the lag.
Receive packet 1 with second 1: character at position 1
Get package 2 with second 100: character at position 3000
distance traveled = 2999
time = 99
rate = 30
Nothing has happened.
Get package 3 with second 101: Character at 3301
distance traveled = 301
time = 1
rate = 301
Cheating detected.
What you call a “lagging spike” is really a high delay in packet delivery. But it does not matter, since you do not pass when the data is processed, you pass when each packet was received. If you save time calculations regardless of the processing of the tick of your game (as it should be the way it happened during this checkmark), high and low latency only affect how confident the server is in the position of the character that you use for interpolation + extrapolation for resolution.
If the client is not synchronized enough with the one where it has not received any corrections to its position and is not strongly synchronized with the server, there is a significant loss of packets and high latency that your fraud check will not be able to take into account. You should consider this at a lower level with the handling of actual network messages.
For any game data, the ideal method is designed for all systems, except that the server runs for 100-200 ms. Let's say you have a supposed update every 50 ms. The client receives the first and second. The client has no data to display until it receives a second update. Over the next 50 ms, it shows the progression of the changes, as it has already happened (i.e. with very weak slow-motion playback). The client sends its button states to the server. The local client also predicts motion, effects, etc. Based on these button presses, it only sends the “button state” to the server (since there are a finite number of buttons, there are a finite number of bits necessary to represent each state, which allows using a more compact packet format).
The server is an authoritarian simulator that determines the actual results. The server sends updates to each client, say, 50 ms. Instead of interpolating between two known frames, the server instead extrapolates the positions, etc. For any missing data. The server knows what was the last real position. When it receives an update, the next package sent to each client includes updated information. Then the client must receive this information before reaching this point in time, and the players react to it as it is, without seeing any strange jumps, because they never displayed the wrong position.
Perhaps the client should be authoritarian for some things or make the client act as an authoritative server. The key determines the impact of trust on the client.
The client should regularly send updates, say, every 50 ms. This means that the 500-second “delayed burst” (packet reception delay), or all packets sent during the delay period, will be delayed by the same amount, or the packets will be received out of order. The underlying network must correctly handle these delays (discarding packets that have too much delay, delivering packets, etc.). The end result is that with proper packet processing, the expected problems should not arise. In addition, do not receive explicit symbol addresses from the client and instead the server explicitly fixes the client and receives only control states from the client, this will prevent this problem.