Matrix Connection Test - themeldingwars/Documentation GitHub Wiki

Matrix Connection Test

This is a command that can be run from the games console matrix_connectionTest to test the clients ability to connect to a server, it does a minimal amount to connect and then disconnect, this makes it a great first test for a server emu :>

This page will try to describe in detail what needs to be done to be able to have a server pass this test and makes a good place to start getting familiar with the networking protocol and see how the basics work.

The Command

Run matrix_connectionTest 127.0.0.1 in the games console to start the test connection to localhost 127.0.0.1, with out a server it will fail, but below is how it should look if there is a server running on 127.0.0.1:25000.

06:04 RAM:1675MB FPS:142 INFO  RENDER  >matrix_connectionTest 127.0.0.1
06:04 RAM:1675MB FPS:142 INFO  RENDER  matrix_connectionTest: Testing 1 hosts ...
06:04 RAM:1675MB FPS:142 DEBUG NETWORK GameServer socket 'matrix_connection_test' created.
06:04 RAM:1675MB FPS:142 INFO  NETWORK GameSocket 'matrix_connection_test' connecting to 127.0.0.1:25000
06:04 RAM:1675MB FPS:142 DEBUG NETWORK Created Socket 3756
06:04 RAM:1675MB FPS:142 DEBUG NETWORK 'matrix_connection_test' Entering State Initializing(1)
06:04 RAM:1675MB FPS:142 DEBUG NETWORK Game socket 'matrix_connection_test' opened on port 63133
06:04 RAM:1675MB FPS:142 TRACE NETWORK matrix_connection_test Sent INIT (timeout=400, count=1)
06:04 RAM:1675MB FPS:142 DEBUG NETWORK 'matrix_connection_test' Entering State Transferring(2)
06:04 RAM:1675MB FPS:142 TRACE NETWORK matrix_connection_test Sent TRANSFER (timeout=800, count=1)
06:04 RAM:1675MB FPS:142 DEBUG NETWORK 'matrix_connection_test' Entering State Connecting(3)
06:04 RAM:1675MB FPS:142 TRACE NETWORK matrix_connection_test[1] Reliable Channel INIT (seqstart=1)
06:04 RAM:1675MB FPS:142 TRACE NETWORK matrix_connection_test[2] Reliable Channel INIT (seqstart=1)
06:04 RAM:1675MB FPS:142 TRACE NETWORK matrix_connection_test Sent CONNECT (timeout=800, count=2)
06:05 RAM:1675MB FPS:143 TRACE NETWORK matrix_connection_test Sent CONNECT (timeout=400, count=1)
06:05 RAM:1675MB FPS:143 DEBUG NETWORK 'matrix_connection_test' Entering State Connected(5)
06:05 RAM:1675MB FPS:143 DEBUG NETWORK Game socket 'matrix_connection_test' connected.
06:05 RAM:1675MB FPS:143 NOTCE  GAME   matrix_connectionTest: 127.0.0.1 SUCCESS
06:05 RAM:1675MB FPS:143 DEBUG NETWORK 'matrix_connection_test@63133->127.0.0.1:25000' Entering State Destroyed(8)
06:05 RAM:1675MB FPS:143 DEBUG NETWORK Game socket 'matrix_connection_test@63133->127.0.0.1:25000' closed by owner.
06:05 RAM:1675MB FPS:143 DEBUG NETWORK Closing socket 3756
06:05 RAM:1675MB FPS:143 DEBUG NETWORK 'matrix_connection_test@63133->127.0.0.1:25000' Entering State Closed(9)
06:05 RAM:1675MB FPS:143 TRACE NETWORK matrix_connection_test@63133->127.0.0.1:25000[1] Reliable Channel FINISH (recv_ack=1, send_ack=1)
06:05 RAM:1675MB FPS:143 TRACE NETWORK matrix_connection_test@63133->127.0.0.1:25000[2] Reliable Channel FINISH (recv_ack=0, send_ack=0)
06:05 RAM:1675MB FPS:143 DEBUG NETWORK GameServer socket 'matrix_connection_test@63133->127.0.0.1:25000' deleted.

Message Step Through

Here is a message by message walk through. C 🖥️ Means this message came from the client. S 🖧 Means this message came from the server.

Note: Every UDP packet to or from the server starts with a uint SocketID.

1: C 🖥️ - POKE

[uint]          [char * 4]      [uint]
SocketID        MsgID           Protocol Version
-----------     -----------     -----------
00 00 00 00     50 4F 4B 45     00 04 5B A3
0               POKE            2740651008

The client send a POKE Jack message with the protocol version that it is using.

2: S 🖧 - HEHE

[uint]          [char * 4]      [uint]
SocketID        MsgID           Socket ID
-----------     -----------     -----------
00 00 00 00     48 45 48 45     AE 75 EA 41
0               HEHE            1105884590

The server replies back to the port the POKE came from with a HEHE message with this connections assigned SocketID.

3: C 🖥️ - KISS

[uint]          [char * 4]      [uint]              [ushort]
SocketID        MsgID           Socket ID           Streaming Protocol Version
-----------     -----------     -----------         -----
00 00 00 00     50 4F 4B 45     AE 75 EA 41         42 E2
0               KISS            1105884590          57922

The client says what Streaming protocol version it is using. And note that the socket id isn't set in the header as that would then miss identify this message as somethign other than a JACK message, it is added as part of the message instead.

4: S 🖧 - HUGG

[uint]          [char * 4]      [ushort]            [ushort]
SocketID        MsgID           Game Server Port    Sequence Start
-----------     -----------     -----               -----
00 00 00 00     48 45 48 45     9B 0E               D7 7E
0               HUGG            3739                32471

The last message in the handshake from the server gives the client a port to send the rest of its messages over and the sequence number it should use to start its message channels with. More on that in the Sequence number page. (TODO: link to page)

The rest of these messages are sent to the port given in the HUGG message

Note: If the SocketID isn't 0 then what follows is a byte buffer of X game packets, the start of each of these packets is a common two byte header of the form.

[2bits]      [2bits]         [1bit]         [11bits]
Channel      Resend Count    Is Splitted    Length

There is a better and more indepth explanation of this header in the protocol overview page.

5: C 🖥️ - TimeSyncRequest

[uint]          [ushort]        [byte]      [long]
SocketID        Packet Header   MessageID   ClientUnixTime
-----------     -----           --          -----------------------
AE 75 EA 41     00 0B           04          58 29 D4 B7 0B 00 00 00
1105884590      *See below*     4           50328775000

Packet header expanded

00 0B                         
[2bits]      [2bits]         [1bit]          [11bits]     
---------    ------------    ------------    ------------ 
Channel      Resend Count    Is Splitted     Length       
0            0               False           11

This is the client sending a request to the server with its time as a micro second unix epoch. This is used as the connections heartbeat and is periodically.

6: S 🖧 - TimeSyncResponse

[uint]          [ushort]        [byte]      [long]                      [long]
SocketID        Packet Header   MessageID   ClientUnixTime              ServerUnixTime
-----------     -----           --          -----------------------     -----------------------
AE 75 EA 41     00 13           05          58 29 D4 B7 0B 00 00 00     EB FA 0A 0A 49 28 05 00
1105884590      *See below*     5           50328775000                 1451669049768683

Packet header expanded

00 0B                         
[2bits]      [2bits]         [1bit]          [11bits]     
---------    ------------    ------------    ------------ 
Channel      Resend Count    Is Splitted     Length       
0            0               False           19

The reply to the clients request, it send back the client time that was given in the request as well as the servers time.

7: C 🖥️ - TimeSyncRequest

[uint]          [ushort]        [byte]      [long]
SocketID        Packet Header   MessageID   ClientUnixTime
-----------     -----           --          -----------------------
AE 75 EA 41     00 0B           04          E0 89 D4 B7 0B 00 00 00
1105884590      *See below*     4           50328812000

Packet header expanded

00 0B                         
[2bits]      [2bits]         [1bit]          [11bits]     
---------    ------------    ------------    ------------ 
Channel      Resend Count    Is Splitted     Length       
0            0               False           11

Another time sync request. Note: Perhaps its one per reliable channel (Channel 1 and 2) ?

8: S 🖧 - TimeSyncResponse

[uint]          [ushort]        [byte]      [long]                      [long]
SocketID        Packet Header   MessageID   ClientUnixTime              ServerUnixTime
-----------     -----           --          -----------------------     -----------------------
AE 75 EA 41     00 13           05          E0 89 D4 B7 0B 00 00 00     E2 7F 0B 0A 49 28 05 00
1105884590      *See below*     5           50328812000                 1451669049768683

Packet header expanded

00 0B                         
[2bits]      [2bits]         [1bit]          [11bits]     
---------    ------------    ------------    ------------ 
Channel      Resend Count    Is Splitted     Length       
0            0               False           19

The reply for the second time sync request.

9: C 🖥️ - Login

[uint]          [ushort]        [ushort]        [byte]      [byte x 26]          
SocketID        Packet Header   Sequence Num    MessageID   Unkown
-----------     -----           -----           --          -----------------------------------------------------------------------------    
AE 75 EA 41     40 1F           9B 0E           11          00 4D 07 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   
1105884590      *See below*     3739            17         

Packet header expanded

00 0B                         
[2bits]      [2bits]         [1bit]          [11bits]     
---------    ------------    ------------    ------------ 
Channel      Resend Count    Is Splitted     Length       
1            0               False           31

Don't really know much about this form of the login packet for the connection test.

10: S 🖧 - Matrix ACK

[uint]          [ushort]        [byte]      [ushort]        [ushort]              
SocketID        Packet Header   MessageID   Sequence Num    ACK For
-----------     -----           --          -----           -----
AE 75 EA 41     00 07           02          9B 0F           9B 0E
1105884590      *See below*     2           3995            3739

Packet header expanded

00 0B                         
[2bits]      [2bits]         [1bit]          [11bits]     
---------    ------------    ------------    ------------ 
Channel      Resend Count    Is Splitted     Length       
0            0               False           7

An ack for a message on the matrix channel that had the sequence number 3739 and that was the last Login packet.

11: S 🖧 - Login Reply

[uint]          [ushort]        [ushort]        [byte]      [byte x 10]              
SocketID        Packet Header   Sequence Num    MessageID   Unknown
-----------     -----           -----           -----       --------------------------------
AE 75 EA 41     40 0F           9B 0E           22          22 00 00 00 00 00 00 00 00 00 00
1105884590       *See below*     3739            34

Packet header expanded

00 0B                         
[2bits]      [2bits]         [1bit]          [11bits]     
---------    ------------    ------------    ------------ 
Channel      Resend Count    Is Splitted     Length       
1            0               False           15

12: C 🖧 - Matrix ACK

[uint]          [ushort]        [byte]      [ushort]        [ushort]              
SocketID        Packet Header   MessageID   Sequence Num    ACK For
-----------     -----           --          -----           -----
AE 75 EA 41     00 07           02          9B 0F           9B 0E
1105884590      *See below*     2           3995            3739

Packet header expanded

00 0B                         
[2bits]      [2bits]         [1bit]          [11bits]     
---------    ------------    ------------    ------------ 
Channel      Resend Count    Is Splitted     Length       
0            0               False           7

13: C 🖥️ - Close

[uint]          [ushort]        [byte x 5]         
SocketID        Packet Header   Zeros
-----------     -----           -----
AE 75 EA 41     00 07           00 00 00 00 00
1105884590      *See below*     

Packet header expanded

00 0B                         
[2bits]      [2bits]         [1bit]          [11bits]     
---------    ------------    ------------    ------------ 
Channel      Resend Count    Is Splitted     Length       
0            0               False           15

14: S 🖧 - Close

[uint]          [ushort]        [byte x 5]         
SocketID        Packet Header   Zeros
-----------     -----           -----
AE 75 EA 41     00 07           00 00 00 00 00
1105884590      *See below*     

Packet header expanded

00 0B                         
[2bits]      [2bits]         [1bit]          [11bits]     
---------    ------------    ------------    ------------ 
Channel      Resend Count    Is Splitted     Length       
0            0               False           15

And that its, that whats needed to complete the connection test. So if you implement a server that passes this, then I guess you have a server emulator, just prob not the most interesting one :>

⚠️ **GitHub.com Fallback** ⚠️