By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,213 Members | 1,105 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,213 IT Pros & Developers. It's quick & easy.

Timer issue

P: n/a
Hey guys

Here is what i want to do. I have made a multiplayer game that needs to when
more than one player is ready start a countdown that the clients can see,
so players can still join in this time frame and then after the time elapses
the game starts.

I am trying to do it lie this, my server controls all handling of the game
logic, deciding who wins, who is next to play etc. For all the players to
have their timers showing the same times i have created the timer on the
server and this time is then serialised as part of the game object that is
sent to the clients.

The idea being the clients receive that object and they will then continue
to be running the timer their end with it having started at the server
theoretically making the timers go in sync.

My problem is first of all that System.Timers objects cannot be serialised.

My second problem is i think this may be flawed, if it takes longer for data
to reach one client his timer will start slightly late etc.

Anyone have any ideas how i can do this so all players see the same timer??

Thanks
Apr 22 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Send a TimeSpan (say 30 seconds) to all clients. It is a duration in the
future so it will be relative to any timezone or system time. You can't get
it *exact, but a second or two should not be an issue. If a client comes
in late, then that is just the way the ball bounces. Start your timer on
the server after the last client message is sent so that should give
everyone at least 30 seconds (for example) to connect - the first clients
may wait a tiny bit longer, but that should be ok.

--
William Stacey [MVP]

"Daniel" <Da*****@vestryonline.com> wrote in message
news:ua**************@TK2MSFTNGP03.phx.gbl...
| Hey guys
|
| Here is what i want to do. I have made a multiplayer game that needs to
when
| more than one player is ready start a countdown that the clients can see,
| so players can still join in this time frame and then after the time
elapses
| the game starts.
|
| I am trying to do it lie this, my server controls all handling of the game
| logic, deciding who wins, who is next to play etc. For all the players to
| have their timers showing the same times i have created the timer on the
| server and this time is then serialised as part of the game object that is
| sent to the clients.
|
| The idea being the clients receive that object and they will then continue
| to be running the timer their end with it having started at the server
| theoretically making the timers go in sync.
|
| My problem is first of all that System.Timers objects cannot be
serialised.
|
| My second problem is i think this may be flawed, if it takes longer for
data
| to reach one client his timer will start slightly late etc.
|
| Anyone have any ideas how i can do this so all players see the same
timer??
|
| Thanks
|
|
Apr 22 '06 #2

P: n/a
Hi William,

Ok so step by step your saying:

1) instantiate timer on the server
2) send to each player currently ready (once i have more than 1) a time span
object
3) now start the servers timer
4) clients on receiving the timespan object start their timers
5) anyone new joins in this time they are sent the timespan as it stands on
the server at this stage (so maybe 20seconds left), they then start their
timers from there
6) when server hits 0 send the start game to all clients
Thats sounds like a good method, there is one more problem though. my game
can have 3 or 4 games upto 100 going at once. So each game needs its own
timer tracked independantly.

At first thought a TimerManager class springs to mind where i can have every
game running tracked via a unique id number and on a player joining a game i
check which game he/she has joined and return the time details from the
timemanager class for that game.

My only problem is from a design point of view this could get messy. It
would mean i would have to when i instantiate my games do something liek
this:

GameManager.CreateGame("Game1", 1);
TimerManager.Create(1);

where 1 is the unique id.

Ideally i would want the timermanager done inside the gamemanager class but
that class is serialised and sent to the client on connecting so they can
see all the available games. As a result i cant put the timer manager in
there as it would need to be serialisable and i cant serialise a timer.

Anyway round that? I dont want future coders to forget to create a
timermanager for each game, plus they would have to always stay in sync.

Look forward to your views.

"William Stacey [MVP]" <wi************@gmail.com> wrote in message
news:O5**************@TK2MSFTNGP03.phx.gbl...
Send a TimeSpan (say 30 seconds) to all clients. It is a duration in the
future so it will be relative to any timezone or system time. You can't
get
it *exact, but a second or two should not be an issue. If a client comes
in late, then that is just the way the ball bounces. Start your timer on
the server after the last client message is sent so that should give
everyone at least 30 seconds (for example) to connect - the first clients
may wait a tiny bit longer, but that should be ok.

--
William Stacey [MVP]

"Daniel" <Da*****@vestryonline.com> wrote in message
news:ua**************@TK2MSFTNGP03.phx.gbl...
| Hey guys
|
| Here is what i want to do. I have made a multiplayer game that needs to
when
| more than one player is ready start a countdown that the clients can
see,
| so players can still join in this time frame and then after the time
elapses
| the game starts.
|
| I am trying to do it lie this, my server controls all handling of the
game
| logic, deciding who wins, who is next to play etc. For all the players
to
| have their timers showing the same times i have created the timer on the
| server and this time is then serialised as part of the game object that
is
| sent to the clients.
|
| The idea being the clients receive that object and they will then
continue
| to be running the timer their end with it having started at the server
| theoretically making the timers go in sync.
|
| My problem is first of all that System.Timers objects cannot be
serialised.
|
| My second problem is i think this may be flawed, if it takes longer for
data
| to reach one client his timer will start slightly late etc.
|
| Anyone have any ideas how i can do this so all players see the same
timer??
|
| Thanks
|
|

Apr 22 '06 #3

P: n/a
sb
Synchronization is probably the most common concern in all MPOGs. One
approach is to measure & track the time it takes for a packet of data to
complete a round trip (server -> client -> server) for each connected
client. This value can be used by the server to determine when to send
packets to each client as well as when to completely disconnect them...ie
they are responding too slowly.

For example:
Client A has a round-trip time (RTT) of 100 ms or ~50ms one-way
Client B has a round-trip time (RTT) of 200 ms or ~100ms one-way
Client C has a round-trip time (RTT) of 500 ms or ~250ms one-way

Now let's say I have some data that each client needs to see at the same
time...such as a player shooting a bullet. Knowing the information above I
can do the following and be fairly confident that everyone will be in synch:
Send C the data packet...wait 150ms and send client B the data, wait
50ms more and send client A the data.
Of course, this method requires that you frequenty check the latency of
every client because connections vary over time....but this does get you
down to milliseconds in terms of accuracy. Depending on what your game does
and how much timing matters in it, you can take the above scenario and add
many more levels of complexity to measuring the latency more accurately.
Alas, this is just one way to do it that isn't too complicated.

-sb
"Daniel" <Da*****@vestryonline.com> wrote in message
news:ua**************@TK2MSFTNGP03.phx.gbl...
Hey guys

Here is what i want to do. I have made a multiplayer game that needs to
when more than one player is ready start a countdown that the clients can
see, so players can still join in this time frame and then after the time
elapses the game starts.

I am trying to do it lie this, my server controls all handling of the game
logic, deciding who wins, who is next to play etc. For all the players to
have their timers showing the same times i have created the timer on the
server and this time is then serialised as part of the game object that is
sent to the clients.

The idea being the clients receive that object and they will then continue
to be running the timer their end with it having started at the server
theoretically making the timers go in sync.

My problem is first of all that System.Timers objects cannot be
serialised.

My second problem is i think this may be flawed, if it takes longer for
data to reach one client his timer will start slightly late etc.

Anyone have any ideas how i can do this so all players see the same
timer??

Thanks

Apr 22 '06 #4

P: n/a
You can still put the timer logic in the Game class. Just mark the timer
var and [nonserialized] or what ever the attribute is as I can't remember.
If xml, private vars will not be serialized anyway, only public properties
with get and set.
1) Create the game.
2) First client starts the timer (for example)
3) Future clients get a timespan between now and future time.
4) If client get into the game before timer trigger, then good, otherwise
return failure to client.

It probably makes sense to keep the timer logic close to the client connect
logic, where ever that is. If in the game class, great place to put it.
hth

--
William Stacey [MVP]

"Daniel" <Da*****@vestryonline.com> wrote in message
news:uF**************@TK2MSFTNGP05.phx.gbl...
| Hi William,
|
| Ok so step by step your saying:
|
| 1) instantiate timer on the server
| 2) send to each player currently ready (once i have more than 1) a time
span
| object
| 3) now start the servers timer
| 4) clients on receiving the timespan object start their timers
| 5) anyone new joins in this time they are sent the timespan as it stands
on
| the server at this stage (so maybe 20seconds left), they then start their
| timers from there
| 6) when server hits 0 send the start game to all clients
|
|
| Thats sounds like a good method, there is one more problem though. my game
| can have 3 or 4 games upto 100 going at once. So each game needs its own
| timer tracked independantly.
|
| At first thought a TimerManager class springs to mind where i can have
every
| game running tracked via a unique id number and on a player joining a game
i
| check which game he/she has joined and return the time details from the
| timemanager class for that game.
|
| My only problem is from a design point of view this could get messy. It
| would mean i would have to when i instantiate my games do something liek
| this:
|
| GameManager.CreateGame("Game1", 1);
| TimerManager.Create(1);
|
| where 1 is the unique id.
|
| Ideally i would want the timermanager done inside the gamemanager class
but
| that class is serialised and sent to the client on connecting so they can
| see all the available games. As a result i cant put the timer manager in
| there as it would need to be serialisable and i cant serialise a timer.
|
| Anyway round that? I dont want future coders to forget to create a
| timermanager for each game, plus they would have to always stay in sync.
|
| Look forward to your views.
|
| "William Stacey [MVP]" <wi************@gmail.com> wrote in message
| news:O5**************@TK2MSFTNGP03.phx.gbl...
| > Send a TimeSpan (say 30 seconds) to all clients. It is a duration in
the
| > future so it will be relative to any timezone or system time. You can't
| > get
| > it *exact, but a second or two should not be an issue. If a client
comes
| > in late, then that is just the way the ball bounces. Start your timer
on
| > the server after the last client message is sent so that should give
| > everyone at least 30 seconds (for example) to connect - the first
clients
| > may wait a tiny bit longer, but that should be ok.
| >
| > --
| > William Stacey [MVP]
| >
| > "Daniel" <Da*****@vestryonline.com> wrote in message
| > news:ua**************@TK2MSFTNGP03.phx.gbl...
| > | Hey guys
| > |
| > | Here is what i want to do. I have made a multiplayer game that needs
to
| > when
| > | more than one player is ready start a countdown that the clients can
| > see,
| > | so players can still join in this time frame and then after the time
| > elapses
| > | the game starts.
| > |
| > | I am trying to do it lie this, my server controls all handling of the
| > game
| > | logic, deciding who wins, who is next to play etc. For all the players
| > to
| > | have their timers showing the same times i have created the timer on
the
| > | server and this time is then serialised as part of the game object
that
| > is
| > | sent to the clients.
| > |
| > | The idea being the clients receive that object and they will then
| > continue
| > | to be running the timer their end with it having started at the server
| > | theoretically making the timers go in sync.
| > |
| > | My problem is first of all that System.Timers objects cannot be
| > serialised.
| > |
| > | My second problem is i think this may be flawed, if it takes longer
for
| > data
| > | to reach one client his timer will start slightly late etc.
| > |
| > | Anyone have any ideas how i can do this so all players see the same
| > timer??
| > |
| > | Thanks
| > |
| > |
| >
| >
|
|
Apr 23 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.