How to synchronize the time between the clients in an online game

Viewed 432

I am making an online multiplayer game in NodeJS where players have to guess the correct answer to a puzzle as fast as possible. The game is played through multiple rounds of 1 minute each (similar to skribbl.io). Between every round is a 10 seconds pause where the Scoreboard is displayed. If every player has found the answer before the time is up, the round ends immediately.

When a player's client fetches the game, the server sends how much time there is remaining to the current round, based on when it started and the server's time. Every player's client has a local timer for rounds and the 10-seconds pause between them. A client's timer is initialized using the remaining time sent by the server. When a player's timer is up or when there is a websocket notification that says that the round has ended, the client shows that the round has ended.

For the first round to begin, the person that created the game clicks on a button to tell the server to create a new round and a puzzle. The server then sends a websocket notification to the players of this game that a round has started.

My problem is this: The rounds have to start and end at the same time for every player. After the first round, a puzzle for the next round has to be created, so the server has to know that it should create a new round with a puzzle and tell the players via websocket that a new round has started. Because I could eventually deploy my game on multiple servers (clusterize it), I want my server to be stateless, so I don't want the back-end to keep timers for every game that is being played.

Do you have any ideas on how this problem could be solved?

Thank you,

0 Answers
Related