Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'll start by saying that I am fully aware that this question might seem subjective at first, but I'll try and provide a specific test case scenario for it to be a clear question about validating the data received from 2 multiplayer game clients.

Scenario

Imagine we have a multi-player Tower Defense (TD) game. And let's assume that the game is built using HTML5 Canvas, Javascript and a multi-threaded web server, for example, Tornado running in the back-end. And in this scenario both of the players have an option to place a turret anywhere they want.

After a turret is placed, a bunch of enemies are released from both sides and move in a straight line towards the other side.

As soon as an enemy reaches turret range, we can assume that it is destroyed in 1-5 shots. If it takes more than that, the enemy safely passes to the other side. Now, my problem lies in the fact that usually I would do all the validation server-side, but it becomes increasingly difficult to do, because I would need to simulate every step of the game.

Instead, I would like to depend on the event data (enemy destroyed/enemy gets safe passage) received from both clients.

Question

The main question then is this:

What is the best and hopefully easiest way to implement these sorts of checks and would there be anything prohibiting me from continuing with the development using HTML5, Canvas and Javascript?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

The most efficient way of preventing cheating is to let both competitors run the same simulation and only have the server run it when and if the players' machines disagree on the result.

This requires a deterministic engine and a precise history of player actions. Thus you should have the players send their orders to the server, have the server give the order a time stamp, and then send it back to both players for execution. The server should also inform players if no actions have taken place in a given time frame so that they can advance their simulation.

For a tower defence game you may want to use a simple engine that runs relatively few simulation steps, and then interpolate those to get fluid animation, thus if the server has to validate the result only the simple part needs to be run.

Node.js is an obvious choice for platform as that makes it easy to migrate client code to the server.

share|improve this answer
    
Thanks. I do hear a lot of people recommending using node.js, but since this project is 50% game development and 50% me learning Python, I'll stick to Tornado. But the validation logic won't change anyway, so - good answer! :) –  leo.vingi Jan 31 '12 at 14:49

Why not use your game engine (without the visuals) as a server with node.js or something similar? Then you could run the simulation server-side and periodically sync with clients, and most of your codebase would be the same for both the game and the server.

Alternatively, if you wish to tunnel only events through the server, I would recommend you to set one client as the master, so that after all the events are exchanged, whatever happened on the master is final and syncs to other client(s).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.