如何使用开发者控制台检查玩家是否作弊



我曾尝试制作一款点击游戏,用一种基本的方法来判断游戏是否被变量欺骗,但即使在故意作弊测试后,它也无法正常工作。

这是我的HTML代码:(有js(

var i = 0;
function myFunc() {
var one = document.getElementById("one");
if (one.innerHTML == "Click the button to get your first dimension!") {
one.innerHTML = "You have one dimension."
} else {
a = i
b = a + 1
i += 1;
if (i == b) {
alert("No Cheats")
} else {
alert("Cheater!")
}
one.innerHTML = "You have " + i + " dimensions."
}
}
#one {
width: 200px;
height: 200px;
border: 1px solid blue;
}
button {
width: 200px;
background: yellow;
box-shadow: 4px 4px 4px #333;
}
<!DOCTYPE HTML>
<title>Clicker</title>
<noscript>turn on javascript man</noscript>
<head>
</head>
<html>
<body>
<div id="one">Click the button to get your first dimension!</div>
<button onclick="myFunc()"> Dimension Creator </button>
</body>
</html>

正如对您最初问题的评论所指出的,您需要使用后端来使您的游戏不可复制。然而,如果控制台打开,一种不太投入(更容易作弊(的方法是使页面不可用。可以通过检查外部浏览器尺寸和内部浏览器尺寸之间的差异来执行此操作。像这样:

setInterval(function() {
const widthDiff = window.outerWidth - window.innerWidth > 160;
const heightDiff = window.outerHeight - window.innerHeight > 160;
if (widthDiff || heightDiff) {
console.log('You are cheating.');
location.reload();
}
}, 500);

但是,这对使用浮动浏览器窗口的用户不起作用。您可以使用debugger关键字来解决此问题,但用户不会立即受到惩罚。像这样:

setInterval(function() {
var minimalUserResponseInMiliseconds = 100;
var before = new Date().getTime();
debugger;
var after = new Date().getTime();
if (after - before > minimalUserResponseInMiliseconds) { // user had to resume the script manually via opened dev tools 
console.log("You are cheating");
location.reload();
}
}, 500);

(此答案的代码(

最新更新