123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|208|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Blitz -> Universal Clock

Thu, 26 Aug 2010, 17:20
BGDDisco
My web game needs a standard time reference.
CurrentTime$() and CurrentDate$() come from the individual user's computer. Not only does this introduce a global positioning timezone error, but even the fact that your computer may be a few seconds or minutes out from the real thing introduces errors.

Does anyone know of an web-accessible time reference that Blitz Basic can refer to?

-=-=-
God gave Man a brain...and a penis...but only enough blood to run one at a time!
Thu, 26 Aug 2010, 18:18
JL235
What are you trying to achieve? Accuracy really depends on what you are trying to build and there might be a far better way of building whatever you are trying to build.

But for this specific question, the proper way would be for you to take advantage of a Time Server. They are servers (many of which are public) designed to hold and distribute the current exact time using the network time protocol and so are pretty much designed specifically for synchronizing computers around the world. You'll never get the exact time due to latency, but implementations do predict the latency you are occuring (note that they only predict).

On Windows there is the Windows Time Service which you could take a look at. This is MS's implementation of the Network Time Protocol and can give you the exact time to within a few seconds. It's also included with Windows since Windows 2000. There are far better libraries out there on the net which will give you a far more accurate time. For use with Blitz you'd probably be best building bindings in C/C++ and then calling it from BB.

As a poor-mans alternative you could find one of the many 'what is the current time' websites only and have your app download the page (using BBs TCP functions) and then just strip out the time on the page. You then need to add on half the time taken between starting the request and receiving the page (this is a cheap way of accounting for the latency).
Fri, 27 Aug 2010, 01:54
Stealth
Why does your game need to know the exact time?
Fri, 27 Aug 2010, 09:40
BGDDisco
It's not that I need a particularly accurate time, just a standard reference that all my players are 'governed' by.
My two-player games will have a time limit to make your move/play, and if two opponents had differing 'local' times even by a few minutes (just checking my computer - it is 3 seconds slow) this could make a big difference to game play.
Will check if my web-hosts (UK2) have a server time that I can refer to.

-=-=-
God gave Man a brain...and a penis...but only enough blood to run one at a time!
Fri, 27 Aug 2010, 13:40
Stealth
You should have both games "handshake" at the beginning of the game. They both essentially agree on a time to use. Both clients should also checkup on the other clients to assure they are playing by the rules. For instance, if the other player sends a move outside of their timeframe, my client would receive the command and should reject it. From there, you can either have error control code or trigger a game "out of sync" error.

-=-=-
Quit posting and try Google.
Fri, 27 Aug 2010, 21:00
JL235
IMHO this would be a much better way to structure your game. You should build it using a server/client architecture. However hosts is running both a server and a client, all other players are just clients.

The servers are just dumb front-ends. They send their moves to the server and visualize the response.

The server runs the game itself and validates all moves that are sent to it (i.e. is the move allowed?). The only time that matters is the servers time, and only the server needs to keep track of this. At the start of a players move the server will record a timestamp and then message the player to say they can move. When the player has finished moving they will message back to the server their move, and the server will know if they are within time by measuring the time difference between it's first instruction to play and the response of the move being carried out.

If a client fails to send it's move to the server within the timelimit, the server sends out an 'out of time' message (or something to that effect) and simply ignores any illegal moves (moves taken when a player can't actually move).

With this structure none of the clients will need to keep track of the time. Only the server will keep track of time and will do this based solely on the timestamps it's recording for the messages it's sending and receiving.
Sat, 28 Aug 2010, 17:45
Scherererer
I think he just means getting a standard time, such as everyone using UTC/GMT instead of each computer using their local time.

-=-=-
YouTube Twitter
Computer Science Series: Logic (pt1) (part 2) (part 3) 2's Complement Mathematics: Basic Differential Calculus
Fri, 03 Sep 2010, 09:25
BGDDisco
Yep Scherererer, that's exactly it. I don't even want that much accuracy - to the nearest minute would suffice. Anyone know of a web-page with the current time and date somewhere on it (preferably near the beginning) that I could aim my program at as a reference.

My reasons again:
Say P1 and P2 take turns at a game of chess and they have a time limit of 5 minutes to take there turn. P1's (local) CurrentTime$() is a minute slow. P2's CurrentTime$() is a minute fast. This would mean that when the game update with TimeOfLastTurn$() is TCP'd to webspace, P1 would be giving P2 a full two minutes extra to contemplate his turn, and P1 himself would only be getting 3 minutes. This is why I need a remote time reference - even if it's not all that accurate.

-=-=-
God gave Man a brain...and a penis...but only enough blood to run one at a time!
Fri, 03 Sep 2010, 10:21
JL235
BGDDisco Say P1 and P2 take turns at a game of chess and they have a time limit of 5 minutes to take there turn. P1's (local) CurrentTime$() is a minute slow. P2's CurrentTime$() is a minute fast. This would mean that when the game update with TimeOfLastTurn$() is TCP'd to webspace, P1 would be giving P2 a full two minutes extra to contemplate his turn, and P1 himself would only be getting 3 minutes. This is why I need a remote time reference - even if it's not all that accurate.

As I understand it, you don't actually need to send players the time, you only need to send them the 'difference' in time between moves. With my suggestion you can do this.

Lets say you want to update the TimeOfLastTurns, first the server takes a timestamp for the current time. For ease we'll say all timestamps work in seconds, and the current timestamp is 660.

When it sends out the time of last moves it'll send out it's current time (the 660) plus it's timestamps for the old moves. Lets say those old moves occurred at 400, 500 and 600.

The client can work out the time to display using this knowledge. 660 is the time now, 17:09:00 for me, so 600 will be 1 minute ago at 17:08:00. 500 is 17:06:20 and 400 is 17:04:40.

To summarise...

Servers timestamp now: 660
Servers timestamps of old moves: 600, 500, 400

Lets say local time on players machine is 17:09:00. 660 represents now, so 660 is 17:09:00!

Therefore...
600 => 17:08:00 (60 seconds earlier),
500 => 17:06:20 (160 seconds earlier),
400 => 17:04:40 (260 seconds earlier)

Does this not solve your problem without having to strip the time from a website?
Thu, 23 Dec 2010, 07:37
BGDDisco
Finally got a working function written.
I've put the source on BB.com

https://www.blitzbasic.com/codearcs/codearcs.php?code=2800

Use it freely.

-=-=-
God gave Man a brain...and a penis...but only enough blood to run one at a time!