- Home /
Get real world's time which independent with device
I'm creating a game on Iphone/Android. In my game, user plants a tree then have to wait for that tree grow up. Each time user opens game, I check the time when user planted the tree and the current time, then decide the tree is grew up or not.
The problem is, if user plants the tree, then change device's time, he/she can cheat to make the tree grow faster.
How to avoid this? Is there a way to get the "real world current time" which user can not change?
Answer by Saad_Khawaja · Jul 17, 2014 at 12:46 PM
The only way to do this (if i'm not wrong) is to query the time from the internet. You can create a small PHP page that prints the time and host it somewhere on the web, then use WWW to query it whenever you need to find the time.
For e.g.
PHP Page :
<?php
print date("G.i:s", time());
?>
Unity Code
void Start () {
StartCoroutine("getTime");
}
IEnumerator getTime()
{
WWW www = new WWW("http://www.saadkhawaja.com/gettime.php");
yield return www;
Debug.Log("Time on the server is now: " + www.text);
}
@Saad_$$anonymous$$hawaja Thank you for fast reply, but I'm finding a offline method.
I tried to hack time on "Injustice - God among us" (Iphone version) by set the phone to air plane mode, close the game, check to make sure that the game not run at background, then change the time of device, but it didn't work. There must be a way to check the time which independent with device's display time and not use internet. I just want to know the method which give the result like the game "Injustice - God among us"
That could simply be an error handling scenario. If wifi is not connected, then it wouldn't be able to check the time from the internet (hence didn't give the score).
So inorder to check, you must switch off the internet, wait the actual required time and then open Injustice - God among us. If it gives you the credit, when you have wifi off, then it will confirm that it is getting time from the phone.
I hope you understand where i'm co$$anonymous$$g from.