before people mention that such questions have been asked I would like to tell that yes they had been but I am trying to find an answer which suits my situation much better.
I am working on a networked game in which player moves 32 pixels every time they press a direction key (That is they move 1 tile at 1 press of key). My client does collision check etc and then send a packet to server with the direction player pressed key. The client moves the player 2 pixel a frame and hence it takes 16 frames for client to move a tile and while the player is moving, it cannot send any movement update to server.
The server on the other hand as soon as receives a packet, queues it up for the player. I have movement threads running which run every 2ms and check for every player queue and then if player has movement, it updates the other client as well as checks whether player is on correct tile (making sure he is not cheating). The server also checks if player is on a warp tile (there are tiles on which if you step you will be warped to the other map) and other such tiles which the server checks. The server does this by adding (+32, -32) in x or y co-ordinates depending on direction and then checking the new tile type etc. If the player is on an incorrect tile, he was synced back to original tile.
Everything was working fine until I tried it on a real network. Now i receive lag for example when there is a warp to a new map, sometimes the player and server goes out of sync.
Basically there are many synchronization issues I am getting and I am wondering should I rather go to an authorative-server based approach where server will tell client when to move and when not to move. I can post code if needed.
I am using TCP protocol because the game doesn’t need to be Real-time. What’s important is reliability of messages.