Analysis of online network process of Sprague 3 part-time work mode

Original link: https://victrid.dev/2022/si-pu-la-dun-3-da-gong-mo-shi-lian-ji-wang-luo-guo-cheng-fen-xi/

s3-disconnected.jpg

Screenshot of disconnected connection

introduce

I was working part-time today and was angry with my teammates who dropped the line again. Just before, I wrote a P2P protocol analysis plug-in for Wireshark based on Nintendo Clients , and I captured some network data of part-time work. I probably recorded the network interaction in part-time work mode, and I can do some simple analysis.

The entire interaction process of part-time work is encrypted by Nintendo’s SSL certificate and the key distributed by Nintendo’s server. If you want to get or modify what kind of content is transmitted online, you must crack the Switch to bypass the verification of the certificate, which violates the use agreement and will be banned. The tools and methods we use in this article are only based on public content and do not involve cracking the Switch itself.

This article is also based on my own speculation on network traffic observations, and has nothing to do with Nintendo, nor does it make any guarantees about its correctness. After reading this article, you can only get a rough idea of ​​why your teammates/you are disconnected, it can neither solve the problem of teammates/you disconnection, nor allow you to be legendary.

We describe several stages of the game.

match

Nintendo adopted the same next-generation NPLN server architecture as Monster Hunter in this generation. It is said that the concept of microservices has been introduced, and various effects have been improved. But unfortunately, except for some rare cases, this is hardly any help for part-time work.

Hole punching and NAT type detection

The current network infrastructure is such that devices are often hidden behind a router’s NAT. Before connecting to P2P, NAT hole punching is required.

An analogy about NAT hole punching is that you tell the router that I am visiting a guest who lives in Room 202 (port number), No. 800 (IP address), Dongchuan Road, and he will come later and leave a door for me. The NAT table in the router is the gatekeeper. Some NATs don’t care about anything. Some NATs only let people who live at No. 800 Dongchuan Road come in. Some NATs not only check whether they live at No. 800 Dongchuan Road, but also check the room number. Room 202 was not allowed to come in.

A, B, and C types of networks correspond to these three gatekeepers. To connect two people online is actually a two-way interaction process. For example, if A and C want to visit each other, Nintendo, as the intermediary, only needs to tell CA which room they live in. After C goes to visit A, the doorman at C’s house will leave the door for A. Readers can think about which networks A, B, and C can be interconnected and which cannot be interconnected. Readers who are interested can read further on NAT types .

network activity

  • The game sends three UDP packets with content e , f or g three times to several servers pointed to by nncs[1,2]-lp1.nnsrv.nintendo.net . The server will return 9 packets, but how many you get depends on your network. The package records:

    • What type of connection is this testing
    • what is your ip address and port number

    For example I am a class B network and only 6 packets are recovered.

    network test

  • Send the IP address and port number you received to the game server to notify you that you are ready to work part-time.

  • During the matching process, the server will push your teammate’s IP address and port number information. At this time, depending on your network, the Pia v11 protocol will be used to send a handshake packet with the destination variable ID, source variable ID, and packet ID all 0. This process also performs NAT hole punching.

  • After receiving such a handshake packet, it will reply a handshake confirmation packet that only writes the source variable ID, and all others are 0. The source variable ID and target variable ID are random variables and may be numbers assigned by the matching system. This number is constant within a match (that is, a queued group of teammates, including a “continue on the same team” game), but varies from match to match.

  • When the handshake confirmation packet is received, it means that the handshake party has established a one-way connection to the handshake party. After that, the encrypted game information will be exchanged, which is expressed as the target variable ID and the source variable ID corresponding to the variable IDs of the handshake party and the handshake party, and the packet ID is incremented from a random number.

  • If the handshake confirmation is not received, the game will notify the server that it cannot connect to the other party. At this time, the matching system may re-match other players, and inform the other party that they cannot match, and no longer send the corresponding packet. Repeat this step until you can connect to each other.

  • Here is an example of the transfer process:

    handshake example

    Note the three packs marked in orange in the picture, I am online with players from the Polish IP. This is a handshake, handshake confirmation, and the process of starting the transmission of encrypted information. The three ICMP packets on the black bottom indicate that my superior router told me that I could not connect to Russian players, so I notified the server and stopped sending packets to Russian players.

  • There is a situation where one of the two sides can’t connect to the other, but luck is good (I guess it’s the fit between the two of you, minus the possible delay, minus the point deduction item that can’t be connected, it’s better than finding a teammate again The price is high), Nintendo will provide a relay server of the TURN protocol. The TURN protocol wraps the Pia protocol packet to be sent intact, and is relayed by Nintendo’s server and forwarded to the other party.

    The TURN protocol is transparent to the receiving end. The specific communication mode can refer to the following figure. The game only establishes a channel for a pair of users in one direction, and the data is unidirectional in the channel.

    Note that the data part of the TURN packet in the figure below starts with the magic number 32 ab 98 64 , indicating that this is a Pia protocol packet, which is the Nintendo P2P protocol packet.

  • When all teammates are ready, “time to work” will be displayed. At this time, it will communicate with the game server and start working in this round.

common problem

The problems that often occur in this step are mostly errors. There are two forms of error reporting: black error boxes in the game interface, and game blurring as the background, error boxes in the Switch system. The following are recorded as game box and system box.

  • The game box says a connection error has occurred. This step is usually not a P2P network error on our side. I guess this situation is pushed to you by the Nintendo server. For example, one teammate cannot connect with another teammate, but they can connect to you, and you have to rematch.
  • The system box says unable to connect to server/connection error. This situation is usually related to the connection between you and Nintendo’s servers, such as your connection is unstable, or Nintendo’s servers are out of repair.
  • The game box says “connection lost”, and there are four lines (i.e. the cover image). This situation may be a combination of the above two. The difference from the above game box is that the system box’s unconnectable error may usually occur when receiving TCP (that is, your connection to the server) error packets, duplicate packets, while the game box usually occurs when the connection is disconnected.
  • The system box says it cannot connect to the other party’s game console. This is usually sporadic and happens when your UDP connection to your teammates fails. For example, there are many errors in UDP transmission caused by network instability. If it occurs frequently, you may need to pay attention to the quality of the router or accelerator, and there may be a situation in which the NAT type is wrongly judged.
  • The game box said that the number of people was not gathered within the specified time. If this happens frequently, you need to check your NAT type first. The NAT types are described above, and the worse the type, the fewer people will be ranked. If the NAT type is good, but it is still difficult to match people, you may need to pay attention to the quality of the accelerator, or if there is a connection blocking situation with your ISP.

If any of your teammates have a poor network connection to the Nintendo server, you will get stuck on the “Time to work” interface. If the teammate is disconnected from the Nintendo server at this time, a “connection error occurred” game box may appear, or it may evaporate on the helicopter.

game process

network activity

communicate with the server

During the whole working process, only a few actions will communicate with the game server. Since I can’t get the exact content of the communication, this step might include:

  • egg into the frame
  • Kill and spawn giant salmon
  • Kill yourself, revive teammates

Interplayer Communication

Everything else is done through P2P communication only. The communication between each pair of players is carried out through a back-and-forth 2 Pia protocol unidirectional “channels” (expressed as increasing packet numbers), and lost packets will not be retransmitted. Send about 15 packets to each teammate per second (similar to the game’s Tick Rate), the size of each packet varies from about 100B to about 700B, and the size of the packet may reach 1KB during settlement.

P2P communication is divided into ordinary events and key events. Actions such as moving and smearing the ground are ordinary events, which will happen in the game as long as the information (such as moving) from the player is received. Being a swimmer, resurrecting, and picking up eggs are the key information. As long as there is one person in the entire game who is not synchronized on the key event, it is considered that the key event has not occurred.

I guess based on the disconnection behavior of the game and the difference in the size of the packets sent to different people, players will be selected as the synchronization benchmark (hereinafter referred to as the homeowner) according to certain rules throughout the game, and players with better network may be more likely to be caught. Chosen as a homeowner.

during the game

The one marked orange in the figure is a channel, and it can be noticed that the packet number is incremented. It can also be observed that the data exchanged with one person is generally larger than the other players, possibly the homeowner responsible for the synchronization. The pink entry in the picture is the communication with the game server.

There are many ways to handle dropped calls .

  • There are 12 channels in total. If a channel fails to work, the game will try to save it, requesting the establishment of a relay from the NPLN server (of course, it may also directly reduce the number of people). It should be noted that the relay is single channel. For example, if I can’t receive a teammate’s package, I will only request the server to transfer the teammate’s package to my direction. At the same time, the NPLN server will notify the teammate that the package sent to me will be transferred through Nintendo.
  • If a non-host player is disconnected from the Nintendo servers, the player will display an in-game error box saying “A connection error has occurred” and the game server will notify all players that the player is disconnected.
  • If the homeowner is unable to connect to a player, it may happen that the player will be kicked from the game server even if the connection to Nintendo is not lost.
  • If the homeowner is disconnected, I personally think that Nintendo may not have written the code to reselect the homeowner, so it will end everyone’s game and pop up an in-game error box of “A connection error occurred” for everyone.

common problem

  • The egg doesn’t fit in the frame : Nintendo’s servers are under repair. This is rare these days.
  • A teammate is standing stupidly, dead and not resurrected : it may be that there is a problem with the connection between you and the teammate, but the system is still trying to reconnect through the TURN forwarding mechanism. Usually with bad luck, within 10 seconds the teammate (or you) will be dropped.
  • Eggs can’t be picked up, eggs are snatched by teammates, teammates can’t help them : Except for the third one, which may be related to the level of teammates, the most likely reason is that the delay between you and the host player is relatively high. If a game starts out smoothly, but suddenly starts to get stuck, it may be that there has been a major change in the homeowner’s connection (or your connection), such as a change in the middle link, and you have to be prepared to drop the line. .
  • A connection error occurred during checkout: The checkout is uploaded by the host to the Nintendo server, and then downloaded to your device by the Nintendo server. When the homeowner uploads, the settlement is already recorded. Therefore, if you check the history and it does not end correctly, it means that the host is disconnected; if there is a normal settlement, it means that the connection between you and the Nintendo server is unstable.

This article is reprinted from: https://victrid.dev/2022/si-pu-la-dun-3-da-gong-mo-shi-lian-ji-wang-luo-guo-cheng-fen-xi/
This site is for inclusion only, and the copyright belongs to the original author.