【发布时间】:2016-07-15 12:00:58
【问题描述】:
我正在为我的游戏实施基本的(仅针对儿童)反作弊。我为每个移动数据包添加了时间戳,并在服务器端检查这些数据包之间的时间差。
我还包含一个数据包,它根据处理速度每 5 秒发送一个时间戳。但是当PC滞后时,这似乎是一个问题。
那么我应该用什么来检查处理时间是否由于“speed hack”而变快?
我当前在客户端的循环速度检查:
this_time = clock();
time_counter += (double)(this_time - last_time);
last_time = this_time;
if (time_counter > (double)(5 * CLOCKS_PER_SEC))
{
time_counter -= (double)(5 * CLOCKS_PER_SEC);
milliseconds ms = duration_cast<milliseconds>(system_clock::now().time_since_epoch());
uint64_t curtime = ms.count();
if (state == WALK) {
// send the CURTIME to server
}
}
// other game loop function
如果客户端 PC 没有因为 RAM 或 CPU 问题而出现延迟,则上面的代码可以正常工作。他们可能运行了太多的应用程序。
供参考的服务器端代码:(GoLang)
// pktData[3:] packet containing the CURTIME from client
var speed = pickUint64(pktData, 3)
var speedDiff = speed - lastSpeed
if lastSpeed == 0 {
speedDiff = 5000
}
lastSpeed = speed
if speedDiff < 5000 /* 5000 millisec or 5 sec */ {
c.hackDetect("speed hack") // hack detect when speed is faster than the 5 second send loop in client
}
【问题讨论】:
-
我正在使用 VisualStudio2015
-
@MikeMB 不,我没有尝试过 stable_clock
-
您的代码发送客户端 PC 的
system_clock时间 - 他们可能不会将他们的 PC 同步到任何参考(即使您有),在这种情况下,您的服务器时间和他们的时间之间可能存在差异,即使没有任何与负载相关的滞后。您最好将他们的消息视为“心跳” - 预计每个消息都在最后一次的 10 秒内。 -
@TonyD 是的,我就是这么对待的。我将在我的问题中包含一些服务器端检查的代码。给我一些。
-
刚刚编辑到问题中的服务器端检查代码确保客户端将数字 声称 至少相隔 5000 毫秒,但不执行任何服务器端检查接收消息的频率,这就是我上面所说的。
标签: c++ performance loops infinite-loop