Sending and receiving messages

Once connected to the DCSS Webtiles, the game will send various messages and will expect some interactions.

Receiving messages

The first few messages that are received, before the user sends any commands, are the following:

{"msg": "ping"}
{"msg": "lobby_clear"}
{"msg": "lobby_complete"}

All messages received from DCSS webtiles will have the msg dictionary key. This will indicate what type of message it is. The above three are simply information about the connection and the state of the lobby. Other messages will have other keys for additional information. Once the lobby_complete message is received, DCSS is ready to receive the next commands. It will not send anything until a command is received.

Sending messages

All messages sent to DCSS Webtiles have to be in the JSON format. The most basic form are simple key presses, a “msg” key of type “input”, with a “text” key with the specified key(s).

For example, this will send the . (wait) key to DCSS Webtiles:

{"msg": "input", "text": "."}

It is also possible to send multiple keys, one after the other. This will send yes to DCSS Webtiles:

{"msg": "input", "text": "yes"}

There are also multiple ways to send some of the commands. For example, both of these will send the “tab” command:

{"msg": "input", "text": "\t"}
{"msg": "key", "keycode": 9}

Here is a table representing the keycodes for each special key. The dcss-api column is the way to address them while using dcss-api – (webtile.write_key("key_esc")).

Key dcss-api JSON message
CTRL + A “key_ctrl_a” {“msg”: “key”, “keycode”: 1}
CTRL + B “key_ctrl_b” {“msg”: “key”, “keycode”: 2}
CTRL + C “key_ctrl_c” {“msg”: “key”, “keycode”: 3}
CTRL + D “key_ctrl_d” {“msg”: “key”, “keycode”: 4}
CTRL + E “key_ctrl_e” {“msg”: “key”, “keycode”: 5}
CTRL + F “key_ctrl_f” {“msg”: “key”, “keycode”: 6}
CTRL + G “key_ctrl_g” {“msg”: “key”, “keycode”: 7}
CTRL + H “key_ctrl_h” {“msg”: “key”, “keycode”: 8}
CTRL + I “key_ctrl_i” {“msg”: “key”, “keycode”: 9}
CTRL + J “key_ctrl_j” {“msg”: “key”, “keycode”: 10}
CTRL + K “key_ctrl_k” {“msg”: “key”, “keycode”: 11}
CTRL + L “key_ctrl_l” {“msg”: “key”, “keycode”: 12}
CTRL + M “key_ctrl_m” {“msg”: “key”, “keycode”: 13}
CTRL + N “key_ctrl_n” {“msg”: “key”, “keycode”: 14}
CTRL + O “key_ctrl_o” {“msg”: “key”, “keycode”: 15}
CTRL + P “key_ctrl_p” {“msg”: “key”, “keycode”: 16}
CTRL + Q “key_ctrl_q” {“msg”: “key”, “keycode”: 17}
CTRL + R “key_ctrl_r” {“msg”: “key”, “keycode”: 18}
CTRL + S “key_ctrl_s” {“msg”: “key”, “keycode”: 19}
CTRL + T “key_ctrl_t” {“msg”: “key”, “keycode”: 20}
CTRL + U “key_ctrl_u” {“msg”: “key”, “keycode”: 21}
CTRL + V “key_ctrl_v” {“msg”: “key”, “keycode”: 22}
CTRL + W “key_ctrl_w” {“msg”: “key”, “keycode”: 23}
CTRL + X “key_ctrl_x” {“msg”: “key”, “keycode”: 24}
CTRL + Y “key_ctrl_y” {“msg”: “key”, “keycode”: 25}
CTRL + Z “key_ctrl_z” {“msg”: “key”, “keycode”: 26}
esc “key_esc” {“msg”: “key”, “keycode”: 27}
tab “key_tab” {“msg”: “key”, “keycode”: 9}
North “key_dir_n” {“msg”: “input”, “text”: “8”}
North East “key_dir_ne” {“msg”: “input”, “text”: “9”}
Est “key_dir_e” {“msg”: “input”, “text”: “6”}
South East “key_dir_se” {“msg”: “input”, “text”: “3”}
South “key_dir_s” {“msg”: “input”, “text”: “2”}
South West “key_dir_sw” {“msg”: “input”, “text”: “1”}
West “key_dir_w” {“msg”: “input”, “text”: “4”}
North West “key_dir_nw” {“msg”: “input”, “text”: “7”}
Down stairs “key_stair_down” {“msg”: “input”, “text”: “>”}
Up stairs “key_stair_up” {“msg”: “input”, “text”: “<”}
enter “key_enter” {“msg”: “input”, “text”: “}

There are a few special JSON messages that are accepted by the game, especially to navigate the lobby. The login and games page go over many of them in more details. Other ones, especially the admin and user commands, can be found here in the DCSS Webtiles code.