📜 ⬆️ ⬇️

Sync in online games

Multiplayer online game - packet transfer and messaging between clients and gray (client-server, p2p, tcp / upd, graphs)
Imagine a multiplayer game like lineage


Description of the process and setting the task:

1) each player performs an action on his client and must notify the players of the monsters and game objects within a certain radius.
2) The player should see 3d objects and monsters only within a certain radius.
3) The server performs actions for the world and monsters and notifies all players or players within a certain radius of the object.
4) player monsters and server performing actions form messages or packets
5) the format of the game message or package pseudocode
')
[player1, player2, server] [time_stamp] [client / server] [geo_location] [game_map_location] [net_key] [player_id] [visible_radius] -
[player1, player2, server] Where each item is a serialized object
player [
actions [[hit, player2, fireball], [run, vector], [rotate, radius]],
player [param1, param2],
items [item1, item2],
message [string, chat],
gruops [clan, party],
time [time_stamp]
]

If you send messages from clients to the server and form a large package.

Problems:

1) Synchronize players
2) Client server synchronization
3) Low transfer rate tcp / upd, low transfer rate clien-server
5) Only the server should know about all packages,
6) Players are geographically at different distances - which reduces transmission speed.
7) You need to send packets only to neighboring objects
8) Packages can be lost, packages can be replaced

Solution options at the level of the game:
1) Two-dimensional array [] [] which corresponds to the physical map of the game world
2) Adding game objects to this array
3) Adding a radius of visibility for each object that can send packets.
4) The object sends packets only to objects that are within a certain radius of it.
6) Object groups are formed.
5) One of the objects is appointed as the main
6) Each of the group of objects sends each packet
7) A reference package is created.
8) The main group object sends the reference packet to everyone.

Network level solution and server:
1) A world map is taken and a two-dimensional array is created, the cell contains information about the region [country] [city] and about all clients located in the region
2) A graph is constructed on these points and the shortest paths to each point are calculated.
3) In each region, select several clients with the highest speed
4) One of the clients becomes a data transfer server for everyone else in the region.
5) Regional servers transmit messages along the chain and the shortest path between themselves and to the server

1) Clients send timeout messages.
2) A thread is created on the server that forms message queues
3) A message queue is also created on the main server.

I want to know your opinion about this algorithm and the concept as a whole.

Source: https://habr.com/ru/post/280720/


All Articles