Design of a high performance network game server architecture

Source: Internet
Author: User

The network game structure is divided into the client and the server side, the client uses the 2D drawing engine or the 3D drawing engine to draw the real-time picture of the game world, the server side is responsible for responding to all client's connection request and game logic processing, and control all the client's game screen drawing. Client and server through the network packet interaction to complete each step of the game logic, because the game logic is handled by the server, to ensure that the face of massive user login, the game has a good fluency and user experience, excellent server architecture played a key role.

1 Server Architecture Design

1.1 Server Architecture Classification
The architecture of a server group is generally divided into two types: the first is a server architecture with a gateway server, and the second is a server architecture without a gateway server, both of which have pros and cons. Before giving the server architecture design, the two design scenarios are discussed in detail. The so-called Gateway server, is actually gate server, such as Logingate, Gamegate and so on. The primary responsibility of the gateway server is to isolate the client and the game server, and the client program communicates directly with the gateway servers without needing to know the specific game server internal architecture, including their IP, port, network communication model (completion port or epoll), etc. The client connects to the gateway server only, and forwards the packets through the gateway server to interact with the game server indirectly. Similarly, the game server does not communicate directly with the client, and the protocol sent to the client is forwarded through the gateway server.

1.2 Server Architecture Design
Depending on the size and design of the online game, the type and number of servers in each group are different. The server group architecture with Gateway server is designed in this article as shown in 1.


In this paper, the design of the server as a gateway server architecture, while increasing the complexity of the server design, but it brings the following benefits:
(1) As a transit station for network communication, is responsible for maintaining the intranet and external network isolation, so that the external can not directly access internal servers, to ensure the security of intranet servers, to a certain extent, less plug-in attacks.
(2) The Gateway server is responsible for parsing packets, adding and decrypting, time-out processing and certain logic processing, so that the error packets and illegal packets can be filtered out in advance.
(3) The client program only need to establish a connection with the gateway server to enter the game, no need to establish multiple connections with other game servers, save the client and server programs network resource overhead.
(4) When the player jumps the server, such as the large scene switch, does not need to disconnect with the gateway server connection, the player data in the different game server between the switch is the intranet switch, the switch work instantaneous completion, the player almost imperceptible, this guaranteed the game smoothness and the good user experience.
While enjoying the benefits of a gateway server, there are two situations that can lead to negative effects: how to avoid a traffic bottleneck in a high-load situation for a gateway server, and an issue where a single-node failure of a gateway can prevent an entire set of servers from being serviced externally. The above two problems can be solved by "multi-gateway" technology. As the name implies, "multi-gateway" is the existence of multiple gateway servers, such as a group of servers can be configured three gamegate. When the load is large, you can increase your gateway's overall traffic by increasing the gateway server, and when one gateway server goes down, it only affects the clients connected to the server, and the other clients are unaffected.
As you can see from the server architecture diagram in Figure 1, a set of servers includes Logingate, Loginserver, Gamegate, Gameserver, DBServer, and Mserver. Logingate and Gamegate are gateway servers, typically a group of servers will be configured with 3 gamegate, because stability is critical to network game operations, and server outages and other emergencies are potential risks in game operations. Configuring multiple servers can effectively reduce the risk of a single server outage. In addition, configuring multiple gateway servers is also an effective means of load balancing. The following is a detailed explanation of the main functions of the various servers and the interaction of data with each other.
(1) logingate
Logingate is mainly responsible for maintaining the network connection and communication between the client and the Loginserver when the player is logged in, and to encrypt and decrypt the communication data between the Loginserver and the client.
(2) Loginserver
Loginserver main function is to verify that the player's account is legal, only through the authenticated account to login to the game. This can filter out some of the illegal accounts, or some malicious login information. As you can see from the architecture diagram, DBServer and Gameserver connect loginserver. Player Login Basic process is, the client sends the account and password to loginserver authentication, if the authentication passes, Loginserver will assign a sessionkey,loginserver to the player will send this sessionkey to the client, DBServer and Gameserver, after the subsequent selection of roles into the game process, DBServer and Gameserver will verify sessionkey legitimacy, here is the intranet authentication, Gmserver the SessionKey from the dbserver, compared to the SessionKey the client brings, and if the SessionKey with the client is inconsistent, it will not be able to successfully acquire the role or enter the game.
(3) gamegate
Gamegate (GG) is responsible for maintaining the GS and the client network connection and communication during the user game process, the GS and the client communication data to decrypt and verify, the client sent to the GS user data to parse, filter the error packet, the client sent some protocol for simple logic processing, These include some timeout judgments in game logic. In the process of selecting roles, the user is responsible for maintaining the network connection and communication between the DBServer and the client, DBServer and verifying the communication data of the client, and making a simple analysis of the user data sent to DBServer by the client. Maintain network connection and communication, encryption and decryption, data forwarding and simple logic processing between client and Mserver.
(4) Gameserver
Gameserver (GS) is mainly responsible for the game logic processing. The online game has a huge world view background, gorgeous fierce camp confrontation and complete equipment and skill system. At present, the network game mainly includes mission system, prestige system, player PK, pet system, stall system, guild system, ranking system, replica system, production system and GEM system, etc. From the perspective of software architecture, these systems can look at GS subsystems or modules, which work together to deal with the entire logic of the game world. Game logic includes character entry and exit games, jump GS, and various logic actions (such as walking, running, talking, and attacking).
As the entire game world has many game scenes, in the framework of a group of servers have 3 GS jointly responsible for game logic processing, each game server is responsible for a part of the map processing, which not only reduces the load on a single server, but also reduces the risk of GS downtime. Player role information will keep the player's last exit when the map number and the GS number, so that when the player logs in again, will enter the last time the GS exit.
mentioned above, after verifying the account, Loginserver will send this sessionkey to GS, when the player chooses the role to login GS, will send SessionKey together GS, then GS will verify SessionKey and its preservation is consistent, If inconsistent, GS will refuse to enter the game. Mserver is mainly responsible for data transmission between the GS and data broadcast, in addition, some systems can also be put on the mserver, which can also reduce the operating pressure GS.
(5) DBServer
The main function of DBServer is to cache player character data to ensure that the character data can be read and saved quickly. Because the amount of role data is relatively large, including the player's level, experience, health, magic value, equipment, skills, friends, guild, and so on. If each GS gets the role data to read the database, the efficiency must be very low, with DBServer cache role data, greatly improve the response speed of data requests.
Loginserver will send the SessionKey to DBServer when the player is selected, and when the player sends the access to the role information agreement, it will bring the sessionkey, if it is inconsistent with dbserver saved SessionKey, The dbserver will assume that the player is not a legitimate user and that acquiring the role agreement will fail. In addition, when the player chooses the character to enter the game formally, the GS will send the dbserver to carry the SessionKey's acquiring role information agreement, then DBServer will also verify the legitimacy of SessionKey. In short, only the client, DBServer, and GS are saved by SessionKey consistent, to ensure that the agreement receives successful feedback.
DBServer communication with the main server Gg,gs and Loginserver,dbserver and GG interaction with the protocol mainly includes column roles, create roles, remove roles, restore roles, dbserver and GS interaction with the protocol includes reading role data, Save role data and jump server, DBServer and loginserver interaction protocol is mainly user login protocol, this time will send SessionKey to DBServer.
(6) Mserver
Each group has a mserver, which is responsible for maintaining data forwarding and data broadcast between 3 GS. Other game systems may also be placed on Mserver, such as Guild systems.
1.3 Main processes for server interaction
The following is the main flow of data communication between servers from these processes can see how the various servers between the data interaction and work together.


The process in Figure 2 illustrates that in the process of selecting a role, the client will send the game account and SessionKey's optional role agreement to GG,GG do some simple processing after the transfer to Dbserver,dbserver to verify the legality of SessionKey, after verification, DBServer will send all the role information from the role information buffer to the client. The client's performance is that when the server group is selected, the client directly displays all the roles under that account, and then chooses the role to enter the game.


The process in Figure 3 illustrates that when a player is selected to enter the game, the client will send the login agreement with the game account, role ID and SessionKey to Gg,gg to do some simple processing and then forward to the GS. GS will verify the legality of the SessionKey, after verification, the GS will pass the results of verification to the client, and GS to DBServer to get the role of the Protocol, these role data is a player all the game data, including equipment, skills and so on.


The process in Figure 4 illustrates that, during the player's game process, the client sends the logical protocol (including walk, talk, run, use skills, etc.) to Gg,gg to complete the decryption and simple logic processing, and then forwards the main logical processing to GS,GS responsible for these protocols.

Summary: This is a simple framework, the real game development process, more complex than this, but this architecture is overall, the current game server architecture is based on some of the expansion. For example, you can also add individual AI servers, chat servers, battle servers, cross-service servers, and so on. The organization of these servers, communication methods can refer to this scenario.

If reproduced, please specify from: Game Technology Network

Original: http://www.youxijishu.com/blogs/31.html

Design of a high performance network game server architecture

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.