vnztms
vnztms

Reputation: 21

Get correct time since app was closed without network

I am creating an idle game (user is rewarded for offline time with ressources). For that calculation I will need the elapsed time since the app was closed.

My first idea was to save the current time when the app is closed and read the current time when the app is opened. But what if a malicious user changes the system time between those actions? The user could get as many ressources as he wants with this trick.

My solution would be to consult a time server to get its current time when closing and opening the app. But this would mean the app would need to be always online, which I am trying to avoid.

Is there any other way I could use to accomplish this?

Upvotes: 2

Views: 924

Answers (2)

Loolooii
Loolooii

Reputation: 9170

I don't think it means that the app always needs to be online. You just take the server time when the user closes the app and you take the time when the user opens the app again. You then subtract the first from the latter and then you have the offline time. Assuming of course that you save the "last_closed" time in a database of some sort.

Upvotes: 1

MMG
MMG

Reputation: 3268

When you are online you read correct time from an api which shows greenwich time not from user's device; so that you always have correct time.

Upvotes: 0

Related Questions