1
\$\begingroup\$

I'm trying to implement multiplayer into my game using the server client model. What is the best method of synchronozing the game between the clients? What I'm thinking is that the game runs on the client, where the clients send the inputs (keyboard input for example) to the server, and the server then passes that on to the other clients, which then process that information. To make this system more robust the game would also run on the server, and the server would send synchronization packets to synchronize all the instances in the room. I can already see some potential flaws in this design, so that's why I'm asking for a better implementation. Both the server and client run in gamemaker.

To give you some context: my game is a relatively simple rpg platformer, where you have an inventory and items, player stats like armor and physical damage (the stats are almost identical to those of league of legends). You move with the arrow keys or wasd, like a regular platform game. For now I want to implement pvp, but would like to set up networking in a way that allows for npcs. I want to have a maximum of say 4 or 5 players connected at a time.

I have read up on client prediction, server reconciliation, entity interpolation and lag compensation, but it seems overkill for my application (it might not be I'm not sure).

I guess there it is somewhat acceptable to have a pure authoritative server, other than the fact that the player movement will become unresponsive, which is a big issue. Also using items and switching between then will become less responsive, which will make pvp less intense, but I can't think of a reasonable workaround for that.

Also, I am not worried about cheating as I am making this game just to have fun with friends.

Thanks.

\$\endgroup\$
  • \$\begingroup\$ Hello Rs, usually, questions that are like "What is the best way to ...?" are usually too broad or opinion-based to be answerred, if you're able to make your question more specific, then it might help gettings answers too. \$\endgroup\$ – Steven Sep 7 '18 at 6:18
  • \$\begingroup\$ Why would using an authoritative server make the player movement less responsive? Many of the most popular, fast-paced multiplayer games out there use this authoritative model. When you say this though: "I have read up on client prediction, server reconciliation, entity interpolation and lag compensation..." that's probably a clue that multiplayer replication is a BIG topic, and the "best" way to handle multiplayer might be significantly more complex than fits in a simple answer here. Narrowing your question might help you get the answers you need. \$\endgroup\$ – DMGregory Sep 27 '18 at 0:02
0
\$\begingroup\$

Rather than sending key-presses, you may be better sending actions/results.

So, for moving a character, you can send Direction and Speed. If the client does not receive a new Direction and Speed for an NPC or another player , it attempts to extrapolate from the last values (e.g. it keeps trying to move the player instance in the same Direction, at the same speed, or adds the same acceleration, etc)

Every so often, you also send the Location (X/Y/Z) to resync instances across clients.

Similarly, the server and other clients don't need to know "You pressed A", they just need to know "you attack with your sword".

This allows you to have your Client make a decision based on your actions for responsiveness, then the Server ratifies it and distributes it based on everyone's actions, which may retcon your result:
- Player 1 Attacks Player 2, and their Client show this as 8 damage.
- The "Attack" command is sent to the server, which has also just received a "Defend" command from Player 2.
- The server decides that Player 2 blocked in time, and tells everyone that Player 2 took 4 damage, and what the new health is.

Player 2 sees that they loose 4 health
Player 1 sees the 8 damage the dealt is changed to 4
Everyone else sees that Player 1 attacks, and Player 2 blocks for 4 damage

(If you play MMOs that use this system when they are at high-load, you will sometimes encounter "rubber-banding", where you move but the server doesn't receive all of the commands - when the resync happens you snap back to a previous location, like a bungee cord.)

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.