当前位置:网站首页>【防作弊】Unity防本地调时间作弊
【防作弊】Unity防本地调时间作弊
2022-07-30 06:11:00 【博赢天下】
目录
1.需求背景
- 许多游戏有一种“体力”的概念,一般跨越30分钟(NowTime-LastRewardTime)恢复一个。如果是单机游戏,玩家就可以改本地时钟,NowTime一下跑很大块,超过30min就可以立即获得奖励了。
- 问题:如何防止这种本地改时间作弊。
2.解决方案
2.1 初步方案
- 维护开机时间的偏移量,计算Passing(N-L)差的时候带上开机时间偏离量,即可规避改时间的作弊行为,保证时间差运算合法。
- 以Unity使用C#代码为例:
public static DateTime GetSystemStartupTime() { return DateTime.Now.AddMilliseconds(-Environment.TickCount); }在游戏启动时获取MobileBoot的时间戳记为 Boot.Old。
那么就可以在下次判定奖励获取时,计入一个 Boot.New-Boot.Old的时间差 offset修正,防止改时间的作弊行为。包含防改时间作弊的计算奖励时间差伪代码如下:
// 游戏启动时记录 DateTime bootOld = GetBootDate(); DateTime bootNew = GetBootDate(); int rewardHeardCount = ((NowTime - LastRewardTime) - (bootNew - bootOld)) / 30;
2.2 最终方案
- 当玩家不重启,不关闭app,以上非联网状态是可以纠正的。但你想想,如果玩家app再改时间,上面的方式也是无法纠正的。
- 所以实际解决方案,应该在游戏启动时同步Server时间戳是第一步,在游戏中某次检测识别到 Boot.New 与Boot.Old不一致时,表明玩家在app未关闭的情况下改了时间,做一次弱联网同步时间戳,而不是用本地校验直接算结果(本地永远是不可靠的)。
3.纯单机如何防作弊
- 兄弟,纯单机了还想防…… 你又不允许起后台VirtualServer计时器
- 其实,纯单机,能识别,但不能纠正,毕竟咱们没有时间计时器了,不依靠外部Service辅助就不能获取正确的当前时间了。
边栏推荐
- DNS domain name resolution services
- Architectural Design Guide How to Become an Architect
- Input method for programmers
- New material under the plastic restriction order - polylactic acid (PLA)
- Equation Derivation Proof of Vector Triple Product
- sql concat()函数
- IDEA搜索插件无结果一直转圈圈的解决办法
- Go uses the mencached cache
- go : use gorm to modify data
- Basic usage of tree arrays
猜你喜欢

No, the Log4j vulnerability hasn't been fully fixed yet?

The first artificial intelligence safety competition officially launched

Graphical relational database design ideas, this is too vivid

树状数组的基本用法

Keil软件中map文件解析

物联网网关该怎么选

Is it possible to use the same port for UDP and TCP?

AI可通过X光片识别种族,但没人知道为什么

DP5340国产替代CM5340立体声音频A/D转换器芯片

【雷达目标检测】恒定阈值法和恒虚警(CFAR)法及代码实现
随机推荐
Go语学习笔记 - gorm使用 - 数据库配置、表新增 Web框架Gin(七)
大飞机C919都用了哪些新材料?
golang: Gorm配置Mysql多数据源
VR机器人教你如何正确打乒乓球
Architectural Design Guide How to Become an Architect
【COCI 2020/2021 Round #2 D】Magneti(DP)
Playing script killing with AI: actually more involved than me
ARM体系结构概述
Get all interface paths and names in the controller
常用的配置
DNS domain name resolution services
go : delete database data using grom
Go combines Gin to export Mysql data to Excel table
识别“数据陷阱”,发现数据的可疑之处
Graphical relational database design ideas, this is too vivid
How does Redis prevent oversold and inventory deduction operations?
Electron使用romote报错 : Uncaught TypeError: Cannot read property ‘BrowserWindow‘ of undefined
selenium module
和AI一起玩儿剧本杀:居然比我还入戏
MySQL off-topic [ORM thought analysis]