How to protect js from custom events

久未见 提交于 2020-01-17 08:05:34

问题


I am writing a game on Javascript with canvas and easeljs and I wonder if there are any ways to protect it. For example, I use stage.Addchild(index) to add a new object to the stage. Simply editing DOM I can attatch new event handler and fire it, something like <body onclick="stage.removeChild(0)"> and this will remove all the stage objects one by one.

I was thinking to filter all the coming events and check what had fired it. But I am not sure how to do that and there may be better ways to make it... Please point me in the right direction...


回答1:


The best way to protect your Javascript is put all of your initialization code into closures and not expose anything against global variables.

However, this only provides some guarantees against run-time namespace clashes and is meant to be used as good development practice.

You cannot trust any code run on the client side; for anti-cheat behavior you need to check incoming inputs on the server-side. The users have 100% control over what is running in their browsers and this includes control to modify your code any way they wish.



来源:https://stackoverflow.com/questions/9794182/how-to-protect-js-from-custom-events

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