Single player with Multiplayer stuff networking structure

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By jujumumu

I am making a game that you play by yourself but with multiplayer addons like chats and clans. To prevent hacking I would assume that you send the server the user input and it sends back the output or what it should display. Am I correct?

:bust_in_silhouette: Reply From: Zylann

Sending inputs, simulate on server and get back the result on client is indeed a way to keep the server authoritative of the game state. You need to compensate for lag, though. You can do that by simulating also on the client just for visual purposes, and then when you get new state from the server you overwrite the local state. Hopefully they match up and no jitter will be visible.

There is timing subtleties involved. For example, all state you receive from the server will always be in the past. So you may want to send your input in the future, so when the server receives them, it will actually use them only once your ping has gone round-trip. The result being, your client may also start processing your input late for visual purposes, and when the server sends you the real state, they will arrive at matching time to avoid state “jumping”.

I suggest you take a look at this video, as it explains the technique overall https://www.youtube.com/watch?v=rtcERbTybj8