Server and client||doc136868

September 20, 2022

Server

The server handles the data of all areas. If an object is created at the server, the data of this object is subject to the data of the server, that is, if the client modifies the attribute a of the object, it will only affect itself, but when the server modifies the attribute a of the object, it will be synchronized to all clients, and the attribute a modified by the client before will be overwritten. Generally speaking, the server is responsible for the specific logic of the game process and receiving messages from the client and then making corresponding logical processing. For example, when the client sends a "mobile" message, the server controls the corresponding entity to move and synchronizes it to all clients.

client

The client only processes data in a small area. Each player's mobile device is a client. After entering the game, the server will continue to send the data within a certain range of the player entity to the player client. The client will render the screen according to these data. At the same time, the client will continue to destroy the data outside a certain range of the player entity, so as to avoid unnecessary data calculation. Generally speaking, the client is responsible for the input of the device, and then sends the input operation to the server. For example, every time the player drags the joystick, the client will send the input direction data to the server. The server moves the player entity according to the direction, and synchronizes it to all clients. The following video simulates the communication range of the client with the editor. Assuming that the whole ground is all the areas of the game, the green area is the communication range of the client. The server will only synchronize the data within this range, while the gray area beyond the range, the client will not get any data.

Server code:

The part dealing with game logic should be put on the server, such as creating and destroying instances, recording player scores, releasing skills, etc. There are two loose standards for deciding whether the logic should be placed on the server. One is that the changes caused by the logic need to be synchronized to all clients. The other is that some data such as player currency on the client may be tampered with by hackers. When the logic meets these two conditions, it should usually be placed on the server for execution.

Client code:

The logic that processes the player's screen output or does not want to synchronize to other clients should be placed on the client. The most common is the GUI interface, which can be used to display game related information and receive player input. The GUI interface is also the unique logic of the client.

Communication between server and client:

PackageHandlers The communication protocol service is used for cross end message transmission. The basic format is protocol name plus protocol parameter table. This kind of protocol cannot be used for single end communication.

Local event communication:

BindableEventBindable events are used for single end message delivery. The basic format is event name plus event parameter table. Such events cannot be used for cross end communication. Bindable events can be passed throughEventInstanceWindowGet the getevent function of the object.

Access rights:

Every API in the class document is sometimes followed by[ServerOnly][ClientOnly]They respectively represent that the API can only be accessed on the server side and the API can only be accessed on the client side. If there is no special description under the class title that the class can only be accessed at one end and there is no permission identifier behind the API, it means that the API can be accessed at both ends, and there will be a port description of access permission on the detailed document page corresponding to the API.