5 These are some notes on the traditional INET protocol between hunt(6) and
6 huntd(6) as divined from the source code.
8 (In the original hunt, AF_UNIX sockets were used, but they are not
11 The game of hunt is played with one server and several clients. The clients
12 act as dumb 'graphics' clients in that they mostly only ever relay the
13 user's keystrokes to the server, and the server usually only ever sends
14 screen-drawing commands to the client. ie, the server does all the work.
16 The game server (huntd) listens on three different network ports which
17 I'll refer to as W, S and P, described as follows:
19 W well known UDP port (26740, or 'udp/hunt' in netdb)
23 The protocol on each port is different and are described separately in
24 the following sections.
26 Lines starting with "C:" and "S:" will indicate messages sent from the
27 client (hunt) or server (huntd) respectively.
31 This server port is used only to query simple information about the
32 game such as the port numbers of the other two ports (S and P),
33 and to find out how many players are still in the game.
35 All datagrams sent to (and possibly from) this UDP port consist of
36 a single unsigned 16-bit integer, encoded in network byte order.
38 Server response datagrams should be sent to the source address
39 of the client request datagrams.
41 It is not useful to run multiple hunt servers on the one host
42 interface, each of which perhaps listen to the well known port and
43 respond appropriately. This is because clients will not be able to
44 disambiguate which game is which.
46 It is reasonable (and expected) to have servers listen to a
47 broadcast or multicast network address and respond, since the
48 clients can extract a particular server's network address from
49 the reply packet's source field.
53 A client requests the game play port P with the C_PLAYER message.
54 This is useful for clients broadcasting for any available games. eg:
56 C: {uint16: 0 (C_PLAYER)}
57 S: {uint16: P (TCP port number for the game play port)}
59 The TCP address of the game play port should be formed from the
60 transmitted port number and the source address as received by
65 A client can request the game play port P with the C_MONITOR message.
66 However, the server will NOT reply if there are no players in
67 the game. This is useful for broadcasting for 'active' games. eg:
69 C: {uint16: 1 (C_MONITOR)}
70 S: {uint16: P (TCP port number for the game play port)}
74 If the server receives the C_MESSAGE message it will
75 respond with the number of players currently in its game, unless
76 there are 0 players, in which case it remains silent. This
77 is used when a player wishes to send a text message to all other
78 players, but doesn't want to connect if the game is over. eg:
80 C: {uint16: 2 (C_MESSAGE)}
81 S: {uint16: n (positive number of players)}
83 Statistics port request
85 The server's statistics port is queried with the C_SCORES message.
88 C: {uint16: 3 (C_SCORES)}
89 S: {uint16: S (TCP port number for the statistics port)}
94 The statistics port accepts a TCP connection, and keeps
95 it alive for long enough to send a text stream to the client.
96 This text consists of the game statistics. Lines in the
97 text message are terminated with the \n (LF) character.
101 S: {char[]: lines of text, each terminated with <LF>}
104 The client is not to send any data to the server with this
109 This port provides the TCP channel for the main game play between
110 the client and the server.
112 All integers are unsigned, 32-bit and in network byte order.
113 All fixed sized octet strings are ASCII encoded, NUL terminated.
117 The initial setup protocol between the client and server is as follows.
118 The client sends some of its own details, and then the server replies
119 with the version number of the server (currently (uint32)-1).
126 C: {uint32: 'enter status'}
127 C: {char[20]: ttyname}
128 C: {uint32: 'connect mode'}
129 S: {uint32: server version (-1)}
131 If the 'connect mode' is C_MESSAGE (2) then the server will wait
132 for a single packet (no longer than 1024 bytes) containing
133 a text message to be displayed to all players. (The message is not
136 C: {char[]: client's witty message of abuse}
139 The only other valid 'connect mode's are C_MONITOR and C_PLAYER.
140 The server will attempt to allocate a slot for the client.
141 If allocation fails, the server will reply immediately with
142 "Too many monitors\n" or "Too many players\n', e.g.:
144 S: Too many players<LF>
147 The 'enter status' integer is one of the following:
149 1 (Q_CLOAK) the player wishes to enter cloaked
150 2 (Q_FLY) the player wishes to enter flying
151 3 (Q_SCAN) the player wishes to enter scanning
153 Any other value indicates that the player wishes to enter in
156 A team value of 32 (space character) means no team, otherwise
157 it is the ASCII value of a team's symbol.
159 On successful allocation, the server will immediately enter the
160 following phase of the protocol.
164 The client provides a thin 'graphical' client to the server, and
165 only ever relays keystrokes typed by the user:
167 C: {char[]: user keystrokes}
169 Each character must be sent by the client as soon as it is typed.
172 The server only ever sends screen drawing commands to the client.
173 The server assumes the initial state of the client is a clear
174 80x24 screen with the cursor at the top left (position y=0, x=0)
176 Literal character 225 (ADDCH)
178 S: {uint8: 225} {uint8: c}
180 The client must draw the character with ASCII value c
181 at the cursor position, then advance the cursor to the right.
182 If the cursor goes past the rightmost column of the screen,
183 it wraps, moving to the first column of the next line down.
184 The cursor should never be advanced past the bottom row.
186 (ADDCH is provided as an escape prefix.)
188 Cursor motion 237 (MOVE)
190 S: {uint8: 237} {uint8: y} {uint8: x}
192 The client must move its cursor to the absolute screen
193 location y, x, where y=0 is the top of the screen and
194 x=0 is the left of the screen.
196 Refresh screen 242 (REFRESH)
200 This indicates to the client that a burst of screen
201 drawing has ended. Typically the client will flush its
202 own drawing output so that the user can see the results.
204 Refreshing is the only time that the client must
205 ensure that the user can see the current screen. (This
206 is intended for use with curses' refresh() function.)
208 Clear to end of line 227 (CLRTOEOL)
212 The client must replace all columns underneath and
213 to the right of the cursor (on the one row) with
214 space characters. The cursor must not move.
216 End game 229 (ENDWIN)
218 S: {uint8: 229} {uint8: 32}
221 S: {uint8: 229} {uint8: 236}
224 The client and server must immediately close the connection.
225 The client should also refresh the screen.
226 If the second octet is 236 (LAST_PLAYER), then
227 the client should give the user an opportunity to quickly
228 re-enter the game. Otherwise the client should quit.
230 Clear screen 195 (CLEAR)
234 The client must erase all characters from the screen
235 and move the cursor to the top left (x=0, y=0).
237 Redraw screen 210 (REDRAW)
241 The client should attempt to re-draw its screen.
243 Audible bell 226 (BELL)
247 The client should generate a short audible tone for
250 Server ready 231 (READY)
252 S: {uint8: 231} {uint8: n}
254 The client must refresh its screen.
256 The server indicates to the client that it has
257 processed n of its characters in order, and is ready
258 for more commands. This permits the client to
259 synchronise user actions with server responses if need be.
261 Characters other than the above.
265 The client must draw the character with ASCII value c
266 in the same way as if it were preceded with ADDCH
272 $OpenBSD: README.protocol,v 1.1 1999/12/12 14:51:03 d Exp $
273 $DragonFly: src/games/hunt/README.protocol,v 1.1 2008/09/02 21:50:18 dillon Exp $