Design and definition of data package in network game

Source: Internet
Author: User

Contact a period of time of the online game package design, with some preliminary ideas, want to borrow this article summed up, but also make a record, in order to facilitate the later update their own ideas.
Network Game Technology research and development, divided into three main aspects: Server design, client design, database design. The intermediary between the server and the client to implement the game logic is the game data packet, and the server and the client can drive the game logic by exchanging the game packet and according to the data packet of the analysis. The essence of the network game is interactive, and the interactive control is done by the server and the client, and the cooperation must depend on the data to complete.
The current network game in the packet, the definition of the form is various, but summed up, generally have the following elements: packet length, packet type, packet parameters, check code.
The packet length is used to determine the length of the current game packet, because in the underlying TCP network transmission, the transmission sometimes merges several small packets into a large data packages for transmission efficiency, and in the process of merging, Instead of merging every logically complete packet together, sometimes, because of this merging, a logically complete game packet is sent in two send, so that after the current data is sent to the receiving party, its tail packet must cause a "broken tail" phenomenon, In order to determine the end of the situation and the specific content of the tail, game packets in the design will generally provide the packet length of this information, according to the recipient of this information to know whether the packet received a broken tail, if there is a broken tail, Then the broken tail of the packet and the next packet to be sent over to create the original logical meaning of the packet.
The packet type is used to identify what type of package the current package is and what it means.
The packet parameter is a more specific description of the package type, which specifies the parameters required in the description of this type of package. For example, a speech packet, its packet type, can be expressed in a numerical value, while the specific speech content and speakers as the package parameters.
The function of the check code is to verify the contents of the packet, so as to ensure that the contents of the package are not changed in the process of transmission, and that the packet is not a legal packet in the format according to the check code. To check code as a way to improve the security of packets, is already the popular way of online games. Packet design, is generally the first to determine the overall structure of the package, and then to specific breakdown of what the package, each package should contain what content, and finally the details of the package in the contents of the specific number of bytes and meaning.
The specific design of the packet is generally divided and delineated according to the function of the game. For example, the game has a chat function, then you have to design the client and server chat packets, the client should have a description of the speech and speaker information packet, and on the server side to contain a user to speak and speaker information broadcast packets, through it, The server side can broadcast the current player's speech to other nearby players. For example, in the game to have the transaction function, then with this function corresponds to may have the following packets: To apply for a transaction package, to apply for a transaction, to allow or reject a transaction package, to allow or reject a transaction, to submit a transaction package, to submit a package for the transaction, to confirm the transaction, to cancel the transaction package, to cancel the transaction packet , transaction success or failure of the information package. It should be noted that in these packages, there are either one party to use and the other not to use, while others are used by both sides of the package. For example, the application for a transaction package may only be used by one party, and the other will receive a packet of information for the transaction, while the confirmation of the transaction and the submission of the transaction are the same for both parties when they are determined to make the transaction. The design of the package also follows the design principle of top to bottom, that is, to determine the function of the package, and then determine the package should contain information, and finally determine the location and length of the information should be occupied. A layer of analysis and definition, the final formation of a complete package definition scheme. In the actual package design process, the backtracking situation is often present. Due to the initial design of the ill-conceived or other reasons, may cause the package design scheme modification or additions and deletions, this time an important issue is to remember to update your design documents. In my package design, I used the following package description form to describe:
Package numbering function describes the corresponding class or struct body name type command Word command parameter structure and meaning
According to the function of the game, we can roughly delineate the approximate structure and the approximate contents of the package. However, the package design also contains more content, how to ensure that the packet logic concise premise of shortening the design length of the packet to improve the packet transmission speed and the speed of the game, this is also an important issue we should consider. In general, the design of the packet, should try to avoid the production of more than 100 bytes of the packet, most of the definition of the package control within 100 bytes, or even 20-50 bytes within. In the package I've defined, most of the packets are within 20 bytes, which can be a bit bigger for a packet such as a pass-through server list and a user list. In a word, it should be as short as possible to describe the package function and meaning as succinctly as possible.
In terms of package structure design, I have another extensible idea: dynamically define the position of each element in the packet. This way, when switching to other games or replacing the package structure of the current game, simply change the dynamic definition of those elements without having to completely redesign the package structure. For example, we have a packet number, packet type, packet parameters, check code the starting position and length of the information to define, so that you can form a dynamic definition of the packet structure, the future of the packet transplant will be very helpful, a potentially dynamic change in the packet structure of the game packet, To a considerable extent, it has increased the difficulty of the external analysis of the envelope structure.
In the design of the package, it is best to classify the design according to the different packet client and server side. For example, the lobby and the game server's packet and game server and game client packet separate to design, on the package number indicates their differences (in different opening words), so the overall structure of the package will be clearer.

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.