| 1 |
=============================================================================== |
| 2 |
monopd API |
| 3 |
|
| 4 |
Revision: 0.10.4 |
| 5 |
|
| 6 |
Erik Bourget <[email protected]> |
| 7 |
Rob Kaper <[email protected]> |
| 8 |
Sylvain Rochet <[email protected]> |
| 9 |
=============================================================================== |
| 10 |
|
| 11 |
Contents |
| 12 |
|
| 13 |
1) Notes |
| 14 |
i. protocol notes |
| 15 |
ii. server introduction |
| 16 |
iii. contact information |
| 17 |
iv. generally active servers |
| 18 |
2) Client->Server Messages |
| 19 |
3) Server->Client Messages |
| 20 |
|
| 21 |
=============================================================================== |
| 22 |
1) Notes |
| 23 |
=============================================================================== |
| 24 |
|
| 25 |
i. protocol notes |
| 26 |
----------------- |
| 27 |
|
| 28 |
Commands from clients to the monopd server are in the form of a tiny message |
| 29 |
preceded by a dot and followed by a newline: |
| 30 |
|
| 31 |
.gn |
| 32 |
|
| 33 |
Messages from the server to clients are in XML form. An example: |
| 34 |
|
| 35 |
<monopd><playerupdate playerid="1" money="1420"/></monopd> |
| 36 |
|
| 37 |
All messages are complete and exclusive to the line they are sent on; a |
| 38 |
message such as |
| 39 |
|
| 40 |
<monopd> |
| 41 |
<gamelist> |
| 42 |
<game id="1" users="2"/> |
| 43 |
</gamelist> |
| 44 |
</monopd> |
| 45 |
|
| 46 |
should be parsed by clients as five separate (and all invalid) messages. |
| 47 |
|
| 48 |
<monopd><msg type="info" value="Rob throws a 6 and a 2."/></monopd> |
| 49 |
|
| 50 |
is thus one valid message. |
| 51 |
|
| 52 |
Further example messages in this document will however be wrapped using |
| 53 |
newlines, for readability. |
| 54 |
|
| 55 |
There have been complaints of monopd sending multiple root elements in one |
| 56 |
"document", but unless there's a bug somewhere, newline-separated messages |
| 57 |
themselves should not contain more than one root element. Please do treat data |
| 58 |
after a newline as a new document. Most modern network APIs provide methods |
| 59 |
such as canReadLine() and readLine() which are optimised for this usage. |
| 60 |
|
| 61 |
Not all fields of the XML messages are sent on every update; clients are to |
| 62 |
assume that anything not referred to is either undefined if there has been no |
| 63 |
previous mention of the attribute, or that it keeps the same value as the |
| 64 |
last update that included it set it to. These incremental updates decrease |
| 65 |
the amount of data sent over the network. |
| 66 |
|
| 67 |
The encoding of the protocol is UTF-8. |
| 68 |
|
| 69 |
ii. server introduction |
| 70 |
----------------------- |
| 71 |
|
| 72 |
The server identifies itself with an introductory XML message: |
| 73 |
|
| 74 |
<monopd><server host="string" version="string"/> |
| 75 |
|
| 76 |
The client must then complete the handshake by using the "set name" command: |
| 77 |
|
| 78 |
.n$1 |
| 79 |
|
| 80 |
$1 string Player name. |
| 81 |
|
| 82 |
Until this command has been sent, any data the client sends will be ignored. |
| 83 |
When the handshake is completed the server gives the client some connection |
| 84 |
info: |
| 85 |
|
| 86 |
<client playerid="26" cookie="26/32631782"/></monopd> |
| 87 |
|
| 88 |
Each client that connects to the server receives a unique playerid; this |
| 89 |
will be used as identifier in games and eventually together with the cookie |
| 90 |
field to support graceful reconnects after timeouts. |
| 91 |
|
| 92 |
iii. contact information |
| 93 |
------------------------ |
| 94 |
|
| 95 |
The monopd team uses the [email protected] mailinglist as its |
| 96 |
primary discussion forum. |
| 97 |
|
| 98 |
While this documentation ought to be complete and free of errors, there |
| 99 |
might be inconsistencies, missing entries or other problems you might |
| 100 |
experience when dealing with the protocol. Please do not hesitate to report |
| 101 |
any problems or ask for clarification when in doubt. |
| 102 |
|
| 103 |
iv. generally active servers |
| 104 |
--------------------------- |
| 105 |
|
| 106 |
A list of available monopd servers is available on the metaserver and can be |
| 107 |
used by clients to connect to dedicated servers on the Internet. |
| 108 |
|
| 109 |
Please read the file README.metaserver from the monopd distribution for |
| 110 |
more information. |
| 111 |
|
| 112 |
=============================================================================== |
| 113 |
2) client->server messages |
| 114 |
=============================================================================== |
| 115 |
|
| 116 |
The following is a list of supported client-server messages. |
| 117 |
|
| 118 |
$<number> refers to a value that should be supplied; i.e. for a command .xyz$1, |
| 119 |
the message .xyz14 would be a valid instance of the command to send to the |
| 120 |
server. |
| 121 |
|
| 122 |
- connection commands |
| 123 |
|
| 124 |
.R$1 : reconnect using cookie $1. |
| 125 |
|
| 126 |
- game commands |
| 127 |
|
| 128 |
.gn$1 : create a new game of optional type $1. monopd defaults to the |
| 129 |
Atlantic game type. |
| 130 |
.gl : request a game template list. |
| 131 |
.gj$1 : join game number $1. |
| 132 |
.gx : exit a game without disconnecting from the monopd server |
| 133 |
.gk$1 : the player listed as master for a game can use this to kick a |
| 134 |
player with playerid $1 from a game during configuration, back |
| 135 |
into the lounge |
| 136 |
.gu$1 : upgrade spectating player with playerid $1 to a real player. Only |
| 137 |
the master can do so. |
| 138 |
.gc$1:$2 : Make changes to the game configuration. $1 is the unique configId |
| 139 |
from a received configupdate and $2 is the new value for value, |
| 140 |
which can be string, int or bool depending on the type specificed |
| 141 |
in the configupdate. |
| 142 |
.gS$1 : Join game $1 as spectator. |
| 143 |
|
| 144 |
- trade commands |
| 145 |
|
| 146 |
.Tn$1 : Initiate a trade with player with playerid $1. |
| 147 |
.Tc$1:$2:$3 : Set target owner of card $2 to player $3 in trade $1. |
| 148 |
.Te$1:$2:$3 : Set target owner of estate $2 to player $3 in trade $1. |
| 149 |
.Tm$1:$2:$3:$4 : Player $2 gives $3 an amount of $4 as part of trade $1. |
| 150 |
.Ta$1:$2 : Accept current (revision $2) terms of trade with tradeid $1. |
| 151 |
.Tr$1 : Reject trade $1. |
| 152 |
|
| 153 |
- movement commands |
| 154 |
|
| 155 |
.r : roll dice for movement |
| 156 |
.E : end current turn |
| 157 |
.t$1 : confirm latest player movement to location $1. This is used |
| 158 |
for clients that animate token movement to let the daemon know |
| 159 |
when to give money for going across "Go". |
| 160 |
|
| 161 |
- debt settling commands |
| 162 |
|
| 163 |
.D : declare bankruptcy |
| 164 |
.p : pay off debts |
| 165 |
|
| 166 |
- estate management commands |
| 167 |
|
| 168 |
.eb : buy current estate |
| 169 |
.es$1 : sell estate with estateid $1 to bank |
| 170 |
.ea : auction current estate |
| 171 |
.hb$1 : buy a house on estate with estateid $1 |
| 172 |
.hs$1 : sell a house on estate with estateid $1 |
| 173 |
.em$1 : toggle mortgage on estate with estateid $1 |
| 174 |
|
| 175 |
- auction commands |
| 176 |
|
| 177 |
.ab$1:$2 : bid $2 dollars for auction with auctionid $1 |
| 178 |
|
| 179 |
- jail commands |
| 180 |
|
| 181 |
.jc : use get out of jail free card |
| 182 |
.jp : pay get out of jail fee |
| 183 |
.jr : attempt to roll doubles in jail |
| 184 |
|
| 185 |
- tax commands (only available when the tax dialog has been initialised) |
| 186 |
|
| 187 |
.T$ : pay static tax |
| 188 |
.T% : pay tax as percentage of assets |
| 189 |
|
| 190 |
- player management commands |
| 191 |
|
| 192 |
.pi$1 : set player image to $1 |
| 193 |
|
| 194 |
- game management commands |
| 195 |
|
| 196 |
.gn : start a new game |
| 197 |
.gl : request a list of open games |
| 198 |
.gj$1 : join game with gameid $1 |
| 199 |
.gd$1 : set current game description to $1 |
| 200 |
.gs : start current game |
| 201 |
|
| 202 |
- miscellaneous commands |
| 203 |
|
| 204 |
.d : disconnect from server |
| 205 |
.n : set name |
| 206 |
.f : request full update |
| 207 |
|
| 208 |
=============================================================================== |
| 209 |
3) server->client messages |
| 210 |
=============================================================================== |
| 211 |
|
| 212 |
While they won't come like this from the server, I've split some messages |
| 213 |
onto more than one line for readability. Each line of messages is enclosed |
| 214 |
by <monopd> and </monopd>. |
| 215 |
|
| 216 |
-------------------- |
| 217 |
|
| 218 |
<server host="$1" version="$2"/> |
| 219 |
|
| 220 |
Identifies the server, sent upon connection. |
| 221 |
|
| 222 |
-------------------- |
| 223 |
|
| 224 |
<client playerid="$1" cookie="$2"/> |
| 225 |
|
| 226 |
Gives the client a unique identification. |
| 227 |
|
| 228 |
-------------------- |
| 229 |
|
| 230 |
<msg type="string" playerid="int" author="string" value="string"/> |
| 231 |
|
| 232 |
Used for sending informative messages to clients. Possible types include |
| 233 |
chat, info, error. For chat messages, playerid and name of the chatting |
| 234 |
player are sent. |
| 235 |
|
| 236 |
-------------------- |
| 237 |
|
| 238 |
<display estateid="$1" text="$2" cleartext="bool" clearbuttons="bool"> |
| 239 |
<button command="$3" caption="$4" enabled="$5"> |
| 240 |
</display> |
| 241 |
|
| 242 |
Used for sending client estate landing and transaction messages to display. |
| 243 |
Text is the body text of the message (text of chance cards, transaction |
| 244 |
messages when purchasing/landing). In case this is a dialog that requires |
| 245 |
user input, buttons can be requested for display, including the |
| 246 |
corresponding response command (.e.g. button "pay x % tax" has command |
| 247 |
".T%"). |
| 248 |
|
| 249 |
If estateid is -1, clients should clear the display. |
| 250 |
|
| 251 |
-------------------- |
| 252 |
|
| 253 |
<playerupdate playerid="int" game="int" name="string" image="string" |
| 254 |
money="int" location="int" jailed="bool" directmove="bool" |
| 255 |
bankrupt="bool" hasturn="bool" can_roll="bool" can_buyestate="bool" |
| 256 |
host="string" spectator="bool" hasdebt="bool" canauction="bool" |
| 257 |
canusecard="bool" turnorder="int"/> |
| 258 |
|
| 259 |
Most of these are obvious. Directmove is a suggestion to clients whether |
| 260 |
they should animate tokens (or not, directmove is 1 for "go directly to |
| 261 |
jail"). Master is 1 or 0 depending on whether the player is the controlling |
| 262 |
player in a game and spectator indicates whether a player is participating |
| 263 |
in the game or just watching it. |
| 264 |
|
| 265 |
-------------------- |
| 266 |
|
| 267 |
<deleteplayer playerid="int"/> |
| 268 |
|
| 269 |
Delete a player object. |
| 270 |
|
| 271 |
-------------------- |
| 272 |
|
| 273 |
<estateupdate estateid="int" name="string" owner="int" houses="int" |
| 274 |
houseprice="int" sellhouseprice="int" mortgaged="bool" group="int" |
| 275 |
can_be_owned="bool" can_toggle_mortgage="bool" can_buy_houses="bool" |
| 276 |
can_sell_houses="bool" money="int" price="int" mortgageprice="int" |
| 277 |
unmortgageprice="int" color="#rrggbb" bgcolor="#rrggbb" rent0="int" |
| 278 |
rent1="int" rent2="int" rent3="int" rent4="int" rent5="int" /> |
| 279 |
|
| 280 |
Again, stuff is pretty self-explanatory. The "owner" attribute is set to |
| 281 |
the playerid of the estate's owner or -1 if unowned; group is the groupid of |
| 282 |
the group that the estate belongs to (or -1 if not part of a group). Money |
| 283 |
is only used for Free Parking; it indicates how much money will be received |
| 284 |
upon landing on an estate. Color and bgcolor are hexcodes, e.g. "#00ff00" |
| 285 |
|
| 286 |
-------------------- |
| 287 |
|
| 288 |
<cardupdate cardid="$1" title="$2" owner="$3"/> |
| 289 |
|
| 290 |
When a card is removed from the stack, all three attributes are shown: the |
| 291 |
unique id, a title to be used in client GUI and dialogs and the playerid of |
| 292 |
the owner. When trading and putting cards back on the stack only the cardid |
| 293 |
and owner (-1 when the card is on the stack) are sent. |
| 294 |
|
| 295 |
-------------------- |
| 296 |
|
| 297 |
<estategroupupdate groupid="int" name="string"/> |
| 298 |
|
| 299 |
groupid Unique group id. |
| 300 |
name Name of the group. |
| 301 |
|
| 302 |
-------------------- |
| 303 |
|
| 304 |
<tradeupdate type="$1" tradeid="$2" actor="$3" revision="int"> |
| 305 |
<tradeplayer playerid="$4" accept="$5"/> |
| 306 |
<tradecard cardid="$6" targetplayer="$7"/> |
| 307 |
<tradeestate estateid="$8" targetplayer="$9"/> |
| 308 |
<trademoney playerfrom="$10" playerto="$11" money="$12"> |
| 309 |
... |
| 310 |
</tradeupdate> |
| 311 |
|
| 312 |
Type can be either "new" for creating a new trade, or "completed" or |
| 313 |
"rejected", both deleting the trade as object. If missing, "edit" is |
| 314 |
assumed, for adding players and notifying whether they accept current |
| 315 |
proposal or including cards and estates (targetplayer is a playerid, or -1 |
| 316 |
when a component is removed, money objects are removed when money is 0), |
| 317 |
"accepted" (at which point the ownerships are being transferred). |
| 318 |
|
| 319 |
Actor is the playerid of the player initiating the trade or rejecting it. |
| 320 |
|
| 321 |
Tradeplayer's accept field denotes whether that player has agreed to the |
| 322 |
current terms of the trade; this is reset to 0 upon any change and must be |
| 323 |
re-accepted with a .Ta. |
| 324 |
|
| 325 |
-------------------- |
| 326 |
|
| 327 |
<auctionupdate auctionid="$1" actor="$2" estateid="$3" highbid="$4" |
| 328 |
highbidder="$5" status="$6"/> |
| 329 |
|
| 330 |
Actor is the playerid of the player auctioning the estate, estateid the |
| 331 |
estate being auctioned, highbid the higgest bid at the moment and status is |
| 332 |
is 0 for normal, 1 for "going once", 2 for "going twice", and 3 for "gone". |
| 333 |
|
| 334 |
Auctionupdate will probably be deprecated soon and merged into the <display> |
| 335 |
tag, as the actor is not of interest and the highest bid and bidder can also |
| 336 |
be shown as description for a display widget. |
| 337 |
|
| 338 |
-------------------- |
| 339 |
|
| 340 |
<gameupdate gameid="int" gametype="string" name="string" |
| 341 |
description="string" status="string" players="int" canbejoined="bool" |
| 342 |
canbewatched="bool" minplayers="int" maxplayers="int" master="int" |
| 343 |
turn="int"/> |
| 344 |
|
| 345 |
Gives clients information about games on the server. |
| 346 |
|
| 347 |
The description field is optional (and set with .gd). If gameid is -1, this |
| 348 |
is not an actual game which can be joined but a template for a new game. |
| 349 |
Master is -1 for no master (should not happen) or a player id indicating |
| 350 |
this player is the master for the game. Turn is the number of turns that |
| 351 |
players have done so far. |
| 352 |
|
| 353 |
Status can be: |
| 354 |
|
| 355 |
config - Clients should display the configuration widget if their |
| 356 |
player is in this game. Clients in the game selection |
| 357 |
phase should offer players the option to join this game, |
| 358 |
hooked to the .gj command. |
| 359 |
|
| 360 |
init - The client will retrieve the initial game data if its |
| 361 |
player is within the game. Other clients should disable |
| 362 |
joining this game (because canbejoined will turn to |
| 363 |
false, which also happens when players equals maxplayers). |
| 364 |
|
| 365 |
run - The game is running. Clients in it should display the game |
| 366 |
board. |
| 367 |
|
| 368 |
end - The game has ended. Clients in it should no longer offer |
| 369 |
game-related commands, but may still show the board and |
| 370 |
its info and can either disconnect or leave the game (and |
| 371 |
request a new gamelist). |
| 372 |
|
| 373 |
-------------------- |
| 374 |
|
| 375 |
<deletegame gameid="int"/> |
| 376 |
|
| 377 |
Delete a game object. |
| 378 |
|
| 379 |
-------------------- |
| 380 |
|
| 381 |
<configupdate configid="int" gameid="int" name="string" title="string" |
| 382 |
type="string" value="string|int|bool" edit="bool"/> |
| 383 |
|
| 384 |
Allows clients to view/configure options (editing might only be available |
| 385 |
before the game starts!). Each configuration option has its own unique ID |
| 386 |
during a game and can be edited by sending the .gc$1:$2 where $1 is the |
| 387 |
configId and $2 the new value, which can be string, int(eger) or bool(ean) |
| 388 |
as defined by type. Edit tells clients whether the master can edit this |
| 389 |
property. |
| 390 |
|
| 391 |
Note that this behavior changed from monopd versions prior to 0.9.0 where |
| 392 |
edit indicated whether the client itself could edit a property. Monopd will |
| 393 |
now send all clients edit=1 for properties that can be changed. It is |
| 394 |
assumed that clients will disable these items based on being the master |
| 395 |
player for a game or not. |
| 396 |
|
| 397 |
Configuration options may be sent globally in the future so clients can |
| 398 |
display current game configuration before joining a game. Clients are |
| 399 |
expected to filter on gameid attribute even if this doesn't seem necessary |
| 400 |
for now. |
| 401 |
|
| 402 |
-------------------- |
| 403 |
|
| 404 |
<update object="string" id="int"> |
| 405 |
<int key="string" value="int"/> |
| 406 |
<string key="string" value="string"/> |
| 407 |
</update> |
| 408 |
|
| 409 |
WARNING: Do not use yet! |
| 410 |
|
| 411 |
This is part of the new object wire protocol POSSIBLY to be used after |
| 412 |
monopd 1.0. At present, the code sending such messages is commented out in |
| 413 |
Git. |