Forum Multiplayer Please Enlighten Me :)

Discussion and help relating to the PlayerIO Multiplayer API.

Please Enlighten Me :)

Postby batiali » August 19th, 2010, 8:52 am

Hello everyone,

I'm new around here. I have a question, but I'm having hard time to express it.
When simplified, what I want to do is simple. I want to build an application where the user joins with his login name & password, presses a button and starts a countdown timer(lets say 10 minutes). Even if he logs out and logs in back after 6 minutes, he will see that his timer continues to count and it's on 4 minutes.

My prediction is: Store the server time(? - there is one, isn't it?) in a variable to the bigdb? when the button is pressed. Update the countdown in every interval. If the user logs out and comes back, get the stored time for button press and continue updating. (I really couldn't express it, could I?)

So, please enlighten me, how would I achieve this?
batiali
 
Posts: 29
Joined: August 11th, 2010, 2:53 pm

Re: Please Enlighten Me :)

Postby Oliver » August 19th, 2010, 10:21 am

Hey,

When creating a timer:

a) Connect to a game room, create a BigDB object, set a property to DateTime.Now

When wanting to display the time left:

b) Load the BigDB object in the client. The time passed can then be calculated by subtracting the current time in flash from the time stored in the BigDB object (clienttime-bigdbtime). Both the server and actionscript uses UTC as the timezone, so you don't have to worry about timezones. Timeleft from 10 minutes would be 10M-(ClientTime-BigDBTime)

Notice that to display the time left you don't need to connect to a server, and that you don't need to do any updating on any interval.

Best,
Oliver
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am

Re: Please Enlighten Me :)

Postby Benjaminsen » August 19th, 2010, 10:25 am

If security is not a huge issue, you can also simply create the BigDB object and set the time in the client.
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: Please Enlighten Me :)

Postby Oliver » August 19th, 2010, 10:32 am

True, i forgot to mention that to only reason to have to create the object server-side is if you want a secure solution, where you've set it up such that clients can only read from BigDB.

If security is not that big a deal, it's much easier to implement client-side only.
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am

Re: Please Enlighten Me :)

Postby batiali » August 19th, 2010, 11:09 am

I guess I've made a mistake by simplifing what I really want to do :)

Since it's gonna be a small multiplayer game in the future, I don't want to depend on the flash's client time. That's why I want to update depending on the server time, if it's somehow possible.

If I display the time depending on the client, when the client's windows time is changed, won't it affect the displayed time?
batiali
 
Posts: 29
Joined: August 11th, 2010, 2:53 pm

Re: Please Enlighten Me :)

Postby Benjaminsen » August 19th, 2010, 11:24 am

batiali wrote:If I display the time depending on the client, when the client's windows time is changed, won't it affect the displayed time?


You are right, for a secure method you want to write and read the timer on the server.
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: Please Enlighten Me :)

Postby batiali » August 19th, 2010, 11:36 am

So what's the method to get the server time?
Is it possible to get it without writing any serverside code or can I do that only with only BigDB?
I'm not sure but I guess most of the multiplayer flash strategy games using a similar technique to decide when a building is completed or when our army reaches a location and stuff like that.
batiali
 
Posts: 29
Joined: August 11th, 2010, 2:53 pm

Re: Please Enlighten Me :)

Postby Oliver » August 19th, 2010, 12:21 pm

So what's the method to get the server time?


It's just the C#: "DateTime.Now" <-- that gets the current time on the serverside.

As mentioned before, you can just do it 100% clientsside, just get the current time in actionscript, stuff it into a BigDB object (have a look at one of the examples for BigDB sample coe), and save it.

- Olivler
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am

Re: Please Enlighten Me :)

Postby batiali » August 19th, 2010, 12:33 pm

Okay, I guess I got it.
Thanks a lot for your patience :)
batiali
 
Posts: 29
Joined: August 11th, 2010, 2:53 pm

Re: Please Enlighten Me :)

Postby Benjaminsen » August 19th, 2010, 1:54 pm

If you wish to get a time on the server in the same format as you get it from new Date().getTime() you can use
Code: Select all
Math.Round((DateTime.Now - new DateTime(1970, 1, 1)).TotalMilliseconds)
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark


Return to Multiplayer



cron