【问题标题】:how to prevent web game cheating ?如何防止网页游戏作弊?
【发布时间】:2012-03-16 20:02:05
【问题描述】:

我已经在这个论坛上解决了其他网络游戏作弊问题,但我没有得到我的问题的答案,这就是为什么我以类似的标题发布它。

问题来了:

我正在开发一个基于网络的游戏,其中使用简单的 html 在网页上显示三个相似的框。

<img src="box.jpg" />
<img src="box.jpg" />
<img src="box.jpg" />

现在使用 jquery.path 插件,我在随机路径上旋转这些框,并且根据动画结束时的游戏要求,用户需要通过单击三个框来识别中间框的位置。

但如果用户使用 firebug 或 chrome web 开发工具,那么只需检查 dom 的元素,他/她就可以轻松识别中间框的位置。

所以请给我建议来解决这个问题。

附言

我主要使用简单的 jquery 动画,因为我想让游戏也兼容旧版浏览器,所以在我的情况下使用画布或 css3 动画更好吗?他们会解决这种作弊问题吗?

【问题讨论】:

  • 如果你依赖于纯粹的客户端,那么几乎没有办法阻止它们。如果您谈论的更多是基于浏览器的 mmo,目前似乎有很多阻止它的唯一方法是使用服务器检查所有内容,但 DOM 位置等内容将始终可用,这是基于 Web 的性质发展。
  • 你能做的最好的事情可能是充分混淆你的代码,这样除了最热心的作弊者之外,其他人都不会打扰。

标签: jquery html css jquery-animate html5-canvas


【解决方案1】:

尝试考虑使用 if 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() 来处理您的路径(因为代码中只有 randomize 是公开可用的)

tried logginggame 对象以及 div,没有真正的target 的迹象。

【讨论】:

  • 这只是理论代码,从我的脑海中得到它。可能不完整,但想法是存在的。
猜你喜欢
  • 2012-01-06
  • 1970-01-01
  • 2022-10-15
  • 2016-08-22
  • 2017-04-20
  • 2010-10-31
  • 1970-01-01
  • 2012-08-20
  • 2013-02-08
相关资源
最近更新 更多