DEV Community

Aceld
Aceld

Posted on • Edited on

13. MMO Game Server Application Protocol

[Zinx]

<1.Building Basic Services with Zinx Framework>
<2. Zinx-V0.2 Simple Connection Encapsulation and Binding with Business>
<3.Design and Implementation of the Zinx Framework's Routing Module>
<4.Zinx Global Configuration>
<5.Zinx Message Encapsulation Module Design and Implementation>
<6.Design and Implementation of Zinx Multi-Router Mode>
<7. Building Zinx's Read-Write Separation Model>
<8.Zinx Message Queue and Task Worker Pool Design and Implementation>
<9. Zinx Connection Management and Property Setting>

[Zinx Application - MMO Game Case Study]

<10. Application Case Study using the Zinx Framework>
<11. MMO Online Game AOI Algorithm>
<12.Data Transmission Protocol: Protocol Buffers>
<13. MMO Game Server Application Protocol>
<14. Building the Project and User Login>
<15. World Chat System Implementation>
<16. Online Location Information Synchronization>
<17. Moving position and non-crossing grid AOI broadcasting>
<18. Player Logout>
<19. Movement and AOI Broadcast Across Grids>


MMO-GAME Source Code

https://github.com/aceld/zinx/tree/master/zinx_app_demo/mmo_game


In the context of the MMO game demo application, the client portion acts as a server, while the upcoming content in this chapter pertains to the server portion of the game. Prior to development, it is necessary to define the protocol between the two parties.

13.1 Protocol Definition

Based on the requirements of the client application, it is understood that the client will transmit the following types of application protocol game data to the server, as shown in Table 13-1.

Table 13-1

MsgID Client Server Description
1 - SyncPid Synchronize the player's login ID (used for player ID).
2 Talk - World chat.
3 MovePackege - Movement.
200 - BroadCast Broadcast messages (Tp 1: world chat, 2: coordinates synchronization (spawn point sync), 3: action, 4: updated coordinates after movement).
201 - SyncPid Broadcast messages for disconnect/aoi disappearance.
202 - SyncPlayers Synchronize the position information of nearby players (including oneself).

13.1.1 Table Explanation

The meaning of each column in the table is as follows:

MsgID: The Message ID of the current communication protocol, synonymous with the MsgID defined in Zinx.
Client: The name of the protocol for the client, and the current message is initiated by the client.
Server: The name of the protocol for the server, and the current message is initiated by the server.
Description: The description of the current protocol.

13.1.2 Protocol Meanings

In Table 13-1, there are a total of 6 protocols, and their meanings are as follows:

SyncPID Protocol: Initiated by the server to the client, Message ID 1. It informs the client of other online users that the current player has come online.

Talk Protocol: Initiated by the client to the server, Message ID 2. It represents the client-initiated world chat message, informing the server to broadcast the message.

Position Protocol: Initiated by the client to the server, Message ID 3. It carries the coordinates of the client player's movement.

BroadCast Protocol: Initiated by the server to the client, Message ID 200. It represents server-initiated broadcast messages to all online player clients. The Tp variable indicates different types of business.

SyncPID Protocol: Initiated by the server to the client, Message ID 201. It represents server-initiated broadcast messages for player disconnections or changing viewpoints.

SyncPlayers Protocol: Initiated by the server to the client, Message ID 202. It synchronizes the positions of surrounding players, including the player's own position, to other players.

13.2 Proto3 Protocol Definitions

This section will define the specific data protocol format for Protobuf based on the protocol definition format provided in Table 13-1.

13.2.1 Protocol One (MsgID=1)

The SyncPid protocol is used to synchronize the player's unique ID generated by the server to the client after the player logs in. This ID serves to identify the player.
The Proto protocol definition is as follows:

message SyncPid {
    int32 Pid=1;
}
Enter fullscreen mode Exit fullscreen mode

Relevant Parameters are as Follows:
(1) Pid: Player ID.

13.2.2 Protocol Two (MsgID=2)

Talk Protocol, world chat, this message is initiated by the Client client.

Proto protocol definition is as follows:

message Talk {
    string Content = 1;
}
Enter fullscreen mode Exit fullscreen mode

Relevant parameters are as follows:
(1) Content: Chat message.

13.2.3 Protocol Three (MsgID=3)

Position Protocol, coordinates of movement, message about the movement coordinates of the client player, initiated by the Client.

Proto protocol definition is as follows:

message Position {
    float X = 1;
    float Y = 2;
    float Z = 3;
    float V = 4;
}
Enter fullscreen mode Exit fullscreen mode

Relevant parameters are as follows:
(1) X: X-axis coordinate in the 3D map.
(2) Y: Height coordinate in the 3D map, not the Y-axis.
(3) Z: Y-axis coordinate in the 3D map.
(4) V: Angle of rotation for objects or tasks (0~360°).

13.2.4 Protocol Four (MsgID=200)

BroadCast Protocol, broadcast message, the server broadcasts the message to all online player clients, and the Tp variable indicates different types of businesses.

Proto protocol definition is as follows:

message BroadCast {
    int32 Pid = 1;
    int32 Tp = 2;
    oneof Data {
        string Content = 3;
        Position P = 4;
        int32 ActionData = 5;
    }
}
Enter fullscreen mode Exit fullscreen mode

Relevant parameters are as follows:

(1) Pid: Player ID.
(2) Tp: Type of broadcast message. 1 for world chat, 2 for coordinates, 3 for actions, and 4 for coordinates update after movement.

(3) Data: Specific message format for transmission. Data is decorated with the "oneof" keyword. Depending on Tp, Data will have different specific data types. Content is for Tp=1, broadcasting world chat data; Position is for Tp=2 or 4, broadcasting coordinate data; ActionData is for Tp=3, broadcasting specific player action data.

13.2.5 Protocol Five (MsgID=201)

SyncPid Protocol, broadcast message, a player goes offline or a player's visibility disappears from the AOI region, initiated by the Server.

Proto protocol definition is as follows:

message SyncPid {
    int32 Pid = 1;
}
Enter fullscreen mode Exit fullscreen mode

Relevant parameters are as follows:
(1) Pid: Player ID.

13.2.6 Protocol Six (MsgID=202)

SyncPlayers Protocol, synchronizes the positions of nearby players, including the current player, to other players. Initiated by the Server.

Proto protocol definition is as follows:

message SyncPlayers {
    repeated Player ps = 1;
}

message Player {
    int32 Pid = 1;
    Position P = 2;
}
Enter fullscreen mode Exit fullscreen mode

Relevant parameters are as follows:
(1) Player: Collection of players to be synchronized, decorated with the "repeated" keyword.
(2) Pid: Player ID.
(3) Position: Position information.


MMO-GAME Source Code

https://github.com/aceld/zinx/tree/master/zinx_app_demo/mmo_game


[Zinx]

<1.Building Basic Services with Zinx Framework>
<2. Zinx-V0.2 Simple Connection Encapsulation and Binding with Business>
<3.Design and Implementation of the Zinx Framework's Routing Module>
<4.Zinx Global Configuration>
<5.Zinx Message Encapsulation Module Design and Implementation>
<6.Design and Implementation of Zinx Multi-Router Mode>
<7. Building Zinx's Read-Write Separation Model>
<8.Zinx Message Queue and Task Worker Pool Design and Implementation>
<9. Zinx Connection Management and Property Setting>

[Zinx Application - MMO Game Case Study]

<10. Application Case Study using the Zinx Framework>
<11. MMO Online Game AOI Algorithm>
<12.Data Transmission Protocol: Protocol Buffers>
<13. MMO Game Server Application Protocol>
<14. Building the Project and User Login>
<15. World Chat System Implementation>
<16. Online Location Information Synchronization>
<17. Moving position and non-crossing grid AOI broadcasting>
<18. Player Logout>
<19. Movement and AOI Broadcast Across Grids>


Author:
discord: https://discord.gg/xQ8Xxfyfcz
zinx: https://github.com/aceld/zinx
github: https://github.com/aceld
aceld's home: https://yuque.com/aceld

Top comments (0)