Get SERVER Date?

Hi,

I understand that there is an OS clock feature which returns the date/time/etc. but my question is, is there a way to validate this against a server to ensure that the date is correct? For example, I want to have high scores for my game be contingent on that particular day, and I don’t want the player to cheat by adjusting their clock and playing for a different day.

I was thinking I could get a game server of some kind, but since all I want to do is validate the current date, I just wanted to see if there was some web service out there that does this for me.

Any suggestions?

Thanks,
Zach [import]uid: 52208 topic_id: 16866 reply_id: 316866[/import]

I checked to see if this already existed and My google-fu didn’t return anything useful. Most Internet time servers exist to keep other servers in sync. In fact your phone does that already. But the time protocol isn’t easy and there’s a lot of cryptic stuff which is overkill for your purpose.

So what I would suggest is if you have a web hosting account somewhere, where you can run a php script, write a little PHP file and drop it on your server:

gettime.php

<?php <br>echo time();  
?\>  

Then you should be able to do an HTTP GET request:

http://yourserver.com/gettime.php

and it will spit out a big number, which is the time in seconds since Jan 1, 1970 or what’s known as EPOCH time.

Once you have that in place, you can use Corona to make a network.request() call to that URL and in the event handler, the time value would be in the “event.response” variable.

With a little date magic using some of the os.date() functions, you can return something where you can determine if its today or not.

[import]uid: 19626 topic_id: 16866 reply_id: 63182[/import]

Thanks for the reply!

As a matter of fact, I do have a server. Its some cheap place (justhost.com) where I host my personal website. I was actually thinking of doing this but I was wondering what the implications would be in terms of traffic and stuff like that.

Secondly, I’ve been thinking of time zones, etc. The basic logic I was thinking about doing is something like:

Get the OS time & set time zone (if possible)
Do a web request to compare against the server time (with the specified time and time zone)
If they are within ~X amount of time of each other, set a flag to allow for score submission

Does this sound possible? [import]uid: 52208 topic_id: 16866 reply_id: 63225[/import]

Actually, to make things simpler, I could probably just grab the date from the server and do a comparison of +/- 24 hours, that way if it falls in the realm of “yesterday, today, or tomorrow” it would be acceptable for a score submission. So there might be a little bit of “cheating” but probably not enough to make a fuss over. [import]uid: 52208 topic_id: 16866 reply_id: 63231[/import]

Your traffic should be reasonably low, about 10 bytes output per call and the inbound is a request, so it might not even count against your bandwidth, but even if it was, its still fairly small.

PHP has many date/time functions, but I think keeping everything in EPOCH is the simpler way to go. Then you can just do

player\_time = os.time(os.date( '!\*t' ))  
  
if math.abs(server\_time - player\_time) \> 24 \* 60 \* 60 then  
 -- cheater  
else  
 -- all's cool  
end  

[import]uid: 19626 topic_id: 16866 reply_id: 63241[/import]

Great, I’ll give that a try and see how it works. Thanks for the help :smiley: [import]uid: 52208 topic_id: 16866 reply_id: 63389[/import]