MMO sending player position to other players

When it comes to sending data to a player in MMOs, is this what the server is basically doing? (pseudo code)

every gametick:
for each player connected:
compile string of positions of all other players in range
if string different lastString:
send data to player
set lastString to string


It's really hard to have an answer like "Yes, that's how its done" because each game is different. I will assume you mean a "classic MMORPG" where you walk in an open world and you can interact with players if you are close to them.

• Basically the server makes sure that it doesn't waste cycles. If you are in one corner of the map, there is no reason for the server to bother sending you the position of a player on the other side of the map. That's why it keeps track of who player is near whom.
• The server tries to send the position to the right players as often as possible, but networking can be unstable, so the client will need to make "predictions" sometimes. For example if a player was walking north, but lost connection for 2 seconds, the game will assume the player keeps walking north, until it connects again and gives the correct location. This is how a lot of jokes about players suddenly "snapping" to other locations started.
• When the server sends data to a player, it makes sure not to pause until the player responds, so the game goes on even if a player loses connection for some time. This is most likely done with Threads, but it depends on language/platform/game.

But for the most part, I would say, what you described is a good starting point. You can try implementing that, and see if there is some problem you didn't think of.

• For Massive multiplayer it would be async IO, which scales much better than thread per connection. – ratchet freak Feb 20 '19 at 9:59
• @ratchetfreak to be fair, I didn't mean one thread per connection. But in some languages you'd need the main thread, and possibly one more to handle networking (for example in C). There are languages that take that functionality away from the programmer, but they still use threads behind the scenes. – TomTsagk Feb 20 '19 at 10:03
• You can do async IO in C without spinning up new threads (even in the background or the kernel). – ratchet freak Feb 20 '19 at 10:20
• @ratchetfreak do you have a link or a specific "keyword" I can search for? I've started doing networking in C recently and haven't explored all the options. I'd be interested to read some more about it. – TomTsagk Feb 20 '19 at 10:23
• in linux it's all about setting SOCK_NONBLOCK and the select/(e)poll loop (which will also handle notifications of other file descriptors). In windows you also need to set non blocking and then one of the WaitForObject functions, Or use the IO completion queue. – ratchet freak Feb 20 '19 at 10:55