]> git.cworth.org Git - ttt/blob - PROTOCOL
be0f04d04a6b2a5640215c4622d366c672145c9b
[ttt] / PROTOCOL
1                      Tic-tac-toe Protocol (TTTP)
2                            Version 0.0.1
3                              2005-11-05
4                 
5        Carl Worth           Richard Worth           Kevin Worth
6    carl@theworths.org   richard@theworths.org   kevin@theworths.org
7
8 Introduction
9
10 TTTP is a network protocol for playing the game tic-tac-toe. 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 TTTP borrows heavily from RRGP (Ricochet Robot Game Protocol) by Keith
17 Packard and indirectly from other network protocols like SMTP using a
18 synchronous command interface.
19
20 Document Conventions
21
22         All commands include a response (yeah, synchronous protocols are
23         bad.  tough)
24
25         <command> <args> 
26
27         ->
28
29         <response>
30
31         <response> is one of:
32
33         <command> <args>
34         ERROR <error-code>
35
36 1. Requests
37
38 1.1. Connection setup
39
40     The TTTP server has no well defined port; agreement on which port to
41     use must be done through some external mechanism.  Once connected,
42     the client must identify itself:
43     
44     HELO <username>
45     
46     ->
47     
48     HELO <username> <server-addr> <server-port>
49
50     Possible errors: INVALID_NAME
51
52 1.2. Global commands
53
54     1.2.1. Listing available users
55
56         WHO
57
58         ->
59
60         WHO <username1> <username2> ...
61
62         Lists connected users.
63
64         Possible errors: NO_NAME_SET
65
66     1.2.2. STATISTICS
67
68         STATISTICS <username>
69
70         ->
71
72         STATISTICS <username> "
73         TICTACTOE WINS <wins>
74         "
75
76         Lists the statistics for the specified user.
77
78         Possible errors: NO_NAME_SET, NO_USER
79
80     1.2.3. Message
81
82         MESSAGE <text>
83
84         ->
85         
86         MESSAGE
87
88         Sends a message to all connected users. The text must be a
89         single token. Use a quoted-string to include spaces in the
90         message text.
91
92         Possible errors: NO_NAME_SET
93
94     1.2.4. Help
95
96         HELP { <command> }
97
98         ->
99
100         HELP { <command> } "
101         <overview or detailed help>
102         "
103
104         Displays help.  If <command> is provided, displays more
105         detailed help on a specific command, otherwise displays an
106         overview of all commands.
107
108     1.2.5. Quit
109
110         QUIT
111
112         ->
113
114         QUIT
115
116         Disconnects the client from the server.
117
118     1.2.6. Version
119
120         VERSION <client-version-number>
121
122         ->
123
124         VERSION <server-version-number>
125
126         Negotiates version number between client and server.  The server
127         will respond with a version no higher than the client version
128         number, but it may be lower.  Version numbers are integers.
129
130         This document describes protocol version 1.
131
132 1.3. Game management commands
133
134     1.3.1. Inviting a player to play a game
135
136         INVITE <username>
137
138         ->
139
140         INVITE
141
142         Possible errors: NO_USER, BUSY, NO_NAME_SET
143
144     1.3.2. Accepting an invitation
145
146         ACCEPT <username>
147
148         ->
149
150         ACCEPT
151
152         Possible errors: NO_NAME_SET
153
154 1.4. In-game commands
155
156     1.4.1. Get the game contents
157     
158         SHOW
159     
160         ->
161     
162         SHOW <game-board>
163     
164         <game-board> is a quoted multi-line string containing an
165         diagram of the tic-tac-toe board, which is a 3x3 array of
166         cells:
167     
168         c|c|c
169         c|c|c
170         c|c|c
171     
172         c = '_' for empty or 'X' or 'O' for a played space
173     
174         For example:
175     
176         SHOW "
177         _|X|O 
178         _|X|_
179         X|O|O"
180     
181         Possible errors: NOT_IN_GAME, NO_NAME_SET
182     
183     1.4.2. Part
184     
185         PART
186     
187         ->
188     
189         PART
190     
191         Departs the current game
192
193         Possible errors: NOT_IN_GAME, NO_NAME_SET
194     
195     1.4.3. Making a move
196
197         MOVE <number>
198     
199         ->
200     
201         MOVE
202
203         <number> indicates a number in the tic-tac-toe grid as
204         follows:
205
206         0|1|2
207         3|4|5
208         6|7|8
209     
210         Possible errors: NOT_IN_GAME, NOT_YOUR_MOVE, NOT_GRID, NO_NAME_SET
211     
212 2. Asynchronous notification.  
213
214     The server will send notices to each user in a game whenever
215     there is a move. It will also send notices to every connected
216     client when additional people join or new games are
217     started. These are of the form:
218
219         NOTICE <notice-code> <args>
220
221     Game-specific notices are sent to users involved in the related
222     game, other notices are sent to all users.  Note that even the user
223     originating the notice receives a copy.
224
225 2.1. Global notices
226
227     These notices are sent to all connected clients
228
229     2.1.1. New users
230     
231         NOTICE USER <username>
232     
233     2.1.2. Disconnected user
234     
235         NOTICE QUIT <username>
236     
237     2.1.3. Game invitation
238     
239         NOTICE INVITE <username>
240     
241     2.1.4. Terminated games
242     
243         NOTICE DISPOSE <game>
244     
245     2.1.5. Message
246
247         NOTICE MESSAGE <username> <text>
248
249         where <text> is a quoted-string. Quotes escaped with '\"'
250
251 2.2. Game notices
252
253     These notices are sent to all players and watchers in
254     the affected game
255
256     2.2.1. Global game notices
257
258         2.2.1.1. New game begins
259
260             NOTICE NEWGAME <username> <username>
261
262             The first username listed will go first
263
264         2.2.1.2. Game over, and winner
265
266             NOTICE GAMEOVER <outcome> <username>
267
268             <outcome> is either WON in which case <username> indicates
269             the winner or CATSGAME in which case <username> is "".
270
271     2.2.2. Move notices
272
273         2.2.2.1. Move
274         
275             NOTICE MOVE <username> <number>
276
277 3. Errors
278
279     The following error codes may be returned.
280
281 3.1. Connection setup errors
282
283     These errors occur during connection setup.
284
285     3.1.1. No name set
286     
287         ERROR NO_NAME_SET
288     
289         'helo' must be sent before any command other than 'help',
290         'version', 'quit'.
291
292         Possibly returned by: WHO MESSAGE INVITE ACCEPT SHOW PART MOVE
293     
294     3.1.2. Invalid name
295     
296         ERROR INVALID_NAME
297     
298         All names must be of non-zero length and must be unique.
299
300         Possibly returned by: HELO
301
302 3.2. Command format errors
303
304     Errors caused by ill-formed commands
305     
306     3.2.1. Command
307     
308         ERROR COMMAND
309     
310         An invalid command was specified
311     
312     3.2.2. Syntax
313     
314         ERROR SYNTAX
315     
316         A syntax error was detected
317     
318     3.2.3. Not number
319     
320         ERROR NOT_NUMBER
321     
322         A non-numeric value was supplied where a number was required
323         
324     3.2.4. Not a grid number
325     
326         ERROR NOT_GRID
327     
328         The number specified in the command was not a valid grid number
329     
330 3.3. Global command errors.
331
332     There are no errors from any of the global commands
333
334 3.4. Game management errors.
335
336     Errors from game management commands
337     
338     3.4.1. No such game
339         
340         ERROR NO_GAME
341         
342         A game name was provided that does not exist.
343         
344 3.5. User information errors
345
346     3.5.1. No such user
347     
348         ERROR NO_USER
349
350         A user name was provided that does not exist.
351
352 3.6. In-game errors
353
354     3.6.1. Global game errors
355     
356         3.6.1.1. Not in game
357     
358             ERROR NOT_IN_GAME
359     
360             A game playing command was made, but the user is not a
361             particpant of any game.
362     
363             Possibly returned by: MOVE
364
365         3.6.1.2. Not playing
366
367             ERROR NOT_PLAYING
368
369             A command was executed by a watching user that is
370             permitted only to players
371     
372     3.6.2. Moving errors 
373     
374         3.6.2.1. Not your turn
375
376             ERROR NOT_YOUR_TURN
377     
378             A move was submitted during the other player's turn
379
380             Possibly returned by: MOVE