Game Protocol

From Wiki for iCub and Friends
Jump to: navigation, search
Nova-console.png

(This is taken from the YARP source, example/game/PROTOCOL.TXT)

NOVA

Nova is a multi-user maze game.

It is accessible via telnet or YARP.


Accessing NOVA via command-line YARP

Here we describe how to use the game via command-line YARP. Type:

 yarp rpc /game /player/USERNAME

(RPC stands for "Remote Procedure Call" - basically, that we wish to send messages and receive exactly one response for every message we send). You will get a response like:

 RPC connection to /game at tcp://10.0.0.11:8080 (connection name /player/USERNAME)

Then type:

 look

You will get a response like:

 Response: (look
 Response:   (map
 Response:     ":::::::::::::::::::::::"
 Response:     ": #   ##              :"
 Response:     ": #                   :"
 Response:     ": #####   #   #####   :"
 Response:     ": #       #       #   :"
 Response:     ": #   ######  #   ####:"
 Response:     ": #        Q      #   :"
 Response:     ": ##########  #####   :"
 Response:     ": #       #           :"
 Response:     ": #   #   #   ########:"
 Response:     ": #   #       #       :"
 Response:     ": #   ##              :"
 Response:     ":::::::::::::::::::::::")
 Response:   (players
 Response:     (/player/paulfitz (location 9 15) (life 6))
 Response: ))

Now type:

 go right

And look again:

 look

The map should have changed (if not, try another direction). Game commands include:

 look
 go left/right/up/down
 fire left/right/up/down
 say message...

The telnet section details the meaning of these commands. When using yarp rpc, commands do not need to be prefixed with the special tag "d" as they do in the basic telnet protocol.

You can receive all messages broadcast by the "say message..." command by doing the following in another terminal:

 yarp read ... /game

Accessing NOVA from code

As a starting point, you can compile the example code in the YARP repository here:

 example/game/minimal_client

The code in this directory contains the bare minimum needed to talk to the game server from C++. You can extend it yourself anyway you like. If you just want a slightly better interface to the game, try compiling:

 example/game/client

Accessing NOVA via telnet

Here we describe how to use the game via telnet.

First, you need to know where the game is running and how to reach it. You need the name/IP of the server the game is on, and the socket number it listens to.

Either ask someone or, if you have YARP, run:

 yarp name query /game

This will give a response like this:

 registration name /game ip 10.0.0.11 port 8080 type tcp
 *** end of message

You can then reach the game by typing:

 telnet 10.0.0.11 8080

(the IP number may be different).

login

The very first thing the client must do is send:

 CONNECT name

Server responds with:

 Welcome name

Note that there is no password, authentication, or sanity checking. This is a toy game :-). Please don't use names with any unusual characters, or whitespace.


logout

Client sends:

 q

Server responds by removing player from game and dropping connection.


gameplay

To actually do anything in the game, the client sends:

 d

The server then waits for a game command. Game commands include:

 look
 go left/right/up/down
 fire left/right/up/down
 say message...

look

To see a local view of the game map, the client sends:

 d
 look

The server responds with something like:

look (look

 (map
   ":::::::::::::::::::::::"
   ":#          O         :"
   ":#####   #   #####    :"
   ":#       #       #    :"
   ":#   ######  #   #### :"
   ":#               #    :"
   ":##########Q #####    :"
   ":#       #            :"
   ":#   #   #   ######## :"
   ":#   #       #        :"
   ":#   ##               :"
   ":#                    :"
   ":::::::::::::::::::::::")
 (players
   (bozo (location 10 16) (life 6))
   (madmoody (location 11 11) (life 6))
 )

)

There are two parts to this response. The first is the map, which give a summary of what is around the player, using a set of characters with the following meanings:

 :  -- edge of map
 #  -- immovable obstacle
 Q  -- the player, when alive
 O  -- other players when alive
 %  -- the player, when dead
 *  -- other players, when dead
 =  -- traces the path where someone fired; visible for a short time

The second part is a list of the visible players. The first player listed is always the player who issued the look command. Locations are given in global coordinates.

go

To move around map, the client sends:

 d
 go left (or: go right / go up / go down)

The server responds with

 ack [move] "move requested"

and will implement the move on the next game simulation step. The change in location will be visible in the map returned by "look".

fire

To fire at another player, the client sends

 d
 fire left (or: fire right / fire up / fire down)

The server responds with

 ack [fire] "fire requested"

and will implement the firing operation on the next game simulation step. If another player is close and in the line of fire, their "life" count will be reduced by one.

say

The game has a broadcast channel. To send to this channel, the client sends:

 d
 say the-message-text

The server responds with

 broadcast username the-message-text

The same response will be placed on the broadcast channel.