简体   繁体   中英

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

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM