Dijous2 Pablo M. M. Internet-Draft Xavi M. L. Intended status: Informational Universitat de Barcelona February 2014 Domino's Protocol -- DP/0.1 Abstract Domino is a popular game which is played by many users. It's an easy game where you must position your tiles on a board and empty your hand following a set of rules. Table of Contents 1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.1 Basic Structure . . . . . . . . . . . . . . . . . . . . . . 2 2 DP Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . 3 2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . 3 2.2 Structure of Frame . . . . . . . . . . . . . . . . . . . . . 3 2.3 Model Structure of Commands . . . . . . . . . . . . . . . . 4 2.4 Commands . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.4.1 Client to Server . . . . . . . . . . . . . . . . . . . . 5 2.4.1.1 HELLO . . . . . . . . . . . . . . . . . . . . . . . 5 2.4.1.2 MOVEMENT / NO MOVEMENT CLIENT - M/NM C . . . . . . . 6 2.4.2 Server to Client . . . . . . . . . . . . . . . . . . . . 7 2.4.2.1 ERROR . . . . . . . . . . . . . . . . . . . . . . . 7 2.4.2.2 TILES . . . . . . . . . . . . . . . . . . . . . . . 8 2.4.2.3 MOVEMENT / NO MOVEMENT SERVER - M/NM S . . . . . . . 8 2.4.2.4 STEAL . . . . . . . . . . . . . . . . . . . . . . . 9 2.4.2.5 FINAL . . . . . . . . . . . . . . . . . . . . . . . 10 2.5 Command Syntax . . . . . . . . . . . . . . . . . . . . . . . 11 2.6 Examples DP . . . . . . . . . . . . . . . . . . . . . . . . 11 2.6.1 Terminology . . . . . . . . . . . . . . . . . . . . . . 11 2.6.2 Examples . . . . . . . . . . . . . . . . . . . . . . . . 12 3 References . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 14 Dijous2 [Page 1] Distributed computing University of Barcelona February 2014 1 Introduction Domino Protocol was designed by the students of Distributed computing at the 'Universitat de Barcelona'. This protocol define the messages shared betwen client and server in order to control a distributed game of Domino. This is a single-game focused protocol, multiple games and their scores are not expected. 1.1 Basic Structure Each message can be summarised as a request from the client, followed by a response from the server. The response can be a normal response of the request or an error message, all the possible errors are explained later. Client Server | | | | | message to server | |------------------------------------------------------------------>| | message to client / ERROR | |<------------------------------------------------------------------| | | | | | | Figure 1 Dijous2 [Page 2] Distributed computing University of Barcelona February 2014 2 DP Procedure 2.1 Introduction In this section we'll define all messages of the protocol. For each message we will see the request/response. 2.2 Structure of Frame A frame is compound of two parts, header and body, as shown in the following figure: +------------------------------------------------------------+ | | | | HEADER | BODY | | | | +------------------------------------------------------------+ Figure 2 Header size: 1 byte Body size: depends on the command Dijous2 [Page 3] Distributed computing University of Barcelona February 2014 2.3 Model Structure of Commands +---------------+ +---------------+ | _____ |----------------------->| | +-->| HELLO |--------+ | TILES | | | |<---+ | | | | +---------------+ | | +---------------+ | | V | | +---------------+ | | | |------+ | | | ERROR |<--+ | | | | | | | | | +---------------+ | | | | | V V | +---------------+ +---------------+ | | |------------->| ______ | | | M/NM S | | M/NM C |<--+ | | |<-------------| | | | +---------------+ +---------------+ | | | / | | | V / V | | +---------------+ / +---------------+ | | | |<---------/ | |___| +---| FINAL | | STEAL | | | | | +---------------+ +---------------+ Figure 3 This is the model for all commands where the first is 'HELLO' request which starts the game. As soon as game starts we've defined all possible request/response series as a states machine in the figure. Those commands which have a line on them are the requests, and the others are responses. Dijous2 [Page 4] Distributed computing University of Barcelona February 2014 2.4 Commands 2.4.1 Client to Server 2.4.1.1 HELLO This is the first request. Client must send this in order to start a new game. In this message we only need a header because we don't need any additional information. +----------+ | | | 0x01 | | | +----------+ Figure 4 Head information: 0x01 Frame length: 1 byte Example reference: 1 Dijous2 [Page 5] Distributed computing University of Barcelona February 2014 2.4.1.2 MOVEMENT / NO MOVEMENT CLIENT - M/NM C This command is used by the client to make a movement. A movement is defined by 3 ASCII bytes, at this point the client has two legal actions: throwing a piece, not thorwing a piece. In order to make a valid movement, pieces must be sent literally to fit the pieces on the table. Wich means that if we have "[3|2][2|1]" and we want to insert a piece in the left side we will need to send that piece as "[N|3]", or if we want to insert a piece in the right side we will have to send the piece as "[1|N]". If pieces sent doesn't fit this model the server will return an error of type 'Illegal Action'. +----------+-------------------------------------------+ | | | | 0x03 | movement | | | | +----------+-------------------------------------------+ Figure 5 Header information: 0x03 Body information: movement: movement of client definite in command syntax Frame length: 4 bytes Example reference: 2, 3, 4, 6 Dijous2 [Page 6] Distributed computing University of Barcelona February 2014 2.4.2 Server to Client 2.4.2.1 ERROR There are five different error types, each one of them has a unique identifier (errorid). All error frames will contain also a String defining the error, for example "Piece [N|M] doesn't fit [Q|R].". These messages can contain, as much, 140 characters. +----------+-----------+-------------------------------+ | | | | | 0x00 | errorid | errormsg | | | | | +----------+-----------+-------------------------------+ Figure 6 Head information: 0x00 Body information: errorid: error type (definited above) errormsg: not exceeding 140 characters message Frame length: 5 bytes + extension message Example reference: 5, 6 Types of errors: Syntax error: 0x00 Ilegal action: 0x01 Not enoguh resources: 0x02 Internal error server: 0x03 Undefined error: 0x04 Dijous2 [Page 7] Distributed computing University of Barcelona February 2014 2.4.2.2 TILES This frame is the one sent by the server with the starting tiles of the client, and who has the first turn. We first send 7 tiles, each one composed by two positive integers betwen 0 and 6. Afer that, two bytes are added as the first movement of the server. If client has the first movement the two bytes will be "NT". +----------+------------+-------------------------------+ | | | | | 0x02 | 7*tile | tile/'NT' | | | | | +----------+------------+-------------------------------+ Figure 7 Header information: 0x02 7*tile: group of 7 tiles tile/'NT': indicator of who starts the game Frame length: 17 bytes Example reference: 1 2.4.2.3 MOVEMENT / NO MOVEMENT SERVER - M/NM S The server response from a movement, is usually a frame with his own movement. This frame is similar to M/NM C frame, this frame includes the movement of the computer (movement) and the number of tiles remaining in its hand (restserver). +----------+-------------------+-------------------------------+ | | | | | 0x04 | movement | restserver | | | | | +----------+-------------------+-------------------------------+ Figure 8 Header information: 0x04 Body information: movement: movement of the server restserver: #tiles rest of the server Frame length: 8 bytes Example reference: 2, 3, 4 Dijous2 [Page 8] Distributed computing University of Barcelona February 2014 2.4.2.4 STEAL If the client can't place any tile in the table he will send a 'no movement' tile, so it will try to steal. The frame only contains the tile (tile) that has been stolen. This action will end the turn of the client just if there are no pieces left to steal. +----------+-----------+ | | | | 0x05 | tile | | | | +----------+-----------+ Figure 9 Header information: 0x05 Body information: tile: tile stolen Frame length: 3 bytes Example reference: 3 Dijous2 [Page 9] Distributed computing University of Barcelona February 2014 2.4.2.5 FINAL End of game frame, this will be sent when the game is over. It contains the winner, and the final score obtained by the server in case of draw. If draw +----------+------------+---------------+ | | | | | 0x06 | winner | scoreserver | | | | | +----------+------------+---------------+ Otherwise +----------+------------+ | | | | 0x06 | winner | | | | +----------+------------+ Figure 10 Header information: 0x06 Body information: winner: game winner scoreserver: server score Winner: Client: 0x00 Server: 0x01 Draw: 0x02 Frame length: 6 bytes / 2 bytes Example reference: 4 Dijous2 [Page 10] Distributed computing University of Barcelona February 2014 2.5 Command Syntax This is the command syntax (using ABNF notation) [1]. All commands that use character or character sequence should be represented in ASCII [2]. ;basic structures numdp = "0" / "1" / "2" / "3" / "4" / "5" / "6" digit = %x30-39 dir = "L" / "R" char = %x01-7F string = string char int = %x00-FFFF ;The order matters, it's the order as the tiles are put, ;without invert them. tile = numdp numdp movement = [tile dir] / "NT " errorid = %x00-04 ;This is the size of a character sequence. ;The size of this field is expressed in character sequence. ;For example: "5" to say "hello" ;In this case this sequence shouldn't exceed 140 characters ;So this should be three digits midamsg = 3*digit errormsg = midamsg string restserver = int winner = %x00-02 scoreserver = int 2.6 Examples DP 2.6.1 Terminology This is the terminology used in the next examples: C -> Client-DP S -> Server-DP | -> Visual separator " -> Used to represent character sequences 0x -> Hexadecimal number Dijous2 [Page 11] Distributed computing University of Barcelona February 2014 2.6.2 Examples ------------------------------------------------------------- Example of first connection Either start server: C: 0x01 S: 0x02 | "0" "6" "4" "3" "2" "1" "6" "5" "5" "5" "3" "2" "4" "1" | "6" "6" Or start client C: 0x01 S: 0x02 | "0" "6" "4" "3" "2" "1" "6" "5" "5" "5" "3" "2" "4" "1" | "NT" Example 1 ------------------------------------------------------------- ------------------------------------------------------------- Example of a normal movement C: 0x03 | "4" "3" "R" S: 0x04 | "3" "5" "R" | 0x0006 C: 0x03 | "5" "5" "R" S: 0x04 | "NT " | 0x0006 C: 0x03 | "1" "4" "L" S: 0x04 | "1" "1" "L" | 0x0005 Example 2 ------------------------------------------------------------- Dijous2 [Page 12] Distributed computing University of Barcelona February 2014 ------------------------------------------------------------- Example of steal a tile C: 0x03 | "NT " S: 0x05 | "2" "3" C: 0x03 | "NT " S: 0x05 | "1" "3" C: 0x03 | "3" "1" "R" S: 0x04 | "1" "6" "R" | 0x0004 Example 3 ------------------------------------------------------------- ------------------------------------------------------------- Example of end game Subexample 1 C: 0x03 | "3" "2" "R" S: 0x06 | 0x00 Subexample 2 C: 0x03 | "3" "2" "L" S: 0x04 | "5" "6" "R" | 0x0000 S: 0x06 | 0x01 Subexample 3 C: 0x03 | "NT " S: 0x04 | "NT " | 0x0002 S: 0x06 | 0x01 Subexample 4 C: 0x03 | "NT " S: 0x04 | "NT " | 0x0001 S: 0x06 | 0x02 | 0x0005 Example 4 ------------------------------------------------------------- Dijous2 [Page 13] Distributed computing University of Barcelona February 2014 ------------------------------------------------------------- Example of ilegal action C: 0x10 S: 0x00 | 0x01 | "024" | "This command don't exist" Example 5 ------------------------------------------------------------- ------------------------------------------------------------- Example of syntax error C: 0x03 | "10" "3" "L" S: 0x00 | 0x00 | "032" | "Number should be between 0 and 6" Example 6 ------------------------------------------------------------- 3 References [1] ABNF notation Augmented Backus-Naur Form (ABNF) is a metalanguage based on Backus-Naur Form (BNF),but consisting of its own syntax and derivation rules. Reference to RFC 5234. [2] ASCII ASCII is a character-encoding scheme originally based on the English alphabet that encodes 128 specified character (0-9, a-z, A-Z, basic puntuation symbols, code controls and blank space) into 7-bit binary integers. Authors' Addresses Xavi Moreno Liceras University of Barcelona EMail: xmorenli7@alumnes.ub.edu Pablo Martinez Martinez University of Barcelona EMail: pmartima22@alumnes.ub.edu Dijous2 [Page 14]