How to protect code in HTML5/Canvas game?

跟風遠走 提交于 2020-01-11 12:13:21

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/17102665/how-to-protect-code-in-html5-canvas-game

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!