0
\$\begingroup\$

I'm making a simple tile based 2D multiplayer game in JavaScript using socket.io where you can move one tile every 200 ms. The two solutions I've tried are as follows:

  • The client sends "walk one tile north" every 200 ms. Problem: People can easily hack the client to send the action more often.

  • The client sends "walking north" and "stopped walking". Problem: Sometimes the player moves extra steps when "stopped walking" doesn't arrive in time.

Do you know a way around these problems or is there a better way to do it?

EDIT: Regarding the first solution I've tried adding validation on the server to check if it has been 200 ms since last movement. The problem is that latency still encourages people just to spam the action as much as possible, giving them an unfair advantage.

\$\endgroup\$
1
  • \$\begingroup\$ If anyone is wondering, the first solution the edit is talking about can be seen here \$\endgroup\$
    – Heckel
    Jun 4, 2014 at 13:25

1 Answer 1

0
\$\begingroup\$

Both options are viable.

The "walk north every 200ms" can be fixed server-sided by queueing the commands of each client on the server. When the server receives "up, up, left, up, up" from one client in fast sequence, the server pushes these five move-actions on a queue and processes one input every 200ms.

The "stop walking" can be synchronizing by making the stop-position a part of the stop-message. Be careful, though: A client might attempt to manipulate the stop-location to gain an advantage. Sending move messages with stop-locations much further than the distance the client could have traveled in that time could allow speed-hacking. A heuristic approach could be used to detect this: keep a log of player positions and kick those which regularly exceed the maximum possible velocity.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .