6
\$\begingroup\$

Possible Duplicate:
How do you prevent your JavaScript / HTML5 web game from being copied or altered?

If a game client is developed in Javascript, the source code can be found in browser. It's dangerous, because it's easy to hack the game, and patent can't be protected.

Are there any good ways to avoid this, e.g Javascript can be compiled to binary file then browser load and run the compiled javascript?

\$\endgroup\$
2
  • \$\begingroup\$ Despite the fact this is an exact duplicate, it got voted up 3 times and there are 4 answers. I think that says something about the effectiveness of this site and it's users in helping people find previously asked questions. \$\endgroup\$
    – Tim Holt
    Jul 12, 2011 at 16:46
  • \$\begingroup\$ When I was asking the question, I had a look at the similar question list, but didn't find a "exact duplicate" one. If this boring you, you can provide a link to the "exact duplicate" one, instead of complain in comment. I' glad to remove the question. \$\endgroup\$ Jul 13, 2011 at 1:59

4 Answers 4

10
\$\begingroup\$

The bottom line is there's no bullet-proof way to protect your HTML5/Javascript code. Obfuscation and minification will act as a deterrent. Closure Compiler is one such minifier.

If you really want to prevent people from cheating, store the state of the game on the server and turn the web page into a presentation/input layer that communicates with the server.

\$\endgroup\$
0
2
\$\begingroup\$

It's dangerous, because it's easy to hack the game, and patent can't be protected.

If a user hacks your game and cheats he ruins his own fun. The same can be done with desktop applications, it's just not as easy.

For the record flash applications are rather easy to decompile and hack aswell so most web platforms have this problem.

If a user can actively change public data by hacking with the client-side javascript then you have a vulnerability in your server. Any data which a user shouldn't be able to change should either live somewhere the user can't touch it (a server) or have a proper authentication portal in front of it so it can't be changed.

\$\endgroup\$
2
\$\begingroup\$

You can't stop people from reading your JavaScript, so consider that part of the game open-source. Design your game in such a way that seeing that code won't matter. Mostly this is done by only implementing the user interface, visuals, and sounds on the client-side; everything else in the game is done on your server and communicated between the client and server using AJAX techniques.

This exact same approach applies to Flash games as well, btw.

\$\endgroup\$
0
\$\begingroup\$

One of the first thing you can do to try to prevent people reusing your source code is to obfuscate it, meaning making it unreadable, thus very difficult to understand.

Then there's no javascript compiler, as it's interpreted in the browser (so you'd need to compile it to all existing browser).

\$\endgroup\$

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