Inside the 'server' folder, run the following command:
> javac *java
Then:
> cd ..
> java server.Server
(to test) Create your jar file using the following command:
jar -cvfe server.jar *
When launching the Server using CLI, some arguments can be added. Possible args are:
-p [portNumber]
specifies the port where the server has to listen from-l [gridLength]
specifies the grid length-p [portNumber] -l [gridLength]
specifies both options-l [gridLength] -p [portNumber]
###TO BE ADDED
When launching the Client using CLI, some arguments can be added. Possible args are:
[server address]
(format: "127.0.0.1")[portNumber]
(from 1 to 65535)[server address] [portNumber]
The protocol is based on a simple request-response form. The message format is as follows:
REQUEST
CMD <space> MSG
RESPONSE
{
"cmd" : "...",
"msg" : "..."
}
the msg key can contain an object, for example on the HIT response:
{
"cmd" : "HIT",
"msg" :
{
"row" : "...",
"col" : "..."
}
}
where <space>
is a simple space, CMD
is the command, and MSG
is the request/response body (the msg
key is optional)
Create ship:
SET rrcclo
rr
is the row coordinate of the ship (2 char length)cc
is the column coordinate (2 char length)l
is the lenght of the ship (1 char length)o
is the orientation of the ship (1 char, H Horizontal, V Vertical)
Fire ship:
FIRE rrcc
rr
row coordinate (2 char length)cc
column coordinate (2 char length)
Delete ship:
DELETE rrcc
rr
row coordinate (2 char length)cc
column coordinate (2 char length)
Delete all ships:
RESET
[response is GRID [...]
]
Asks for grid infos:
GRID
This interrogates the server, which will respond with the corresponding infos (more in the responses)
Tells the server that the client has all the ships set and is ready to play:
READY
[ possible response are WAIT
or PLAY
or ERROR
]
the documentation is structured like:
CMD
MSG
WAIT
wait for opponent (to finish positioning ships)GRID
response for the aGRID
orRESET
requests.{ length: l, ships: [...] }
length
: size of the gridships
: is the ships array (of integers) of the ships left to position.
PLAY
game can begin (needs to be sent to all players)HIT
selected coordinates had a ship{ row: r, col: c }
MISS
selected coordinates were empty{ row: r, col: c }
SUNK
remote ship was fully hit, and then sunk. (the message contains the coordinates for the head of the ship + length and orientation){ row: r, col: c, length: l, orientation: "..." }
TURN
- msg:
false
opponent's turn - msg:
true
your turn
- msg:
LOST
you lost the gameWON
you won the gameERROR
{ cod: "...", msg: "..." }
cod
: error status codemsg
: error message
OK
successful command
format: abb
the first digit (a) is the category, while the other digits (bb) represent the error itself
00
Invalid ship position01
Selected ship size not available02
Selected tile doesn't contain a ship03
READY command not valid, you still have ships remaining04
Invalid Orientation (Select H or V)
00
Invalid message01
Selected coordinates invalid02
Connection error