Summary of network synchronization scheme for hand-tour backstage PVP system

Source: Internet
Author: User
Tags current time random seed switches time interval notification center server hosting advantage

Http://www.gameres.com/476063.html

Overview
PvP system has become a novice tour of the online standard, hand-tour PVP system experience is excellent, to a large extent, determines the quality of the game. From the recent six months on-line novice tour, more and more games to the core play center of gravity has been placed in the PvP multiplayer game, hand-to-face in a more severe, multi-person real-time interactive direction of development. This paper is mainly divided into two parts of the PVP system, the first half of the main introduction of hand-Tour background PvP synchronization scheme introduced, the second part of the main introduction of daily speed and is now developing the new Racing Hand Tour PVP Network synchronization program.

Consistency problem of synchronization mechanism

The essence of synchronization problem is consistency, in the process of the same game multiplayer, player A sees player B's state, should be consistent with player B itself to see their own state. Delay is the essential reason for inconsistency, assuming that both sides of the network latency is 0, the two should be synchronous, but in reality, is often impossible, the synchronization mechanism discussed in this paper is to solve the consistency problem, for different game types, different team technology accumulation, According to their own situation can adopt different synchronization mechanism technical solution.

According to the topological structure of the network, the network synchronization communication can be client-client direct-to-peer communication or client-server-client server forwarding communication, and the client chooses one as the server to forward the communication between clients. In this paper, the common hand-travel background synchronization scheme mechanism to differentiate, divided into frame synchronization scheme, position state information synchronization scheme is elaborated.

1. Frame Synchronization

Principle

The presence of players A, B, C, server servers set to S, assuming that players A, B, C is a state machine, the beginning of a, B, C are in the state S1, when the server S to a, B, c the same input I, at this time a, B, c through the local operation, get the same state S2. In this short time, it can be understood that all players from the state S1 sync to the state S2, three players to achieve the purpose of synchronization. As long as the state machine function model fun, initial S1, input i is determined, then the results obtained by three players S2 certainly is also certain.


As shown in the figure, players a, B, C in T1, T2, T3 time will receive the server sent over the input, and thus become the same state S1,S2,S3, to achieve the purpose of synchronization. Can imagine this is a turn-based game, each T1, T2, T3 interval is a round, the player at the end of the turn, the state is consistent synchronization. That for our game, the server input can be the player in this round of operation sequence, can be status information, can be, depending on the design of the client game scheme. As long as this input arrives at any client there, it can be simulated into a real game scene. At this point you may have this question, if the frame synchronization is likened to a turn-based game, that will not appear a card one card situation appears. In fact, the average number of frames for the game is 30-60 frames players think is fluent, for frame synchronization, we put inside every time interval short enough, the response of the human eye can be deceived, like a film show, a continuous picture of the rapid play, the human eye will feel is continuous occurrence, The same as frame synchronization is like a turn-based game, but as long as the turn time is short enough, the player looks like a continuous. Usually, we call this round a logical frame, the logical frame can be set according to the game type, self-polishing decision, in general, 4-6 render frame around a logical frame is reasonable, about 1S of time, the client will receive the server 8-10 logical frame input.

Background implementation

1. Core Ideas

For background development, the server mainly play a role in the control of the client frame information input and output management, the server is like a time series of the drive, every interval, will be collected at this time interval of the client input, issued broadcast to all clients, thereby driving the client to perform frame synchronization processing, In short, as a server in the timeline sequence, collect slices, every interval, the time slices collected by the data sent to the client.

1. For frame synchronization, the frequency of data synchronization is high, of course, it is hoped that the smaller the network latency is better, due to the TCP sliding window and retransmission mechanism, resulting in delay can not be controlled, so frame synchronization generally using UDP network transmission. The mention of UDP here will derive the problem of reliability, for the client, if some UDP packets do not receive what to do, this is the frame synchronization client will appear in the case of dropped frames, this time depends on the client and the server to specify a specific retransmission mechanism.

2. Server single Office data first to each frame issued by the client's data is numbered, and then saved, such a client network is poor, lost some of the package in the middle, you can send a request to the server, I now play to which the serial number of the frame, the server can be the client's current serial number frame and the client default frame issued , so that after the client gets the data, it can continue to speed up the playback by the way of the frame fast, to catch up with the current time. In this way the client's performance is in the same place.

3. In general, the package volume of the frame synchronization scheme is relatively small, for the client at this time interval does not upload any data, the server must help the client constructs an empty frame, so that other clients appear without input.

4. For a short period of heavy retransmission, the server can selectively take a combined strategy to reduce the number of instant packets received by the client. At the same time can also take advantage of the packet size is not more than the MTU, as far as possible to carry some of the previous time frame information, to maximize the information push to the client, reduce the probability of client application retransmission.

2, broken wire re-connected

Server single office can be stored down all the logical frame, when the client disconnected, re-login, the server can be all the logical frame to the client, the client to get all the logical frame, you can quickly run through the background of all the logical frame, when running, loaded into the screen, and then back to the game single innings. Because of the disconnection, it is the same logic frame that runs all the clients on a single board, so the player's state is consistent when the game is resumed.

3, anti-plug

The server is cut logical frame, do not perceive the logic of the client, so the anti-plug this block inconvenient verification, you can proceed from the following two aspects to check 1. Because all the client data is consistent, you can let the client to calculate several eigenvalues according to their own data, strictly speaking, All the client's calculated eigenvalues should be the same, because their data is the same, when the player is inconsistent, it can be concluded that the player is suspected of cheating. 2. Through the process or completion of a single board, reporting statistics to the server, the server through a number of data related relationships, data validation. (a bit similar to the hand-tour single-game check)

4. Points of special concern

1. Randomness: There will inevitably be random logic in the game, when pseudo-random comes in handy, by issuing a unified random seed to ensure that each client produces the same random sequence. The critical hit in War3 is the pseudo-random mechanism used, which is also the solution to deal with the problem of frame synchronization.

2. Floating point number: floating point number as far as possible to avoid, and special attention is, if the use of third-party libraries, to ensure that the client on the different platforms of the calculation results are consistent, for example, using some physics engine, on Android and iOS platform will be possible to calculate different results, it is necessary during the development process, Be careful to avoid using platform-inconsistent APIs.

3. Difficulty in commissioning

Frame synchronization is difficult to debug, need a good log system, for inconsistencies can be traced to the cause of log.

As soon as possible to set up the recording function through the video playback can repeatedly see the logic of the different steps to facilitate the problem location.

In the single office to increase the debug mode inconsistent check, when inconsistencies occur, timely detection, positioning reasons. It would be better if you could introduce an automated test.

2. Position synchronization

Principle

Location synchronization is better understood, and the first batch of hand-tour PvP is also mostly used position state synchronization method. The most important difference between position synchronization and frame synchronization is that the server is not doing a tangent logical frame, but instead passively helps the client to forward the position state synchronization package for synchronization purposes. Compared to the existence of players A, B, C, player a reported their position and status to the server s, server s to the player reported the package broadcast to Player B, player C, player B, C received the package, know the position and status of player A, do the corresponding logic. Because of the network latency, the way the location is synchronized causes the packet received by the receiver to be a packet of historical time before the sender, which has a certain lag. Need to obtain a lower network latency, can be sent through UDP to send the synchronization package, the frequency of sending packets relative to frame synchronization can be lower, the server can handle the logic of the single board (using props, etc.), can sense the information in the single office.

Background implementation

1. Core Ideas

The background of the position synchronization is relatively easy to implement, only need to manage the life cycle of the single office, the control of the single office, the end of the single innings, in the process of single-station UDP transfer player position State Synchronization package, the important information can be transmitted through TCP to the server for logical arbitration (using props, attacking others, etc.), The client receives the package to do the corresponding display logic, as long as the client is escalated to the server in the number of packets per second enough, the other clients in the 1s can get multiple synchronization packages, the client can be in the local state of the location of a timely correction, so as to achieve the purpose of each client synchronization.

2. Anti-Plug

Position synchronization Anti-plug is easier to achieve than frame synchronization, first, because the important data is to interact with the server, so the server single office data stored in the player's data information, such as the player in the current time in a single game props, players on the map of the approximate position. For example, clients often appear to use their own items do not exist, often launched CS request to the server, the server itself is a player on the props information, it can be determined that the player has a certain suspicion of cheating. Another example, racing games, the last client reported that the synchronization package is also in the middle of the track, the next second players report their own line, these backstage immediately perceived that the client is suspected of cheating.

3. Wire Break re-connect

CS synchronous disconnection, to see the server to a single bureau of the depth of participation, if the server has a large number of players current status position information, the player can be re-connected back to the time by the server to send all the current player status position information to the player, drop line players to get the full amount of information, immediately be able to reconstruct the single-innings situation If the server is not deep, in fact, only the client has this full time slice of the full position state information, the server can randomly pick a better network condition of the client, to the client to initiate pull the full amount of position state information request, as if the server to pull a time slice of the client request, like, The client at this point in the summary of all the information on the server, the server to the full amount of information, the next to the drop-in-line re-connected clients, so that the drop-off client can also get the full amount of data information, and restore the single office. In the development process, you have to consult with the foreground, in the early stages of development to take into account the needs of the recovery mechanism, client data management Unified Modular.

Case: Sky Fly and New Racing Hand Tour PVP System solution

The above mainly elaborates the theory methodology, the following actual project talks about the program implementation. Game type to a large extent determines the choice of synchronization scheme, racing games need instantaneous strong interaction of the situation is relatively small, only the car and car collision with each other this moment to reflect the needs of this scenario. Therefore, from the beginning of the technology selection to use the CS position synchronization, used to do the day fly PvP system, because it is an online project, a version of the time of about one months, it is unlikely to overturn the client-side architecture using frame synchronization technology, so the days before the PVP is the CS position Synchronization Technology solution, Background development ideas to follow the following ideas for development, stability---scalability---performance, imagine that the PvP server is a stateful server, if the external network often appears unstable causes the server can not service, it will be the same machine tens of thousands of players at the same time drop the line, This is unacceptable at the operational level of the product, so stability is at the forefront of all requirements. The second is now the tide of change fast, accidentally server load is full, may be a new play a time out, and suddenly rushed to the new system up, the original deployment of the machine facing the problem of empty load, so in order to solve the stability and reliability, to improve the scalability of the system, the last remaining problem is performance.

One, adaptive network switching

In order to guarantee the reliability, this paper makes a targeted optimization strategy for the network of mobile phones. As we all know, the characteristics of mobile phone network is not stable, especially in the process of network switching, there will be flash-off. In the WiFi environment, the delay is probably guaranteed between the 40-80ms, if it is a 3G network, the real latency of the external network fluctuations between the average 60-200ms, very unstable (taken from the sky-flight Network PVP statistics). In PvP, the synchronization information of the position state, the client takes priority to the peer to send directly, through the UDP sends, for other important requests, communicates with the client through the TCP, the position synchronizes the packet. In this connection, the server backend communicates with the client using Adaptive network switch, which can satisfy the requirement of efficiency and ensure the reliability of the network. Before the start of a single office, the server will open up the UDP channel with all the clients, and the IP port will be broadcast to all the clients at the start, and the client can synchronize the position with peer communication. When the client senses that the peer cannot communicate, the network packet is sent over UDP to the server, the server forwards the packet through UDP, and when the server senses that the UDP network is not unblocked with a player, the server automatically switches to TCP to communicate with the client for the synchronization packet. In short, the initial client-to-peer communication, found that the network is poor, using server UDP forwarding, the server is aware of a client network is not good, the subsequent synchronization package for the player will be switched to TCP for forwarding. And all this network switching is triggered entirely at the bottom of the network, the application layer is not aware of. The principle of implementation is similar to the ACK acknowledgement mechanism of TCP, which will be described in the form of graphic combination.


* With two timestamps on the head of the network message, the two fields that play a key role are:

M_u32udpservertime; The server finally sends the UDP packet time to the client (the server uses this field to determine if the client received the UDP packet)

M_u32clientudptime; The client finally sends the UDP packet time to the server (the client determines whether the server receives a UDP packet based on the field)

The following server, for example, describes how to perceive the client and server UDP network is not good, instead of switching over the TCP network to send messages.

Server Maintenance Two variables

Waitconfirmtime (server timestamp pending confirmation)

Confirmtime (confirmed receipt of server timestamp)

The first server like a client to send a UDP synchronization package, at this time for T1, can be understood as the package of SEQ for T1, when the server variable waitconfirmtime becomes T1, the server in T1 time sent to the client, do not know the client received the seizure, to wait for confirmation.

When the client receives the UDP packet just now, the client will return the time stamp back in any TCP or UDP packet he wants to send to the server (the Red belt seq:t1 in the picture), in order to let the server know the package of the time just T1, the client has confirmed that it received, when the server received the packet, Knowing that the client has received the package, the server's variable confirmtime is updated to T1., at this time waitconfirmtime and confirmtime are equal, then you can think the network is good, because the server sent the package, the client is all confirmed received.

The fact is that Waitconfirmtime has always been more than Confirmtime is to advance, the two alternately increased, because the client confirmed that there is definitely no time to send a fast, to determine whether the network is still a good standard, when I want to send the client to the contract, I will first look at the client's confirmtime, Waticonfirmtime and the current timestamp three relationships, first if the waitconfirmtime is greater than confirmtime (indicating that the package client is confiscated, so no confirmation) over a certain threshold value, It is considered that the server has not received the packet client, the server will automatically switch to TCP to the client forward synchronization location package, to ensure that the client can receive.



The client determines that the network condition with other clients is the same as that of the server UDP, but uses the different fields of the Baotou.

Real external network data situation: the average single innings time 3 minutes, a player per second synchronization packet frequency 3-7, adaptive network switching threshold for 5S,UDP to get through the rate of about 73.2%, WiFi player accounted for about Two-thirds, the external network completely use peer-to-complete single bureau number only about 7%, Full use of peer and UDP packets to complete the number of single innings is 63.2%, the drop rate is about 5% up and down

Through the data of the external network to draw some conclusions, the situation of mobile phone network is still not suitable for using peer-to communication, the subsequent novice tour of the network development is not used in the way of peers, but directly from the beginning of the server using UDP synchronous location forwarding. The hand-travel network is not stable, the flash will be more, so it is necessary to do a single-line disconnection re-connect.

Second, the connection of broken wire

Disconnection due to the server is not involved very deep, so when the player dropped the line, the player's resources are not destroyed in time, but to the end of the single innings and then the unified destruction. (derived from the special situation, the player has dropped the line, no one in the bureau, so can not drive down, resulting in resources can not be recycled, to increase the operation of Checkinvalid, need to check for a long time without network interaction of a single office, time-out can forcibly recover resources). Wire break the re-connection takes the form of a time slice to one of the clients to restore the information in a single board.

Third, the expansion of scalability

Stability of the problem is resolved, in the expansion of scalability, because the sky is the first batch of the PVP system of the hand tour, there is not much reference on the market, so before the launch of adequate pressure measurement, and in operation and management, fully consider, pre-buried a number of switches, so as to deal with peak operating conditions.

1.PVP server support does not stop the update, dynamic add reduce machine services.

The player is determined by matching the server to login to which PvP server to do multiplayer games, matching server is equivalent to a center, know the current players on all PvP server hosting, when the need to restart a PvP server, can be configured on this PVP server, after the configuration takes effect, The reverse Notification Center matches the server, so that subsequent players will not be assigned to the PVP server, until the PVP server on the end of the single Board (for about 3 minutes), you can freely operate the server, you can replace the program, you can dynamically down the rack and so on. The advantage of this is that just on-line when the problem is more serious, after the problem is exposed, immediately modify the code to add a targeted strategy, direct non-stop in the user no sense of the situation, in the daytime all the external network of PvP server restarted the update.

2. Configuration of key items that affect performance

A. Client-related (configuration of the base number of synchronization packages per second)

In consultation with the client colleagues, the number of synchronization packets sent per second in different situations is also dynamic change, do not use a fixed frequency of synchronization, in the case of racing games, when I do not have any operation, driving on the straight, can be corresponding to reduce the synchronization frequency, when I quickly change to or over the situation, can dynamically increase the volume of synchronization, In short, according to their own game scene, dynamically adjust the synchronization frequency, so as to save the synchronization package, reduce server load.

B. Inside the server

At that time, the pressure measurement found that the main bottleneck of the server is the CPU, a single process of service, the more the number of packets per second processing of the larger, the logic on PvP is not too heavy, the main CPU consumption in the network package, the days fly using the most original tconnd, plus decryption is also the server to do their own, Encryption and decryption are bound to consume more CPU resources. At that time left the switch, for the downlink packet position status information, set the non-encrypted switch. This data is minimal even if the unencrypted effect is not. is to leave more room to operate, in the face of peak operations, the use of expediency.

Four, anti-plug

Two aspects, on the one hand, is to deal with the important game process is through TCP and client interaction, the server for verification. On the other hand, in the process of single office, the client at a certain time, will be reported in the time period of statistical information, after the end of a single office, will report the global statistics, the server collects these statistics, will be after the check.

Summarize

This article mainly elaborated the frame synchronization and the CS position synchronization principle and the main realization method, and according to the actual project, has collated oneself in does the PVP system accumulated some experience experiences, because individual strength limited, inevitably has the mistake place. PvP synchronization of the smooth experience, on the one hand is the design of technical solutions, on the other hand can not be separated from the planning process in some numerical precision grinding, in the numerical polishing methodology, there is no universal guidelines, the only way is based on the experience of a constant attempt (for example, the design of synchronous packet frequency, Client pre-prediction algorithm and so on), regardless of whether the use of the frame synchronization scheme or CS position Synchronization scheme, I believe there will be many parameters related to the game features need to be later polished settings, in order to achieve a smooth multi-person synchronization experience. Different game types, different team technology accumulation, may choose different technical solutions. No matter what the technical solution, the smooth PVP experience alone is not enough to achieve the force behind, in the final analysis of the background of the front desk planning team resultant.

In a nutshell is a smooth pvp sync experience = correct design + fine finishing.

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.