So I've been coding a little project in JS recently, using node.js and socket.io to create a server, and HTML5 canvas to draw the client side. The user receives info from the server every 20ms, and the client interprets the data and displays it. If the user presses a key on the keyboard, it stores this information and sends it to the server instatly - so currently, the code is basically 'is keyboard pressed? if yes, send data to server'.
This has all worked great so far, however recently I increased the servers enemies (AI objects) from only 10 to a whopping 100... this lagged the server. Although I will work out enemy spawning efficiency later, the problem that immediately became apparent is that the user's character moved slower when the server was lagging. This meant that chasing enemies were able to easily catch up to the character and kill him, whereas usually the character could run away with relative ease.
This leads me to the question, what is the most efficient way that the server can interpret the keypresses of the user, and ensure that even if it is lagging that enemies will move at the same proportional speed to if the server wasn't lagging.
Sorry if this question is long-winded, any advice or help would be greatly appreciated. I assume that the same methodologies should apply from different coding languages, so if you have a vague idea how it works in a language you've used... please still share! :)
Thanks,
Cameron