NetworkDesign: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
imported>Hendrik Brummermann No edit summary |
imported>Hendrik Brummermann some cleanup |
||
| Line 5: | Line 5: | ||
{{Likely Outdated}} |
{{Likely Outdated}} |
||
= Basic idea behind Networking = |
== Basic idea behind Networking == |
||
The idea behind arianne's network protocol is to use a single stream of |
The idea behind arianne's network protocol is to use a single stream of TCP packets between the server and the clients. Different kinds of in-game actions create different types of messages that are then interpreted at the opposite side in to meaningful data. |
||
== |
=== TCP Packet Format === |
||
The network system is based on Messages being transmitted using |
The network system is based on Messages being transmitted using TCP. There are two types of data stream; one from the Server to the Client and another one from the Client to the Server. |
||
=== |
===TCP Client to Server communication stream=== |
||
Each message is contained in a SINGLE UDP Packet. There is no mechanism for recovery of lost or repeated messages. |
|||
The messages are sent one after each other over the TCP stream. TCP takes care of sorting the packets and retransmitting lost ones.. |
|||
| ⚫ | |||
| ⚫ | |||
* <i>Protocol version ( 1 byte ) |
* <i>Protocol version ( 1 byte ) |
||
* Type of Message ( 1 byte ) |
* Type of Message ( 1 byte ) |
||
* Client ID ( 4 bytes ) |
* Client ID ( 4 bytes ) |
||
* Rest of Message |
* Rest of Message</i> |
||
=== |
===TCP Server to Client communication stream=== |
||
Each message is held in one or more UDP Packets and the UDP Packet format is as follows: <br> |
Each message is held in one or more UDP Packets and the UDP Packet format is as follows: <br> |
||
{{TODO|update this to reflect the new TCP based protocol |
|||
<b>1st UDP Packet is composed of:</b> |
<b>1st UDP Packet is composed of:</b> |
||
* <i>Total number of packets (1 byte) |
* <i>Total number of packets (1 byte) |
||
| Line 30: | Line 32: | ||
* Type of Message (1 byte) |
* Type of Message (1 byte) |
||
* Client ID (4 bytes) |
* Client ID (4 bytes) |
||
* Rest of Message |
* Rest of Message</i> |
||
<b>All other UDP Packets making up the one message are composed of:</b> |
<b>All other UDP Packets making up the one message are composed of:</b> |
||
| Line 37: | Line 39: | ||
* Signature of the message (2 bytes) |
* Signature of the message (2 bytes) |
||
* Rest of Message (up to 1497 bytes)</i> |
* Rest of Message (up to 1497 bytes)</i> |
||
}} |
|||
The idea is to send the serialized message inside several UDP Packets and then rebuild the full message on the Client. There is no kind of error recovery or retransmission. |
|||
Messages are sent from the Server by simply serializing them. So the message itself contains the protocol version, the type of message and the Client id. |
Messages are sent from the Server by simply serializing them. So the message itself contains the protocol version, the type of message and the Client id. |
||
| Line 44: | Line 45: | ||
Receiving the message is a bit more complex. First we need to determine that we are running a compatible version of the protocol by comparing the protocol version with the expected version in the message. Once we have agreed that the protocol is compatible we read the type of message and we ask the Message Factory ( see [[RolePlayingDesign]]) to build an object of that type with the corresponding data. Once the message is built we simply store it in a queue of incoming messages waiting to be processed. |
Receiving the message is a bit more complex. First we need to determine that we are running a compatible version of the protocol by comparing the protocol version with the expected version in the message. Once we have agreed that the protocol is compatible we read the type of message and we ask the Message Factory ( see [[RolePlayingDesign]]) to build an object of that type with the corresponding data. Once the message is built we simply store it in a queue of incoming messages waiting to be processed. |
||
=Network Manager= |
==Network Manager== |
||
The Network Manager is our router that sends and receives messages to and from the network. The manager exposes the interfaces that allow: |
The Network Manager is our router that sends and receives messages to and from the network. The manager exposes the interfaces that allow: |
||
* Reading a message from the network |
* Reading a message from the network |
||
| Line 95: | Line 96: | ||
That is the basic idea of the Network Manager; however, the manager gets a bit more complex as a result of the need to support Server to Client messages that are bigger than one UDP package. Note that the manager just sends the stream of packets once and doesn't confirm if any of the messages are received. Please refer to [[NetworkDesign#UDP_Packet_Format | UDP Packet Format]] for more info about it. |
That is the basic idea of the Network Manager; however, the manager gets a bit more complex as a result of the need to support Server to Client messages that are bigger than one UDP package. Note that the manager just sends the stream of packets once and doesn't confirm if any of the messages are received. Please refer to [[NetworkDesign#UDP_Packet_Format | UDP Packet Format]] for more info about it. |
||
=Message Types= |
==Message Types== |
||
To communicate, the Client and Server of Marauroa use a stream of UDP packets. The message system belongs to the marauroa.common.net package, so refer to the code for a detailed knowledge of the system. |
To communicate, the Client and Server of Marauroa use a stream of UDP packets. The message system belongs to the marauroa.common.net package, so refer to the code for a detailed knowledge of the system. |
||
| Line 146: | Line 147: | ||
Let's discuss in detail each message type. |
Let's discuss in detail each message type. |
||
==Message C2S Login Request Key== |
===Message C2S Login Request Key=== |
||
This Login Message is sent from the Client to the Server to request the RSA public key of the server. |
This Login Message is sent from the Client to the Server to request the RSA public key of the server. |
||
==Message S2C Login Send Key== |
===Message S2C Login Send Key=== |
||
This Login Message is sent from the Server to the Client in response to a key request. It is composed of two bytes arrays. The first one contains the value of 'n', and the second the value of 'e'. |
This Login Message is sent from the Server to the Client in response to a key request. It is composed of two bytes arrays. The first one contains the value of 'n', and the second the value of 'e'. |
||
==Message C2S Login Promise== |
===Message C2S Login Promise=== |
||
This is the first real action of authentification from the client. It computes a nonce (a random number) and sends a hash of its nonce to the server. This message contains the hash as a bytes array. |
This is the first real action of authentification from the client. It computes a nonce (a random number) and sends a hash of its nonce to the server. This message contains the hash as a bytes array. |
||
==Message S2C Login Send Nonce== |
===Message S2C Login Send Nonce=== |
||
The server responds to the client promise by computing a nonce and sending it in this message. This message contains the nonce as a bytes array. |
The server responds to the client promise by computing a nonce and sending it in this message. This message contains the nonce as a bytes array. |
||
==Message C2S Login Send Nonce Name and Password== |
===Message C2S Login Send Nonce Name and Password=== |
||
The client now sends its nonce, its username and the value Crypt(xor(xor(client nonce, server nonce), password). This message contains 3 fields. The first one is a bytes array containing the client nonce, the second one a string containing the username and the third one a bytes array containing the encrypted password. On reception, the server checks that the hash he received at first is the hash of the nonce he just received. It then decodes the password field, and having the value of the client nonce and its nonce, it gets the value of the password. If the username/password combination is correct then the Server must send a Login ACK Message to indicate to the Client that the message has been correctly processed. However, if the username/password is wrong the Server will send a Login NACK (Not ACKnoledge). |
The client now sends its nonce, its username and the value Crypt(xor(xor(client nonce, server nonce), password). This message contains 3 fields. The first one is a bytes array containing the client nonce, the second one a string containing the username and the third one a bytes array containing the encrypted password. On reception, the server checks that the hash he received at first is the hash of the nonce he just received. It then decodes the password field, and having the value of the client nonce and its nonce, it gets the value of the password. If the username/password combination is correct then the Server must send a Login ACK Message to indicate to the Client that the message has been correctly processed. However, if the username/password is wrong the Server will send a Login NACK (Not ACKnoledge). |
||
==Message S2C Login ACK== |
===Message S2C Login ACK=== |
||
The LoginACK Message is sent from the Server to the Client to indicate that the login process has been completed correctly and that it can proceed to the next step. It has no params. |
The LoginACK Message is sent from the Server to the Client to indicate that the login process has been completed correctly and that it can proceed to the next step. It has no params. |
||
==Message S2C Login NACK== |
===Message S2C Login NACK=== |
||
The LoginNACK Message is sent from the Server to the Client to tell the Client that its login message is incorrect because either the username or password is wrong or because Server has decided to reject the login request, e.g. if the Server is full or because the IP is banned. |
The LoginNACK Message is sent from the Server to the Client to tell the Client that its login message is incorrect because either the username or password is wrong or because Server has decided to reject the login request, e.g. if the Server is full or because the IP is banned. |
||
The message is composed of: Message indicating the resolution. |
The message is composed of: Message indicating the resolution. |
||
==Message S2C Character List== |
===Message S2C Character List=== |
||
The CharacterList Message is sent from the Server to the Client to give the Client a choice of character to play with. This feature models the behavior of having several characters associated with a single account ( see [[DesignOverview#What_is_Marauroa.3F | the Marauroa Feature List]] ). |
The CharacterList Message is sent from the Server to the Client to give the Client a choice of character to play with. This feature models the behavior of having several characters associated with a single account ( see [[DesignOverview#What_is_Marauroa.3F | the Marauroa Feature List]] ). |
||
| Line 176: | Line 177: | ||
Each character name must be unique at Server level, and it is assigned when the character is created. |
Each character name must be unique at Server level, and it is assigned when the character is created. |
||
==Message S2C Server Info== |
===Message S2C Server Info=== |
||
The Server Info Message is sent from the Server to the Client to tell the Client about what Server is running, and details on how to inform the Server administrator of any problems (e.g. their email address). |
The Server Info Message is sent from the Server to the Client to tell the Client about what Server is running, and details on how to inform the Server administrator of any problems (e.g. their email address). |
||
The message is composed of: A List of strings of the type "attribute=value" |
The message is composed of: A List of strings of the type "attribute=value" |
||
==Message C2S Choose Character== |
===Message C2S Choose Character=== |
||
The ChooseCharacter Message is sent from the Client to the Server to indicate what character the user wishes to play the game with. |
The ChooseCharacter Message is sent from the Client to the Server to indicate what character the user wishes to play the game with. |
||
| Line 192: | Line 193: | ||
Once a character is chosen, the only way to choose a new one is by logging out and logging in again. |
Once a character is chosen, the only way to choose a new one is by logging out and logging in again. |
||
==Message S2C Choose Character ACK== |
===Message S2C Choose Character ACK=== |
||
The Choose Character ACK Message is sent from the Server to the Client to notify the Client that the character has been chosen. |
The Choose Character ACK Message is sent from the Server to the Client to notify the Client that the character has been chosen. |
||
| Line 199: | Line 200: | ||
We need this value to track our own character. |
We need this value to track our own character. |
||
==Message S2C Choose Character NACK== |
===Message S2C Choose Character NACK=== |
||
The Choose Character NACK Message is sent from the Server to the Client to notify the Client that the character has not been chosen. This also implies to the Client that it should send another ChooseCharacter Message. |
The Choose Character NACK Message is sent from the Server to the Client to notify the Client that the character has not been chosen. This also implies to the Client that it should send another ChooseCharacter Message. |
||
It has no params. |
It has no params. |
||
==Message C2S Logout== |
===Message C2S Logout=== |
||
The Logout Message is sent from the Client to the Server to indicate that it wants to finish the session. It has no params. |
The Logout Message is sent from the Client to the Server to indicate that it wants to finish the session. It has no params. |
||
If the Client can logout the Server will send a Logout ACK Message and the Client can safely close the connection, but if the Server sends a Logout NACK Message, the Client should keep playing as disconnecting at that moment will leave its avatar in the game uncontrolled ( idle ). |
If the Client can logout the Server will send a Logout ACK Message and the Client can safely close the connection, but if the Server sends a Logout NACK Message, the Client should keep playing as disconnecting at that moment will leave its avatar in the game uncontrolled ( idle ). |
||
==Message S2C Logout ACK== |
===Message S2C Logout ACK=== |
||
The Logout ACK Message is sent from the Server to the Client to notify the Client that the logout has been accepted. |
The Logout ACK Message is sent from the Server to the Client to notify the Client that the logout has been accepted. |
||
It has no params. |
It has no params. |
||
==Message S2C Logout NACK== |
===Message S2C Logout NACK=== |
||
The Logout NACK Message is sent from the Server to the Client to tell the Client that the logout has not been accepted, possibly because something related to the RP entity, for example, combat is in progress. |
The Logout NACK Message is sent from the Server to the Client to tell the Client that the logout has not been accepted, possibly because something related to the RP entity, for example, combat is in progress. |
||
It has no params. |
It has no params. |
||
==Message C2S Action== |
===Message C2S Action=== |
||
The Action message is sent from the Client to the Server to notify the Server of the Clients desire to execute an action. The message is simply composed of a single action. |
The Action message is sent from the Client to the Server to notify the Server of the Clients desire to execute an action. The message is simply composed of a single action. |
||
==Message S2C Action ACK== |
===Message S2C Action ACK=== |
||
The Action ACK is sent from the Server to the Client to identify that the action has been received in the Server. It doesn't acknowledge that the action has been accepted by the RP Manager, it just means that the action successfully arrived at the Server. |
The Action ACK is sent from the Server to the Client to identify that the action has been received in the Server. It doesn't acknowledge that the action has been accepted by the RP Manager, it just means that the action successfully arrived at the Server. |
||
It has 1 param: action_id - is used to identify to which action you referred. In Marauroa you can command several actions per turn. |
It has 1 param: action_id - is used to identify to which action you referred. In Marauroa you can command several actions per turn. |
||
==Message S2C Perception== |
===Message S2C Perception=== |
||
The Perception message is a message sent from the Server to the Client to notify the Client about changes to the objects that exist near it. The message is based on the idea explained in the [[RolePlayingDesign#Perceptions| Delta Perception document]]. |
The Perception message is a message sent from the Server to the Client to notify the Client about changes to the objects that exist near it. The message is based on the idea explained in the [[RolePlayingDesign#Perceptions| Delta Perception document]]. |
||
| Line 242: | Line 243: | ||
Read the Delta perception algorithm to understand what it is for. |
Read the Delta perception algorithm to understand what it is for. |
||
==Message C2S Perception ACK== |
===Message C2S Perception ACK=== |
||
The perception ACK message is sent from the Client to the Server. We use this message to inform the Server that the Client is still there and listening. It has no params. |
The perception ACK message is sent from the Client to the Server. We use this message to inform the Server that the Client is still there and listening. It has no params. |
||
==Message S2C TransferREQ== |
===Message S2C TransferREQ=== |
||
The TransferREQ message is a message sent from the Server to the Client to notify the Client of the server's desire to send content useful for game play. |
The TransferREQ message is a message sent from the Server to the Client to notify the Client of the server's desire to send content useful for game play. |
||
The message is composed of: An array of TransferContent objects containing the name of each resource, its timestamp (or checksum) and if the resource is cacheable or not. |
The message is composed of: An array of TransferContent objects containing the name of each resource, its timestamp (or checksum) and if the resource is cacheable or not. |
||
==Message C2S TransferACK== |
===Message C2S TransferACK=== |
||
The TransferACK message is a message sent from the Client to the Server to notify the Server about what of the given TransferContent elements recieved from TransferREQ should be sent. |
The TransferACK message is a message sent from the Client to the Server to notify the Server about what of the given TransferContent elements recieved from TransferREQ should be sent. |
||
The message is composed of: An array of TransferContent objects containing all the name of each resource and a flag indicating ack or not. |
The message is composed of: An array of TransferContent objects containing all the name of each resource and a flag indicating ack or not. |
||
==Message S2C Transfer== |
===Message S2C Transfer=== |
||
The Transfer message is a message sent from the Server to the Client to send the Client content useful for the game where play will happen. |
The Transfer message is a message sent from the Server to the Client to send the Client content useful for the game where play will happen. |
||
The message is composed of: An array of TransferContent objects containing all the name of each resource, its timestamp, a flag indicating if the resource is cacheable or not and a byte array with the content itself. |
The message is composed of: An array of TransferContent objects containing all the name of each resource, its timestamp, a flag indicating if the resource is cacheable or not and a byte array with the content itself. |
||
= Versioning and port numbering = |
|||
A problem arises when we need to have two versions of Marauroa on the same machine. This happens for example when you run a release version and a development version on the same machine. |
|||
So to avoid port collisions we will use different ports for each release. The release version will run on the standard game port bu the development version will run on the (standard game port)*10 |
|||
For example: |
|||
release version of gladiators runs at 3214 |
|||
development version runs at 32140 |
|||
To allow different servers of Marauroa to run on the same machine running different games we will assign an unique port number to each game. |
|||
* gladiators runs at 3214 |
|||
* mapacman runs at 3215 |
|||
* stendhal runs at 3216 |
|||
Feel free to follow or disgregard these port rules if you wish. They may not apply to you. |
|||
[[Category:Marauroa]] |
[[Category:Marauroa]] |
||