1

How do game manufacturers prevent visitors from seeing the game code by right-clicking on the page in web browsers in popular HTML5/Canvas games? Are all the game code on the server and just a small part of the game code in the browser and then there is some kind of communication between server and browser with Ajax, Websockets or what?

I am curious and would like to know more about this? I'm learning game development in HTML5 with Canvas and I don't want to share all the code that I have spent so many hours to develop. How can I protect it?

Charles
  • 50,943
  • 13
  • 104
  • 142
3D-kreativ
  • 9,053
  • 37
  • 102
  • 159
  • 5
    If you're going to work on the web, get used to sharing code. – DA. Jun 14 '13 at 06:51
  • 1
    since most of your game code will be in JavaScript, you can obfuscate JavaScript code but you cannot hide its programming logic. – AurA Jun 14 '13 at 06:51
  • 1
    open source it, people could participate to the dev and make your game even better – Jonathan de M. Jun 14 '13 at 06:52
  • 1
    possible duplicate of [How to hide or encrypt javascript code?](http://stackoverflow.com/questions/1020368/how-to-hide-or-encrypt-javascript-code) – JJJ Jun 14 '13 at 06:56
  • @Juhana I read some of the info from the link to gave and there I found this: "If you have anything in particular you want to hide (like a proprietary algorithm), put that on the server." That's what I'm looking for. I don't mind sharing some of the code, but it would be sad if someone just copyied the code and made there own game of it! I would like to know more how to put code on the server, but i don't know where to fint info about? – 3D-kreativ Jun 14 '13 at 07:07
  • 2
    We'd need to know a lot more about your game to even be able to say if it makes sense to have any of the code sitting only on the server. Again, if you're building web apps, you really need to let the whole 'hide the code' thing go. – DA. Jun 14 '13 at 07:22

2 Answers2

9

There isn't a way to hide your javascript from the end-user.

In order to execute it, it must be loaded by the users web browser. When it's on the users machine, the user can look at it.

You could use an obfuscator to make your code harder to read, but as long as it is readable for the browser, it is also readable for a determined human. Either live with it, or move your critical business secrets to server-sided code, and communicate with it through AJAX or web sockets.

Philipp
  • 67,764
  • 9
  • 118
  • 153
  • Thanks for the answer. I would like to know more about how to use server-sided code for some part of the game. But I'm not sure how the structure would look like. Can I run a javascript on a PHP-page only on the server and what type of "things" can I use Ajaxs and web sockets for? What would I serach for to get more information about this? – 3D-kreativ Jun 14 '13 at 08:47
  • You sould search for 'AJAX' and 'Web Sockets'. They're basically a way to send data back and forth from the server to the browser. Does it make sense for your game? It depends entirely on what kind of game you're talking about. – DA. Jun 14 '13 at 17:47
1

There really isn't a way you can hide it per se.

However, minifying your code after completion makes it harder to decode (not to mention makes it run faster on many browsers). When whitespace is removed, code is all shoved into one line, variable names are reduced to single letters, and certain key things from the source are removed for optimization, it becomes increasingly difficult to figure out what the programmer is accomplishing with their code.

Marc Marta
  • 542
  • 2
  • 10