如何防止网页游戏作弊?
问题描述:
我已经在这个论坛上通过了其他网络游戏的作弊问题,但我没有得到我的问题的答案,这就是为什么我张贴在类似的标题下。如何防止网页游戏作弊?
这里是问题:
我正在开发一个web为基础的游戏,其中三个类似的箱子通过使用简单的HTML显示在网页上。
<img src="box.jpg" />
<img src="box.jpg" />
<img src="box.jpg" />
现在使用jquery.path插件我正在旋转的每场比赛的要求随机路径上,并为这些箱子在动画用户需要通过单击的标识中间有空格的位置结束的
三盒。
但是,如果用户使用Firebug或Chrome网页开发工具,那么只需检查dom的元素,他/她就可以轻松识别中间框的位置。
所以请给我建议解决这个问题。
P.S.
我主要是使用简单的jquery动画,因为我想让游戏兼容老的浏览器,所以最好是在我的情况下使用canvas或css3动画?他们会解决这种欺骗问题吗?
答
尝试考虑如果JavaScript关闭使用。尽管它可以通过JS调试器进行跟踪,但学习使用调试器将不仅仅是查看源代码或DOM树,而是更高层次的知识。
构建一个具有私人范围的对象。使用该对象创建您需要的3个图像。将这3个图像分配给该对象中的3个私有变量。只有那个物体知道哪个图像是哪个。你甚至不需要给它们区分它的属性,因为你可以使用这3个私有变量在对象中跟踪它们。
在我的例子中,我使用$ .data()这是可见的。虽然他们可以知道盒子的ID,但他们不知道闭合内部的变量target
的值。
考虑随机化target
的值,并在中间放置任何具有该值的框。那样的话,他们不会一直在跟踪,同一个盒子里。
var game = (function(){
//set which box is the target
//they will never know this value
//i sugest including this in randomizing
var target = 1;
//storage variable for the boxes
var boxes = {};
//retrieve data stored and check with target
var check = function(element){
var boxID = $(element).data('boxID');
//check if a match
if(boxID === target){
alert('got me!');
} else {
alert('not me!!!');
}
}
//create 3 boxes and store them in boxes object
for(var i = 0; i < 3 ; i++){
//create box HTML and store it in a variable
//notice that all boxes will have this very same HTML
var box = $('<img src="box.jpg" />');
//store the box identifier using $.data()
//at least in this manner, you are not storing
//the id as an attribute
box.data('boxID',i);
//if your plugin looks like "element.path()"
//plug it to every box created
box.path({
options:value....
});
//add handler for checking
box.on('click',function(){
check(this);
});
//store in the private variable
boxes['box'+ i] = box
//append box to the display, in this case, the body.
$('body').append(box);
}
//your "pathing" function
var randomize = function(){
//do your random path stuff here
//access boxes using: boxes.box1, boxes.box2 and so on...
//they are jQuery objects already so you can use jQuery functions on them
};
//return public accessible methods and functions
return {
randomize : randomize //expose the randomize function
}
}());
在此之后,只需拨打game.randomize()
做你的路的东西(因为只有随机公开可用的代码)
tried logging的game
对象还有div的,没有真正的target
的迹象。
如果您依赖的是纯粹的客户端,那么阻止它们的方法很少。如果你更多地谈论基于浏览器的mmo,目前似乎有很多方法可以阻止它,那就是检查服务器上的所有内容,但DOM位置等东西总是可用的,它基于web的性质发展。 – Henry 2012-02-27 10:39:43
你可以做的最好的做法可能是充分混淆你的代码,除了最热心的作弊者之外,不会感到困扰。 – 2012-02-27 10:47:38