]> git.cworth.org Git - ttt/blob - PROTOCOL
a97a176c5f7f87afbc4bedb050261007723d624a
[ttt] / PROTOCOL
1                  Ricochet Robots Game Protocol (RRGP)
2                            Version 0.1.2
3                              2003-5-31
4                 
5                   Keith Packard         Carl Worth
6                 keithp@keithp.com   carl@theworths.org
7
8 Introduction
9
10 RRGP is a network protocol for playing the Ricochet Robots game.  It permits
11 a single server to host multiple games with named participants.  The
12 protocol is designed so that people can play using only telnet, but it is
13 expected that graphical interfaces will be able to drive the protocol as
14 well.
15
16 RRGP borrows ideas from other network protocols like SMTP using a
17 synchronous command interface.
18
19 Document Conventions
20
21         All commands include a response (yeah, synchronous protocols are
22         bad.  tough)
23
24         <command> <args> 
25
26         ->
27
28         <response>
29
30         <response> is one of:
31
32         <command> <args>
33         ERROR <message>
34
35 1. Requests
36
37 1.1 Connection setup
38
39     The RRGP server has no well defined port; agreement on which port to
40     use must be done through some external mechanism.  Once connected,
41     the client must identify itself:
42     
43     HELO [<username>]
44     
45     ->
46     
47     HELO <servername> <username> <server-addr> <server-port>
48
49     If the client doesn't supply <username>, the server will compute
50     one and return it.
51
52     Possible errors: INVALIDNAME
53
54 1.2. Global commands
55
56     1.2.1 Listing available users
57
58         WHO
59
60         ->
61
62         WHO <username1> <games1> <username2> <games2> ...
63
64         lists connected users and the number of games they've won.
65
66     1.2.2. Listing available games
67
68         GAMES
69
70         ->
71
72         GAMES <game1> <game2> ...
73
74     1.2.3. Message
75
76         MESSAGE <text>
77
78         ->
79         
80         MESSAGE
81
82     1.2.4. Help
83
84         HELP { <command> }
85
86         Displays help.  If <command> is provided, displays more
87         detailed help on a specific command, otherwise displays an
88         overview of all commands.
89
90     1.2.5. Quit
91
92         QUIT
93
94         ->
95
96         QUIT
97
98     1.2.6. Version
99
100         VERSION <client-version-number>
101
102         ->
103
104         VERSION <server-version-number>
105
106         Negotiates version number between client and server.  The server
107         will respond with a version no higher than the client version
108         number, but it may be lower.  Version numbers are integers.
109
110         This document describes protocol version 1.
111
112 1.3. Game management commands
113
114     1.3.1. Listing players in a game
115
116         PLAYERS <game>
117
118         ->
119
120         PLAYERS <username1> <score1> <username2> <score2> ...
121
122         Possible errors: NOGAME
123
124     1.3.2. Listing watchers of a game
125
126         WATCHERS <game>
127
128         ->
129
130         WATCERS <username1> <username2> ...
131
132         Possible errors: NOGAME
133
134     1.3.3. Get game information
135
136         GAMEINFO <game>
137
138         ->
139
140         GAMEINFO <turn> <color> <shape> <state> <time> <bid> <active>
141
142         <turn> is a number from 1 to 17 indicating the current turn
143         <color> <shape> indicate the active piece
144         <state> is one of:
145                 new     Turn just started, no bids yet
146                 bid     Bidding opened.  <time> indicates time remaining,
147                         <bid> indicates the minimum bid
148                 show    Bidding closed and solution being demonstrated
149                         <active> indicates the person demonstrating
150                 done    Current turn is over.  Either a solution
151                         was demonstrated or the players have all
152                         given up trying to find a solution.
153         <time> is valid only in BID state, else it's 0
154         <bid> is valid in all but NEW state where it's 0
155         <active> is valid in SHOW state, else it's ""
156
157         Possible errors: NOGAME
158
159     1.3.4. Creating a new game
160
161         NEW <game-suggestion>
162
163         ->
164
165         NEW <game>
166
167     1.3.5. Joining an existing game
168
169         JOIN <game>
170
171         ->
172
173         JOIN
174
175         Possible errors: NOGAME
176
177     1.3.6. Watching an existing game
178
179         WATCH <game>
180
181         ->
182
183         WATCH
184
185         The client will monitor the game, but not be listed in the
186         userlist nor be allowed to make moves.
187
188         Possible errors: NOGAME
189
190     1.3.7. Dispose an empty game
191
192         DISPOSE <game>
193
194         ->
195
196         DISPOSE
197
198         Disposes <game> unless it still has players associated.
199
200         Possible errors: NOGAME NOTEMPTY
201
202 1.4. User information commands
203
204     1.4.1. Get user information
205     
206         USERINFO <username>
207     
208         ->
209     
210         USERINFO <game> <playing> <score> <bid>
211     
212         <game> is any currently associated game, else "".  If the user
213         is not associated with any game, the remaining fields are
214         false 0 0.
215         
216         <playing> is true if the user is playing and false if watching.
217     
218         <score> is a number from 0 to 17 indicating this players score
219     
220         <bid> is either "0" indicating no bid or a number indicating
221         the users minimum bid.
222             
223 1.5. In-game commands
224
225     1.5.1. Global game commands
226
227         1.5.1.1 Get the game contents
228     
229             SHOW
230     
231             ->
232     
233             SHOW <game-board>
234     
235             <game-board> is a quoted multi-line string containing an
236             diagram of the game contents, (an array of cells). A single
237             cell and its surrounding are indicated as:
238     
239              HHH 
240             VrcsV
241              HHH
242     
243             H = ' ' or '='
244             V = ' ' or '|'
245             r = '.' or <robot-color>  (one of 'r', 'g', 'b', or 'y')
246             c = '.' or <target-color> (one of 'r', 'g', 'b', or 'y')
247             s = '.' or <target-shape> (one of 'c', 's', 'o', or 't')
248     
249             The goal robot and target (color and shape) are indicated with
250             capital letters.
251     
252             For example:
253     
254             SHOW "
255              ===         
256             |R.. ... .gs 
257                          
258              byc|... .RT|
259              ===     === "
260     
261             R.. =       Red robot (goal robot)
262             .gs =       Green square target
263             byc =       Blue robot on yellow circle target
264             .RT =       Red triangle (goal target)
265     
266             Possible errors: NOTINGAME
267     
268         1.5.1.2. Next turn
269     
270             TURN
271     
272             ->
273     
274             TURN
275     
276             Advance the game to the next turn, (which will have a new
277             target square).  TURN is valid only when the game is in
278             the DONE state
279                     
280             Possible errors: NOTINGAME, NOTDONE
281     
282         1.5.1.3. Part
283     
284             PART
285     
286             ->
287     
288             PART
289     
290             Departs the current game
291     
292     1.5.2. Bidding commands 
293
294         1.5.2.1 Bid
295     
296             BID <number>
297     
298             ->
299     
300             BID
301     
302             Possible errors: NOTINGAME, NOTBIDDING, NOTNUMBER, NOTLOWER
303     
304         1.5.2.2. Revoke
305     
306             REVOKE
307     
308             ->
309     
310             REVOKE
311     
312             Possible errors: NOTINGAME, NOTBIDDING, NOBID
313     
314         1.5.2.3. Abandon
315     
316             ABANDON
317     
318             ->
319     
320             ABANDON
321     
322             Possible errors: NOTINGAME, NOTBIDDING
323     
324             Mark this user as having abandoned this turn.  If all users
325             abandon, then the game state is switched to DONE.
326
327         1.5.2.4. No more bids
328
329             NOBID
330
331             ->
332
333             NOBID
334
335             Possible errors: NOTINGAME, NOTBIDDING
336     
337             Mark this user as done bidding.  If all users NOBID, then
338             the game state is switched to SHOW.
339     
340     1.5.3. Solving commands
341
342         1.5.3.1. Move
343     
344             MOVE <color> <dir1> <dir2> ...
345     
346             ->
347     
348             MOVE <count>
349     
350             <color> is one of 'R', 'Y', 'G' or 'B', <dir> is one of 'N',
351             'E', 'S' or 'W'.
352     
353             Possible errors: NOTINGAME, NOTACTIVE, BLOCKED, TOOMANYMOVES
354     
355         1.5.3.2. Undo
356     
357             UNDO
358     
359             ->
360     
361             UNDO
362     
363             Undoes the last move
364     
365             Possible errors: NOTINGAME, NOTACTIVE
366     
367             XXX: Do we add another error code for no further undo?
368     
369         1.5.3.3. Reset
370     
371             RESET
372     
373             ->
374     
375             RESET
376     
377             Resets robot positions to that at the start of the turn.
378     
379             Possible errors: NOTINGAME, NOTACTIVE
380     
381         1.5.3.4. Pass the demonstration to the next lowest bidder
382     
383             PASS
384     
385             ->
386     
387             PASS
388     
389             Possible errors: NOTINGAME
390         
391 2. Asynchronous notification.  
392
393     The server will send notices to each user in a game whenever
394     there is a move. It will also send notices to every connected
395     client when additional people join or new games are
396     started. These are of the form:
397
398         NOTICE <notice-code> <args>
399
400     Game-specific notices are sent to users involved in the related
401     game, other notices are sent to all users.  Note that even the user
402     originating the notice receives a copy.
403
404 2.1. Global notices
405
406     These notices are sent to all connected clients
407
408     2.1.1. New users
409     
410         NOTICE USER <username>
411     
412     2.1.2. Disconnected user
413     
414         NOTICE QUIT <username>
415     
416     2.1.3. New games
417     
418         NOTICE GAME <game>
419     
420     2.1.4. Terminated games
421     
422         NOTICE DISPOSE <game>
423     
424     2.1.5. Message
425
426         NOTICE MESSAGE <username> <text>
427
428 2.2. Game notices
429
430     These notices are sent to all players and watchers in
431     the affected game
432
433     2.2.1. Global game notices
434
435         2.2.1.1. Board layout change
436
437             NOTICE BOARD <game-board>
438
439             The layout of the game board has changed. <game-board> is
440             formatted as in the reply to the SHOW request.
441         
442         2.2.1.2. Game state change
443         
444             NOTICE GAMESTATE <state>
445
446             Game state has changed to <state>.  <state> is one
447             of "NEW", "BID", "SHOW" or "DONE".
448
449         2.2.1.3. Next turn (game)
450
451             NOTICE TURN <color> <shape>
452
453             Note that the game state is implicitly changed to New
454
455         2.2.1.4. Next game (game)
456
457             NOTICE GAMEOVER
458
459         2.2.1.5. Join game (game)
460         
461             NOTICE JOIN <username>
462         
463         2.2.1.6. Watch game (game)
464         
465             NOTICE WATCH <username>
466         
467         2.2.1.7. User departed game (game)
468         
469             NOTICE PART <username>
470
471     2.2.2. Bid notices
472
473         Notices sent duing the bidding phase of a turn
474     
475         2.2.2.1. Bids (game)
476         
477             NOTICE BID <username> <number>
478         
479         2.2.2.2. Revoke (game)
480         
481             NOTICE REVOKE <username>
482
483             The specific user has revoked their bid. If there
484             are no other bids outstanding, the game state is
485             returned to New.
486         
487         2.2.2.3. Timer (game)
488         
489             NOTICE TIMER <seconds>
490     
491             Timer ticks are sent every 10 seconds after the first
492             bid has been made
493
494         2.2.2.4. Abandon request
495
496             NOTICE ABANDON <username>
497     
498             <username> has requested that the current turn be abandoned
499             before bidding has closed.  If all players make such
500             a request, the TURN command may be used to move to the next
501             turn.
502
503         2.2.2.5. Nobid request
504
505             NOTICE NOBID <username>
506
507             <username> has announced that they plan on making no more bids
508             in the current turn.  If all players make such a request,
509             the game moves to the SHOW state.
510
511    2.2.3. Solving notices
512
513         Notices sent during the solving phase of a turn
514                 
515         2.2.3.1. Select active player (game)
516
517             NOTICE ACTIVE <username> <bid>
518
519             Only the active player may move the robots
520
521         2.2.3.2. Move notice (game)
522
523             NOTICE MOVE <count> <color> <dir>
524
525         2.2.3.3. Undo (game)
526
527             NOTICE UNDO
528
529         2.2.3.4. Reset (game)
530
531             NOTICE RESET
532
533         2.2.3.5. Position (after move/undo/reset)
534
535             NOTICE POSITION <color> <x> <y>
536
537             The indicated robot has moved to the indicated position.
538             The board is 0-based with the origin in the upper left
539             corner.
540
541         2.2.3.6. Score (game)
542
543             NOTICE SCORE <username> <score>
544
545             The indicated user has demonstrated a solution and
546             received a point.
547
548 2.3. User notices
549
550      These notices are sent to a single user
551
552      2.3.1. Solving notices
553
554         Notices sent during the solving phase of a turn
555                 
556         2.3.1.1. Notify active player (user)
557
558             NOTICE ACTIVATE <bid>
559
560             Sent to the player which has just become active
561             
562 3. Errors
563
564     The following error codes may be returned.
565
566 3.1. Connection setup errors
567
568     These errors occur during connection setup.
569
570     3.1.1. No name set
571     
572         ERROR NONAMESET
573     
574         'helo' must be sent before any command other than 'quit'.
575     
576     3.1.2. Invalid name
577     
578         ERROR INVALIDNAME
579     
580         All names must be unique.
581
582         Possibly returned by: HELO
583
584 3.2. Command format errors
585
586     Errors caused by ill-formed commands
587     
588     3.2.1. Command
589     
590         ERROR COMMAND
591     
592         An invalid command was specified
593     
594     3.2.2. Syntax
595     
596         ERROR SYNTAX
597     
598         A syntax error was detected
599     
600     3.2.3. Not number
601     
602         ERROR NOTNUMBER
603     
604         A non-numeric value was supplied where a number was required
605         
606     3.2.4. Not color
607     
608         ERROR NOTCOLOR
609     
610         The color name specified in the command was invalid
611     
612     3.2.5. Not shape
613     
614         ERROR NOTSHAPE
615     
616         The shape name specified in the command was invalid
617     
618     3.2.6. Not direction
619     
620         ERROR NOTDIRECTION
621     
622         The direction name specified in the command was invalid
623
624 3.3. Global command errors.
625
626     There are no errors from any of the global commands
627
628 3.4. Game management errors.
629
630     Errors from game management commands
631     
632     3.3.1. No such game
633         
634         ERROR NOGAME
635         
636         A game name was provided that does not exist.
637         
638     3.3.2. Not empty
639         
640         ERROR NOTEMPTY
641         
642         DISPOSE was requested for a game with active players
643         
644 3.5. User information errors
645
646     3.5.1. No such user
647     
648         ERROR NOUSER
649
650         A user name was provided that does not exist.
651
652 3.6. In-game errors
653
654     3.6.1. Global game errors
655     
656         3.6.1.1. Not in game
657     
658             ERROR NOTINGAME
659     
660             A game playing command was made, but the user is not a
661             particpant of any game.
662     
663             Possibly returned by: SHOW, MOVE, RESET, UNDO, TURN, PASS,
664             MESSAGE.
665
666         3.6.1.2. Not playing
667
668             ERROR NOTPLAYING
669
670             A command was executed by a watching user that is
671             permitted only to players
672
673         3.6.1.3. Not done
674     
675             ERROR NOTDONE
676     
677             TURN was requested and the game is not in DONE state.
678     
679     3.6.2. Bidding errors 
680     
681         3.6.2.1. Not bidding
682
683             ERROR NOTBIDDING
684     
685             A bid was submitted after the bidding closed
686     
687             Possibly returned by: BID
688     
689         3.6.2.2. Not lower
690
691             ERROR NOTLOWER
692     
693             A bid was submitted that was higher than previous bid.
694     
695             Possibly returned by: BID
696     
697         3.6.2.3. No bid
698
699             ERROR NOBID
700     
701             A revoke was requested when no bid had been entered
702     
703             Possibly returned by: REVOKE
704             
705     3.6.3. Solving mode errors
706     
707         3.6.3.1. Not active
708
709             ERROR NOTACTIVE
710         
711             A move, undo or reset was submitted by other than the
712             active user.
713             
714             Possibly returned by: MOVE, RESET, UNDO
715         
716         3.6.3.2. Blocked
717         
718             ERROR BLOCKED
719         
720             The robot cannot move the requested direction.
721         
722             Possibly returned by: MOVE
723         
724         3.6.3.3. TOOMANYMOVES
725         
726             ERROR TOOMANYMOVES
727         
728             An attempt was made to make more moves than the users bid
729         
730             Possibly returned by: MOVE
731         
732