I am implementing the multiplayer(client-server architecture) of a game, and I came to doubt about entities common to players.

I understand how to share information such as the position of the players among themselves. However I am caught up in the logic of how to do for the common entities between them.

Imagine: Two players and a chicken, how would you share the position of the chicken between them? because it needs to move, and can not move in different places in the two clients, the two clients should see the chicken in the local place, but if I send the position of the chicken of one client, and also the other, there may be conflicts.

What should I do. Choose one of the clients to be the "master" who will send the chicken position to the other players? How do they handle this in online games?

I am thinking of doing the following:

I can not imagine the calculations being done on the server working properly, I will use the example of the hens, my hens would have an AI maybe too complex to stay on the server. I thought the following, one of the clients of the update area, as it is a big map, the clients are receiving updates being in chunks of the map, then one of the clients would be the master (the first one that entered the channel) , the others would just listen to it, the "master" client would then send to the server the chicken positions/states and the server would send to all the clients enrolled in the channel the chicken position/status.

It works similar to a "token" who is at the top of the channel users list is going to deal with the chicken's calculations.

advantages: - Less work for the server to handle.

Disadvantages: - Poorly trained players could change the position of the hen and make the game experience unpleasant.

What could you do to avoid this disadvantage?

  • \$\begingroup\$ In P2P Multiplayer games ( e.g: CoD ) one player will be the host and the other the clients which means that your statement with the master is theoretically correct. However P2P is a bad design since the whole session is disturbed if the "master" has internet problems, has slow internet etc. In Dedicated Servers it's "basically" the same but that the server is most of the times a really powerfull machine only hosting the game and doing nothing else. So it will calculate the heavy stuff and send the clients the informations. Please correct me if I'm wrong \$\endgroup\$ – Nico Oct 27 '17 at 5:56
  • \$\begingroup\$ Yes, but I'm already using the client-server architecture. but in this case the server could not calculate the movement of the chicken, this is done on the client. My question is exactly how to do this using the client server architecture, P2P would not be an option. \$\endgroup\$ – PerduGames Oct 27 '17 at 8:45
  • 1
    \$\begingroup\$ Why can't you let your server calculate the movement of the chicken? I'm not an expert at all but to my logic NPC based stuff should be handled by the server and the clients should get the informations what the NPC is doing. Every other interaction however could be from the client. When shooting etc is involved it gets tricky but for basics that should be the way to go. Take a look at this Answer which has basically the same question as you \$\endgroup\$ – Nico Oct 27 '17 at 9:05
  • \$\begingroup\$ @Brian I edited my question. \$\endgroup\$ – PerduGames Oct 27 '17 at 13:10
  • 1
    \$\begingroup\$ Are you sure that your comparison with a token ring makes sense? A ring network topography means that each host only receives data from the host before it and sends data to the host after it. So in the worst case, a message needs to travel through every single host in order to reach the host which comes before the sender. That doesn't seem to be what you are describing. \$\endgroup\$ – Philipp Oct 27 '17 at 13:47

The vast majority of online games handle all game mechanics on the host. The host can be either a dedicated server or it can be the same computer a player is playing on. The situation described in the question, with "an AI too complex to stay on the server", is a very exotic requirement. Most games spend only a very small fraction of their computing resources on game mechanics. The vast majority is used for visualizing them.

But if you are indeed creating a very unusual game where the game mechanics are extremely computational expensive, but their results still small enough to send via network in real-time, then you could distribute the work evenly between hosts. When there are 10 players in the game, have each one manage one tenth of the game world.

  • \$\begingroup\$ I thought better, and I think it is not worth dealing with the calculations in the client, would have many more disadvantages than advantages. I will have to make an adjustment of what was in my mind to work out. But I think it would be the best way. \$\endgroup\$ – PerduGames Oct 28 '17 at 2:43

From what I have seen so far, the most common approaches for multiplayer are either peer-to-peer connections (with a master client and connecting clients) or a client-server structure.

Regarding client-server, I would say (like Nico) that you should calculate the movement of the chicken on the server, and send the information (calculations) to both connected clients. This way, there is no real client 'owner' as both clients are recieving the data from the server (the server is the owner in this case).

  • \$\begingroup\$ in fact it is not only in P2P that one can use the strategy of "master" and "slave", this can also be implemented in the client-server architecture. \$\endgroup\$ – PerduGames Oct 27 '17 at 12:50
  • \$\begingroup\$ @PerduGames Do you know if the multiplayer is going to be large? From what I've seen, doing the master/slave on p2p is not so fast because the speed depends on the master's ping. But I think this would also be the case on client/server, if you use a master/slave strategy with clients. Also where did see that a client/server can implement master/slave... as I am unable to find that anywhere. \$\endgroup\$ – D.Kallan Oct 27 '17 at 13:05
  • \$\begingroup\$ @Kallan I edited my question. Read on, I do not know if it exists, I just thought I could do it. \$\endgroup\$ – PerduGames Oct 27 '17 at 13:11
  • \$\begingroup\$ @PerduGames have you seen the accepted answer on how to manage all the npc ai objects on the server? \$\endgroup\$ – D.Kallan Oct 27 '17 at 13:20
  • \$\begingroup\$ I'm reading, but that does not answer the question. I do not think it's a good thing to process things on the server, it limits me to too simplistic mechanics or server overload. \$\endgroup\$ – PerduGames Oct 27 '17 at 13:27

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