Latest Uploads
Invasion V ... prototype

rychan

Invasion V ... Prototype

rychan

Shields 64x64

Pakz

Ffs_Spam

Jayenkai

Hives Screen shot

rychan

Rpg Potion Sprites

Pakz

Forum Home

Universal Clock

UserMessage
Posted : Thursday, 26 August 2010, 17:20 | Permalink
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!
Posted : Thursday, 26 August 2010, 18:18 | Permalink
JL235


WW Entries : 7
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).

-----
PlayMyCode.com - build and play in your browser, Blog, Twitter.
Homepage : http://www.StudioFortress.com
Posted : Friday, 27 August 2010, 01:54 | Permalink
Stealth


Why does your game need to know the exact time?
Homepage : http://strubhar.me
Posted : Friday, 27 August 2010, 09:40 | Permalink
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!
Posted : Friday, 27 August 2010, 13:40 | Permalink
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.
Homepage : http://strubhar.me
Posted : Friday, 27 August 2010, 21:00 | Permalink
JL235


WW Entries : 7
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.

-----
PlayMyCode.com - build and play in your browser, Blog, Twitter.
Homepage : http://www.StudioFortress.com
Posted : Saturday, 28 August 2010, 17:45 | Permalink
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
Homepage : www.google.com/profiles/Scherererer
Posted : Friday, 03 September 2010, 09:25 | Permalink
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!
Posted : Friday, 03 September 2010, 10:21 | Permalink
JL235


WW Entries : 7
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?

-----
PlayMyCode.com - build and play in your browser, Blog, Twitter.
Homepage : http://www.StudioFortress.com
Posted : Thursday, 23 December 2010, 07:37 | Permalink
BGDDisco


Finally got a working function written.
I've put the source on BB.com

http://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!
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 602|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Latest Posts
Puff Dog
therevillsgames Sat 18:59
Crystal Maze
Jayenkai Sat 14:11
Buy Zelda
Jayenkai Sat 08:34
CSS-Me-Do - SoCoder2
Jayenkai Sat 06:25
Welcome Caton
steve_ancell Sat 04:53
Update All Objects in Array?
Jayenkai Sat 03:34
2D Array?
Jayenkai Sat 03:29
Cerberus X - the continuation of Monkey X
zzoom Fri 23:13
Delete Button on Showcases
Pakz Fri 09:13
Grenfell Fridge
Jayenkai Fri 09:02
More

Latest Items
Snippet : Twitter BBCode
Jayenkai Sun 02:44
Link : Learn C++
Pakz Sat 20:33
Dev-Diary : My Journey into NES Development
Jayenkai Thu 03:58
Showcase : A Civilization Clone v0.4
rychan Thu 03:27
News : Newsletter #320
Jayenkai Tue 18:47
Blog : sadas
hardcoal22 Tue 02:50
Showcase : Flappadiddle
Jayenkai Mon 08:20
Article : Cookie Information
rychan Sun 12:28
Dev-Diary : Wii to N64 adapter
spinal Sat 11:50
Link : MonkeyX code examples
Jayenkai Sat 06:42
Link : Available Languages
Jayenkai Thu 13:22
Blog : Mr Testo Tests
Socoder Tue 07:21
Link : Chrome VR Experiments
Jayenkai Tue 06:49
Showcase : Hives
zzoom Fri 16:10
More

Who's Online
Jayenkai
Sun, at 02:47
Pakz
Sun, at 02:35
rockford
Sun, at 02:32
spinal
Sun, at 01:47
therevillsgames
Sat, at 23:18
jprofitt
Sat, at 23:17
steve_ancell
Sat, at 21:01
TomToad
Sat, at 18:33
GfK
Sat, at 17:18
Stealth
Sat, at 15:39
Link to this page
Site : Jayenkai 2006-Infinity | MudChat's origins, BBCode's former life, Image Scaler.