Latest Uploads
Wonder Wom ... ting thing

rychan

SoCoder 1 ... 0 Patreon

Jayenkai

Vagina

Jayenkai

You Were Defeated

rychan

IFS Viewer 3

Andy_A

Still Truckin'

rychan

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.

-----
Andrew // stealth
"Some people see things as they are and say why? I dream things that never were and say why not?" - Robert Kennedy
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 660|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Latest Posts
AGameAWeek : 2016 - Part Two
Jayenkai Sat 10:50
Backspace is no longer Back in Chrome
Jayenkai Sat 07:08
SoTweaking
Jayenkai Sat 01:43
VirginMedia SpeedBoost - Finally..
Jayenkai Fri 07:29
Pizza by Drone
steve_ancell Fri 05:50
A Political Thread That I Shouldn't Have Started
GfK Thu 06:01
Face drawing practise
Jayenkai Thu 00:29
WW - #244 - The Ten Challenge
Jayenkai Wed 10:46
Facebook Ban
GfK Wed 00:38
Flip Out!
Jayenkai Tue 12:35
More

Latest Items
Blog : Monkey-X Box2D: Learning from my perspective... Hopefully!
steve_ancell Sun 14:49
Snippet : JNKrunch v1.0
spinal Sun 12:02
Snippet : Dungeon/Cave Generator - Simple
Pakz Wed 15:05
Snippet : Platform Sprite Generator
Jayenkai Tue 15:22
Snippet : Code Creates Crates
HoboBen Tue 07:02
Snippet : Texture - Leafy camouflage
HoboBen Tue 07:00
Snippet : Texture - Stone 3
Pakz Mon 09:55
Snippet : Texture - Stone 2
Pakz Mon 09:50
Snippet : Texture - Stone 1
Pakz Mon 09:46
Snippet : Texture - Cloudy Patterns
Pakz Mon 08:57
Showcase : Mining Map AI Demo
steve_ancell Wed 08:00
Showcase : Grey Lined Backgrounds
HoboBen Mon 04:17
Showcase : CAVE
Jayenkai Sun 07:20
Showcase : I Shall Be Queen!
rychan Fri 06:41
Snippet : Thousands of 3D Cubes
Pakz Fri 02:49
More

Who's Online
GfK
Sat, at 12:22
rockford
Sat, at 11:58
Jayenkai
Sat, at 10:53
spinal
Sat, at 10:52
steve_ancell
Sat, at 10:26
shroom_monk
Sat, at 09:39
9572AD
Sat, at 07:42
Pakz
Sat, at 06:00
HoboBen
Sat, at 04:18
Dabz
Fri, at 20:53
Link to this page
Site : Jayenkai 2006-Infinity | MudChat's origins, BBCode's former life, Image Scaler.