Difference between revisions of "Network Protocol"

From Custom Mario Kart
Jump to navigation Jump to search
Line 1: Line 1:
This page describes the '''network protocol''' used by [[Mario Kart Wii]]. It is very incomplete at this moment.
+
This page describes the '''network protocol''' used by [[Mario Kart Wii]].  
 
 
  
 
__TOC__
 
__TOC__
Line 27: Line 26:
 
Then it will use TCP connection to the servers and UDP packets for the player to player data transfer.
 
Then it will use TCP connection to the servers and UDP packets for the player to player data transfer.
  
First it connects Nintendos servers (N-server).
+
First it connects the Wiimmfi server (N-server).
 
In a room or while racing, all Wiis communicate directly to each other.
 
In a room or while racing, all Wiis communicate directly to each other.
 
In a race, only some ''alive'' records are send to a N-server.
 
In a race, only some ''alive'' records are send to a N-server.
  
=== Connecting Nintendo servers ===
+
=== Connecting the Wiimmfi-Server(s) ===
  
If entering the Mario Kart WFC, the Wii started with DNS queries to find out the IP addresses of the following servers:
+
When entering the Mario Kart WFC, the Wii started with DNS queries to find out the IP addresses of the following servers:
 
* gpcm.gs.nintendowifi.net
 
* gpcm.gs.nintendowifi.net
 
* gpsp.gs.nintendowifi.net
 
* gpsp.gs.nintendowifi.net
Line 47: Line 46:
 
* mariokartwii.ms19.gs.nintendowifi.net
 
* mariokartwii.ms19.gs.nintendowifi.net
 
* naswii.nintendowifi.net
 
* naswii.nintendowifi.net
 +
 +
("nintendowifi.net" replaced with "wiimmfi.de" for the Wiimmfi server)
  
 
Then it starts the communication with nintendos servers and the first packet goes to ''mariokartwii.available.gs.nintendowifi.net''.
 
Then it starts the communication with nintendos servers and the first packet goes to ''mariokartwii.available.gs.nintendowifi.net''.
Line 54: Line 55:
 
=== Point to point communication ===
 
=== Point to point communication ===
  
The Wii use a frequency of 59.94Hz (based on NTSC, about 1/60s) as time base.
+
The Wii uses a frequency of 59.94Hz (based on NTSC, about 1/60s) as time base.
All clients send every second pulse (~1/30s) a status packet to one of the other clients.
+
All clients send a status packet to one of the other clients every second pulse (~1/30s).
If there for example 3 clients A, B and C, then A sends first a packet to B and then, 1/30s later, a packet to C, and again 1/30s later, the next packet to B. this means, that the individual status update is done only every 1/15s. This update time is reduced to 11/30s (~1/3s), if 12 clients are playing. And that's the reason for the many lagging effects if playing with many players.
+
When there are for example 3 clients A, B and C, then A sends first a packet to B and then, 1/30s later, a packet to C, and again 1/30s later, the next packet to B. This means, that the individual status update is only done every 1/15s. This update time is reduced to 11/30s (~1/3s), when there are 12 clients in a race. And that's the reason for the many lagging effects when playing with many players.
  
The average packet length is about 220 bytes, so the the total traffic is about 6.6 KB/s (52.8 KBit/s) in both directions, independent of the number of clients.
+
The average packet length is about 220 bytes, so the total traffic is about 6.6 KB/s (52.8 KBit/s) in both directions, independent of the number of clients.
  
 
== Records ==
 
== Records ==
Line 107: Line 108:
 
| [[MKWii Network Protocol/SLOT|SLOT]] || <tt>46fc.570x</tt> || 0x08
 
| [[MKWii Network Protocol/SLOT|SLOT]] || <tt>46fc.570x</tt> || 0x08
 
| The following message is related to client slot '''x''' (default: for the sender). This is mainly used in combination with ANNOUNCE and USER to tie information to specific client slots.
 
| The following message is related to client slot '''x''' (default: for the sender). This is mainly used in combination with ANNOUNCE and USER to tie information to specific client slots.
If a client has bandwidth problem, it can use another client as proxy to reduce its own traffic during the race. Such indirect packets are also prefixed by a SLOT record.
+
If a client has bandwidth problems, it can use another client as proxy to reduce its own traffic during the race. Such indirect packets are also prefixed by a SLOT record.
 
|-
 
|-
 
| [[MKWii Network Protocol/STATUS|STATUS]] || <tt>bb49.cc4d</tt> || 0x14+N
 
| [[MKWii Network Protocol/STATUS|STATUS]] || <tt>bb49.cc4d</tt> || 0x14+N
| A status record with 5 different extensions. Byte 9 describes the extension length '''N''' and is 0, 4, 8, or 16. One task is to select and advice client slots to clients.
+
| A status record with 5 different extensions. Byte 0x08 describes the status type. One task is to select and advice client slots to clients.
 
|-
 
|-
 
| [[MKWii Network Protocol/HANDSHAKE|HANDSHAKE]] || <tt>fdfc</tt> || 0x14+N
 
| [[MKWii Network Protocol/HANDSHAKE|HANDSHAKE]] || <tt>fdfc</tt> || 0x14+N
| Different handshake records with different length. At the moment an announce of Nintendo (with ip+port) and a little handshake between host and guest are known.
+
| Different handshake records with different length. At the moment, an announce from Nintendo (with ip+port) and a little handshake between host and guest are known.
 
|-
 
|-
 
| [[MKWii Network Protocol/QUIT|QUIT]] || <tt>fefe.68</tt> || 0x03
 
| [[MKWii Network Protocol/QUIT|QUIT]] || <tt>fefe.68</tt> || 0x03
Line 132: Line 133:
 
* [[Wiimms mkw-ana (tool)]]
 
* [[Wiimms mkw-ana (tool)]]
 
* [http://www.mariokartwii.com/f101/mkw-ana-mario-kart-wii-network-protocol-109421.html Discussion at mariokartwii.com]
 
* [http://www.mariokartwii.com/f101/mkw-ana-mario-kart-wii-network-protocol-109421.html Discussion at mariokartwii.com]
* [http://forum.wii-homebrew.com/board42-kreativitaet/board329-mkw-server-project-english/ MKW-Server Project] (Project to create own MKWii servers)
+
* [http://forum.wii-homebrew.com/board42-kreativitaet/board329-mkw-server-project-english/ Wiimmfi-Project] (Project to create own MKWii servers)
  
 
<br/>
 
<br/>

Revision as of 06:41, 29 May 2015

This page describes the network protocol used by Mario Kart Wii.


In Progress
This article is managed by Wiimm and will grow slowly. Feel free to edit typos and grammatical or speech issues. If you have additional information, please complete this page.


Introduction

The analysis of the data is done with the tool mkw-ana. So the naming of mkw-ana for objects (records, stages, ...) is used here. Because of the very early phase of the analysis, names and structures may completely change.

You can discuss this topic at Wii-Homebrew.com (English and German) or at mariokartwii.com (English).

Terms and definition

Template:MKWii Network Terms

General description

The Mario Kart Wii traffic starts with some name resolutions. Then it will use TCP connection to the servers and UDP packets for the player to player data transfer.

First it connects the Wiimmfi server (N-server). In a room or while racing, all Wiis communicate directly to each other. In a race, only some alive records are send to a N-server.

Connecting the Wiimmfi-Server(s)

When entering the Mario Kart WFC, the Wii started with DNS queries to find out the IP addresses of the following servers:

  • gpcm.gs.nintendowifi.net
  • gpsp.gs.nintendowifi.net
  • gamestats.gs.nintendowifi.net
  • gamestats2.gs.nintendowifi.net
  • mariokartwii.available.gs.nintendowifi.net
  • mariokartwii.natneg1.gs.nintendowifi.net
  • mariokartwii.natneg2.gs.nintendowifi.net
  • mariokartwii.natneg3.gs.nintendowifi.net
  • mariokartwii.master.gs.nintendowifi.net
  • mariokartwii.gamestats.gs.nintendowifi.net
  • mariokartwii.gamestats2.gs.nintendowifi.net
  • mariokartwii.ms19.gs.nintendowifi.net
  • naswii.nintendowifi.net

("nintendowifi.net" replaced with "wiimmfi.de" for the Wiimmfi server)

Then it starts the communication with nintendos servers and the first packet goes to mariokartwii.available.gs.nintendowifi.net.

More Details about the servers

Point to point communication

The Wii uses a frequency of 59.94Hz (based on NTSC, about 1/60s) as time base. All clients send a status packet to one of the other clients every second pulse (~1/30s). When there are for example 3 clients A, B and C, then A sends first a packet to B and then, 1/30s later, a packet to C, and again 1/30s later, the next packet to B. This means, that the individual status update is only done every 1/15s. This update time is reduced to 11/30s (~1/3s), when there are 12 clients in a race. And that's the reason for the many lagging effects when playing with many players.

The average packet length is about 220 bytes, so the total traffic is about 6.6 KB/s (52.8 KBit/s) in both directions, independent of the number of clients.

Records

Each UDP packet can be split in records. Records are logical units. The following table shows:

  • A name used by mkw-ana.
  • Value of the first 4-6 bytes (Record ID, big endian, hex).
  • Length of the record.
  • Description.
List of Records
Name Record ID Length Description
CHECKSUM 0000.0000 0x08 A checksum record used for the most data records.
USER 0000.000x 0xc0 A user information including a FC and 2 Miis for both users of the client. x is 1 for 1 player or 3 for 2 players.
ANNOUNCE 1000.0000 0x08 or 0xc8 Announce a new user by sending it's FC4. This record is send by a Nintendo Server to the host and the new guest. After receiving an announce, both clients start with a little handshake.
unknown 1000.0000.xxxx ? ?
ROOM 1000.0004 0x0c A ROOM record is always placed before an USER record. The byte at offset 8 decides the sub type:
  • 0: unknown
  • 1: Send by host: Start an event (GP, Team, Ballon or Coin).
  • 2: unknown
  • 3: unknown
  • 4: Send a room message (online chat).

Room records are only sent in room events. There is a prefix record "GLOBAL" for non-room-events.

SELECT 1000.0038 0x40 This record is send while selecting driver and track. It is always placed before an USER record. The byte at offset 0x3d decides the phase:
  • 0: Prepare the race.
  • 1: Before first race: Driver selection. All races track selection by user.
  • 2: Track lottery. Before start of the lottery, the host sends to all clients the winning user and track.
RACE
RACEDATA
ITEM
EVENTHEAD
EVENTDATA
1028.2800 0x58
+U*0x40
+U*0x08
+0x18
+N
Record send during race and battle. The content of race and battle records are different.

The record is followed by 1 or 2 extensions (RACEDATA, each 0x40 bytes) for 1 or 2 users of the client. After the user extensions a list with items and events is appended.

SLOT 46fc.570x 0x08 The following message is related to client slot x (default: for the sender). This is mainly used in combination with ANNOUNCE and USER to tie information to specific client slots.

If a client has bandwidth problems, it can use another client as proxy to reduce its own traffic during the race. Such indirect packets are also prefixed by a SLOT record.

STATUS bb49.cc4d 0x14+N A status record with 5 different extensions. Byte 0x08 describes the status type. One task is to select and advice client slots to clients.
HANDSHAKE fdfc 0x14+N Different handshake records with different length. At the moment, an announce from Nintendo (with ip+port) and a little handshake between host and guest are known.
QUIT fefe.68 0x03 This Record is sent when a client quits a rooms or a race. This record isn't prefixed by a CHECKSUM-Record.

Stages

Room

Table

Prepare a race

Count down

First finished

All finished

Links


Template:MKWii Network Protocol mk8:MK8 Network Protocol