Search Unity

Use "real" Time

Discussion in 'Scripting' started by shuskry, Jun 25, 2017.

  1. shuskry

    shuskry

    Joined:
    Oct 10, 2015
    Posts:
    462
    Hi everybody !

    I'm doing a 2d Game with photon and i want to know if it's possible to check the "real" time.

    I want to do a 24h counter chest , but i don't want to use the time of the smartphone, it's to easy to cheat!

    So i want to know if there is a way to check the real Time or something like that ? :/

    Thx for you're help !
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    From a server/service, you could check the time that way. I've seen a few people mention that they use a free service for just such a thing, but I'm not familiar with (or remember it), so I can't tell you what it is/was.
    If you run the server, obviously , you could be the "time verifier" :)
     
  3. TaleOf4Gamers

    TaleOf4Gamers

    Joined:
    Nov 15, 2013
    Posts:
    825
    Use a server.
    For example Playfab has a method to retrieve the time. Playfab is a whole backend service however, so I obviously dont recommend you implement it just to check the time.
     
  4. Pixelith

    Pixelith

    Joined:
    Jun 24, 2014
    Posts:
    580
    What I did was save the current time and date to a Playerpref on open of the chest Then when they log back in, it checks the amount of time between that save and the current time. If it comes back positive, then it's forward in time and will unlock the chest or continue counting. If it comes back negative, otherwise meaning going back in time, then it deletes the save data as punishment. Of course you don't have to be as harsh, but that's how I handled it. Of course Playerprefs are easy to modify, but I also made my own encryption script for playerprefs so its a little harder to modify.

    An example would be that it instead adds time to the counter instead of subtracting it.
     
  5. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,539
    NIST Internet Time Service (it's free):
    http://tf.nist.gov/tf-cgi/servers.cgi

    Simple scrape method:
    https://stackoverflow.com/questions/6435099/how-to-get-datetime-from-the-internet

    Note they mention using NTP instead of TCP for more efficiency... here is an example of that:
    https://www.codeproject.com/Articles/1005/SNTP-Client-in-C
    Though honestly, this is probably overkill since you're not going to be doing it constantly. NTP is more for constant checking and accuracy to synchronize multiple devices with one another.