Tom
Tom

Reputation: 6697

How to calculate a hash of all JS files loaded on page (to verify html5 game runtime)

I have made the html5 game, that users sometime may try to alter to get better highscores.

How can I count in the begin(and runtime) of game the hash of whole JavaScript game ( made with Construct2) so that I can compare if there was any changes runtime done by user.

Game is running inside iframe if it matters anything and sends highscrores after the game.

Upvotes: 1

Views: 318

Answers (1)

Mosè Raguzzini
Mosè Raguzzini

Reputation: 15851

As said in my comment, hashing your source it's not an efficient anti-hack.

The strongest way to prevent cheating is to run your engine server-side, and validate each action with a predictive client/authoritative server strategy.

Predictive client

The client engine behave as no server is involved, sending data (Eg.) only when score changes along with some additional information (Eg. gametime, position, player state etc etc). The client receive a unique token stored server side on each game session to identify it.

Authoritative server

The server, once received the score and the additional information, can run a validation against those data, eg:

  • Is the player position valid ? (Eg: inline with enemy to shoot)
  • The state of the player is valid ? (Eg: can it shoot down the enemy with a single bullet ?)
  • The score vs gametime is suitable ? (Eg: can the player has a score of 1 Billion at 2s from start ?
  • etc etc

Once validation on server side happened, you can reconciliate the game state or invalidate the game by token once finished.

Upvotes: 3

Related Questions