My question is how do most games on iOS, including anyone here who has done something like that, handle real-time limits on items while also preventing them from cheating?
For example, let’s say you’re playing a Sims-like game and you run out of energy. The game says you do not have enough energy to do something, so you have to wait an hour or day to get more energy. Or everyday you play the game they reward you with a certain amount of money.
I’d like to implement a system using System.DateTime, to give them rewards for playing everyday, but I also don’t want them to exploit it by cheating, and exiting the game, then putting their iPhone’s/iPad’s clock forward a day, and then continually getting rewards.
Has anyone figured out a solution to avoid this locally on the system without forcing the player to have to go to a server to get the real time for this?
Anyone know how to get started on this? Looking at the link I’m not sure where to begin with making calls from unity. Also perhaps someone has a plugin that has a check?
The only authoritative way would be to use a server. But you do not even need your own, you could just use NTP to get the time from one of the many thousands of servers out there. Make sure you properly adjust for time zone of course. If you do this when the application starts up, you can calculate the delta from the time server and the system clock. Anything outside of that, plus a little bit of fudge, and they are probably fiddling with their system time. (this is covered in the reply by RazorCut and I should have followed the link first)
An alternative, though less robust method is to keep a history of the system time at application start up, then if the time moves backwards to before last recorded time (don’t forget to account for daylight savings), its a sure bet the user has fiddled with their clock. You keep a small history of times because it lets you adjust for minor adjustments of a few minutes. When you detect a backwards time shift, e.g. they moved their clock forward by 72 hours to get some gold and hurry up a build queue, then moved it back to where the time should be, you can decide what to do. You could just lock the game up and refuse to load that saved game (“It is corrupt…”) or penalize the player somehow.
Sorry for damn outdated answer, but it may be useful for those who gets here via search.
I’ve made a mobile plugin (iOS, Android) to prevent cheating locally without using server. With access to native system functions you can track DateTime changes and calculate unbiased time.