In some games people can cheat by changing the time. For example: when they have to wait 30 minutes before a building is built. Can i prevent this, assuming that the devices have connection with my server? I am programming in java using the libGDX library. Any solutions that work both on IOS and Android?
-
Does your devices have to connect to your server ? If yes you could create a timeout of 30min for each user on your server. When a user make a request from your server, check the timeout value. If it's superior than 0, denies the request, otherwise allows it. – user2336315 Jan 03 '14 at 15:10
2 Answers
Store the time they have to wait to on the server (tell the server they perform a task, server will log that time and when they can do it again) and make the client check if the server thinks it can in fact perform the action. Anytime you store something on the client it is likely that there will be a way around it.

- 5,769
- 1
- 25
- 41
-
And is there no other way i can get the real time on the client? Without the user able to change it? – Emiel Vandenbussche Jan 03 '14 at 15:16
-
2you could request the time from a trusted source such as your service and use that time. The client will only ever knows its own time as per the clock – Paul Harris Jan 03 '14 at 15:19
-
@PaulHarris +1 for using a service. Using a trusted service is better than storing it on the server, IMO. It simplifies the application -- only the client is concerned with time storage/access as opposed to both client and server. – MadConan Jan 03 '14 at 15:46
Your best bet would be to use SystemClock.elapsedRealtime() as an assistant to an infrequent server side timecheck.
return the time since the system was booted, and include deep sleep. This clock is guaranteed to be monotonic, and continues to tick even when the CPU is in power saving modes, so is the recommend basis for general purpose interval timing.
After verifying the time from your server, you can do local checks against SystemClock.elapsedRealtime until the next boot up.

- 4,648
- 2
- 27
- 26