How to prevent time-cheating on offline game based on Cocos2dx?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 17:45:07

问题


Recently I'm working on a mobile offline game based on Cocos2dx-lua.

I found an app on Google Play called GameGuardian which can set the time speed. The app maybe modify the method gettimeofday() in libc.so. I've tried many APIs such as os.time(), SystemClock.elapsedRealtime(), but all failed.

Could somebody please give me a way to avoid the effect of the app?


回答1:


The only sure method is to make your app contact your game's server to ensure time. Many android games is doing that. "The Battle Cats" is one example.
Say, you can check time validity as soon as app starts, and if no connection available, you can allow resources generated for some allowed time. Not more than 1 hour worth since last confirmed time, for example.

Other idea might be checking current fps. Hardware can't speed up, so frame will be rendered in roughly same time when VSync enabled. If you find that rendering single frame takes significantly more time than it should be, and if it happens for many frames, then it might indicate cheating possibility. But this is not stable solution, since you'll have to be sure your fps normally doesn't drop on weak devices, and it doesn't tell you anything about time spent while game wasn't running.

Extreme case might include complete erasing app's state if you find time jumped back since last saved unconfirmed time for more than ~1 hour (in case user adjust DST, etc).

But generally you can't protect completely offline game from time manipulations.



来源:https://stackoverflow.com/questions/40992853/how-to-prevent-time-cheating-on-offline-game-based-on-cocos2dx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!