防止Javascript游戏调整/黑客攻击 [英] Prevent Javascript games tweaking/hacking

查看:94
本文介绍了防止Javascript游戏调整/黑客攻击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于最近的浏览器增强功能,使用canvas和javascript开发游戏已成为一个不错的选择,但现在代码很容易访问,只需编写

Thanks to the recent browsers enhancements, developing games with canvas and javascript has become a good option, but now that the code is easily accessible, just writing

javascript:score=99999

javascript:lives=99

将破坏游戏目标。

我知道通过一些服务器端检查可以做一些事情,但我更愿意访问服务器只是为了存储玩家统计数据结束,或者甚至在大多数情况下都只有客户端。

I know that with some server-side checking something can be done, but I would prefer to access the server just to store player stats at the end, or even have it client only in most cases.

我想知道至少是否有一些最好的实践开始。

I wonder if at least the are some best pratices to start with.

(使用不那么明显的变量名称是一个开始,但还不够)

(using not so obvious variables names is a start, but not enough)

- 已添加 -

感谢您的回复,我希望改进客户端代码,足以阻止随意黑客,但仍然保持代码干净可能。
任何真正想破解它的人都会成功,即使是在服务器端检查,正如我在许多Flash游戏中看到的那样。

Thanks for the replies, I was looking to improve the client-side code, enough to stop "casual hackers", but still leaving the code as clean as possible. Anyone that really wants to hack it will succeed anyway, even with server-side checks, as I've seen it in many flash games.

推荐答案

我会说出我在评论中所说的内容:将每个源代码放在(function(){}()); 中。然后,无法从外部访问变量和函数。

I'll say what I said at my comment: put every source code in (function(){ }());. Then, the variables and functions can't be accessed from outside.

示例:

(function(){
    var a = 'Foo';
    var b = 42;
    function helloWorld(a,b){
        for(i=0;i<b;i++)console.log(a);
    }
    helloWorld(a,b);
});
//Can't access to a, b, or helloWorld using javascript: or default console of Google Chrome,
//but people still can see by looking source code and may be modified by other tools
//(see comments of Tom & user120242)

我'学到了'这个技巧这个当我深入研究Les Paul Google Doodle时。

I 'learned' this technique this when I dig into Les Paul Google Doodle.

为了更安全(不完全安全,但它会让一些黑客感到恼火),通过工具压缩和混淆你的脚本例如 YUI压缩器打包器

To be more secure (not completely secure, but it'll annoy some hackers), compress and obfuscate your script by tools something like YUI compressor or packer.

这篇关于防止Javascript游戏调整/黑客攻击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆