Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Game's score is based on a client-side countdown. How to bulletproof it?

I'm working on a game, which has score based on a JavaScript countdown: the faster you finish the level before the countdown reaches zero, the bigger your score is.

How can I make sure it is not somehow altered when I finally receive it from client-side on server-side?

My initial idea is to make two checkpoints: one at the beginning of a level and another at the end. Checkpoint is basically a session sent via AJAX to server-side PHP script which is then timestamped. So after the game is finished on client-side, the score is verified with the one on server-side. Is this kind of protection any good?

Thank you in advance!

EDIT: I'm also open to any other ways to achieve the desired functionality.

like image 215
Cinnamon Avatar asked May 02 '11 22:05

Cinnamon


2 Answers

Simply, you store the value in a datetime field in your database. Then, you seed your javascript with that value. Thus, any change on the client side, will not have an effect on the stored time.

However, if you depend on the client side to get a value, you cannot do anything to make sure it's correct. The user can still spoof the ajax request with no real problem. It makes it a bit harded, but certainly doable.

Once your countdown is somehow related to the client side, there is no escape :)

like image 154
Spyros Avatar answered Oct 16 '22 02:10

Spyros


As others have pointed out, there's no way you can be certain that the times have not been tampered with, however there are ways to mitigate the consequences:

If you have a (server-side) system that suspects that scores have been tampered, you can blacklist that IP address or cookie, and not show those scores to other users. Do show the scores to the hacker, though. This has several effects: Firstly, if they think they've beaten you they may move on and leave your code alone. Secondly, if your cheat detection wrongly thinks that a ninja player is hacking, the player will still see their score in the tables as normal (even if other players don't). Consequently, false positives don't matter so much, and you can use fuzzier algorithms, e.g. How does this player's rate of improvement compare to the average? Has he got a bunch of poor scores then suddenly an incredible one? Has my server seen an unusual pattern of hits from this user? Etc.

You could probably set this up so that you could refine your detection algorithms incrementally, and blacklist players after you've got suspicious about them (and un-blacklist false positives).

like image 22
Martin Stone Avatar answered Oct 16 '22 02:10

Martin Stone