I am trying to work out the protocols to set up a game between 2 players and the ideas behind getting the timing right between those two players in a running race game. Since this is obviously a timed race on a stop watch (about 4 minutes total), there are syncing issues.
What are the protocols?
In my game the server does not list all games available all across the world. All it does is facilitate a game between 2 players, such as those in a real world cafe, who can pass each other their unique id codes by word of mouth. The server is just there to administer the connection and dish out id codes.
Should I connect to the WebRTC server straight away when the client loads a webpage? There are practice modes and games against the computer that do not require WebRTC connections.
Should I let the user choose when to connect to the WebRTC server after the web page loads, so they can do practices or games against the AI?
One person will start the game, setting all the options, eg uphill etc. How do I stop multiple connected and linked players altering those options? Should it be the first person to start a game out of all those connected and linked who bumps all the other players into the game with the options chosen on their machine?
Should there be a waiting room area to stop the game timer counting while everyone's graphics load on their machine? (Different running tracks have different graphics that load at the race start.)
Or should I let linked players just enter into a game at any time, even after it has started? There are some longer races that can last up to 10 minutes.
This latter option would allow a player in a game to pause their game when they meet someone in the cafe, and that new person could then join mid-race, taking on one of the other previously AI controlled runners.
- Most importantly of all there is obviously a lag between players. This is a timed race, ranging from 4 minutes to 10 minutes. How do I marry-up the times between players? Should I try to marry up as much as possible between the two clients, but consider the TRUE time of each player to be the time on their CLIENT machine?
By this I mean the following.
Assume 'Player A' finishes at 4 minutes dead on his machine and it appears on 'As' machine 'Player B' finished at 4 minutes and 1 second (due to lag issues).
However, on 'Player B's' machine it appears to 'Player B' he finished the race at 3mins 59 seconds.
Should I take the race times as 'Player A' = 4 mins and 'Player B' = 3mins 59 seconds? Ie the true finish time of a player is what occurs on the player's own machine, not the other person's?
Note: since these are friendly games between two people in a cafe, cheating is not an issue. They are playing in front of each other in real life.
Is there any documentation of best practices? How would you do it?