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