11.1Sdholland 21.1SdhollandTHE HUNT PROTOCOL 31.1Sdholland================= 41.1Sdholland 51.1SdhollandThese are some notes on the traditional INET protocol between hunt(6) and 61.1Sdhollandhuntd(6) as divined from the source code. 71.1Sdholland 81.1Sdholland(In the original hunt, AF_UNIX sockets were used, but they are not 91.1Sdhollandconsidered here.) 101.1Sdholland 111.1SdhollandThe game of hunt is played with one server and several clients. The clients 121.1Sdhollandact as dumb 'graphics' clients in that they mostly only ever relay the 131.1Sdhollanduser's keystrokes to the server, and the server usually only ever sends 141.1Sdhollandscreen-drawing commands to the client. ie, the server does all the work. 151.1Sdholland 161.1SdhollandThe game server (huntd) listens on three different network ports which 171.1SdhollandI'll refer to as W, S and P, described as follows: 181.1Sdholland 191.1Sdholland W well known UDP port (26740, or 'udp/hunt' in netdb) 201.1Sdholland S statistics TCP port 211.1Sdholland P game play TCP port 221.1Sdholland 231.1SdhollandThe protocol on each port is different and are described separately in 241.1Sdhollandthe following sections. 251.1Sdholland 261.1SdhollandLines starting with "C:" and "S:" will indicate messages sent from the 271.1Sdhollandclient (hunt) or server (huntd) respectively. 281.1Sdholland 291.1SdhollandW - well known port 301.1Sdholland------------------- 311.1Sdholland This server port is used only to query simple information about the 321.1Sdholland game such as the port numbers of the other two ports (S and P), 331.1Sdholland and to find out how many players are still in the game. 341.1Sdholland 351.1Sdholland All datagrams sent to (and possibly from) this UDP port consist of 361.1Sdholland a single unsigned 16-bit integer, encoded in network byte order. 371.1Sdholland 381.1Sdholland Server response datagrams should be sent to the source address 391.1Sdholland of the client request datagrams. 401.1Sdholland 411.1Sdholland It is not useful to run multiple hunt servers on the one host 421.1Sdholland interface, each of which perhaps listen to the well known port and 431.1Sdholland respond appropriately. This is because clients will not be able to 441.1Sdholland disambiguate which game is which. 451.1Sdholland 461.1Sdholland It is reasonable (and expected) to have servers listen to a 471.1Sdholland broadcast or multicast network address and respond, since the 481.1Sdholland clients can extract a particular server's network address from 491.1Sdholland the reply packet's source field. 501.1Sdholland 511.1Sdholland Player port request 521.1Sdholland 531.1Sdholland A client requests the game play port P with the C_PLAYER message. 541.1Sdholland This is useful for clients broadcasting for any available games. eg: 551.1Sdholland 561.1Sdholland C: {uint16: 0 (C_PLAYER)} 571.1Sdholland S: {uint16: P (TCP port number for the game play port)} 581.1Sdholland 591.1Sdholland The TCP address of the game play port should be formed from the 601.1Sdholland transmitted port number and the source address as received by 611.1Sdholland the client. 621.1Sdholland 631.1Sdholland Monitor port request 641.1Sdholland 651.1Sdholland A client can request the game play port P with the C_MONITOR message. 661.1Sdholland However, the server will NOT reply if there are no players in 671.1Sdholland the game. This is useful for broadcasting for 'active' games. eg: 681.1Sdholland 691.1Sdholland C: {uint16: 1 (C_MONITOR)} 701.1Sdholland S: {uint16: P (TCP port number for the game play port)} 711.1Sdholland 721.1Sdholland Message port request 731.1Sdholland 741.1Sdholland If the server receives the C_MESSAGE message it will 751.1Sdholland respond with the number of players currently in its game, unless 761.1Sdholland there are 0 players, in which case it remains silent. This 771.1Sdholland is used when a player wishes to send a text message to all other 781.1Sdholland players, but doesn't want to connect if the game is over. eg: 791.1Sdholland 801.1Sdholland C: {uint16: 2 (C_MESSAGE)} 811.1Sdholland S: {uint16: n (positive number of players)} 821.1Sdholland 831.1Sdholland Statistics port request 841.1Sdholland 851.1Sdholland The server's statistics port is queried with the C_SCORES message. 861.1Sdholland eg: 871.1Sdholland 881.1Sdholland C: {uint16: 3 (C_SCORES)} 891.1Sdholland S: {uint16: S (TCP port number for the statistics port)} 901.1Sdholland 911.1Sdholland 921.1SdhollandS - statistics port 931.1Sdholland------------------- 941.1Sdholland The statistics port accepts a TCP connection, and keeps 951.1Sdholland it alive for long enough to send a text stream to the client. 961.1Sdholland This text consists of the game statistics. Lines in the 971.1Sdholland text message are terminated with the \n (LF) character. 981.1Sdholland 991.1Sdholland C: <connect> 1001.1Sdholland S: <accept> 1011.1Sdholland S: {char[]: lines of text, each terminated with <LF>} 1021.1Sdholland S: <close> 1031.1Sdholland 1041.1Sdholland The client is not to send any data to the server with this 1051.1Sdholland connection. 1061.1Sdholland 1071.1SdhollandP - game play port 1081.1Sdholland------------------ 1091.1Sdholland This port provides the TCP channel for the main game play between 1101.1Sdholland the client and the server. 1111.1Sdholland 1121.1Sdholland All integers are unsigned, 32-bit and in network byte order. 1131.1Sdholland All fixed sized octet strings are ASCII encoded, NUL terminated. 1141.1Sdholland 1151.1Sdholland Initial connection 1161.1Sdholland 1171.1Sdholland The initial setup protocol between the client and server is as follows. 1181.1Sdholland The client sends some of its own details, and then the server replies 1191.1Sdholland with the version number of the server (currently (uint32)-1). 1201.1Sdholland 1211.1Sdholland C: <connect> 1221.1Sdholland S: <accept> 1231.1Sdholland C: {uint32: uid} 1241.1Sdholland C: {char[20]: name} 1251.1Sdholland C: {char[1]: team} 1261.1Sdholland C: {uint32: 'enter status'} 1271.1Sdholland C: {char[20]: ttyname} 1281.1Sdholland C: {uint32: 'connect mode'} 1291.1Sdholland S: {uint32: server version (-1)} 1301.1Sdholland 1311.1Sdholland If the 'connect mode' is C_MESSAGE (2) then the server will wait 1321.1Sdholland for a single packet (no longer than 1024 bytes) containing 1331.1Sdholland a text message to be displayed to all players. (The message is not 1341.1Sdholland nul-terminated.) 1351.1Sdholland 1361.1Sdholland C: {char[]: client's witty message of abuse} 1371.1Sdholland S: <close> 1381.1Sdholland 1391.1Sdholland The only other valid 'connect mode's are C_MONITOR and C_PLAYER. 1401.1Sdholland The server will attempt to allocate a slot for the client. 1411.1Sdholland If allocation fails, the server will reply immediately with 1421.1Sdholland "Too many monitors\n" or "Too many players\n', e.g.: 1431.1Sdholland 1441.1Sdholland S: Too many players<LF> 1451.1Sdholland S: <close> 1461.1Sdholland 1471.1Sdholland The 'enter status' integer is one of the following: 1481.1Sdholland 1491.1Sdholland 1 (Q_CLOAK) the player wishes to enter cloaked 1501.1Sdholland 2 (Q_FLY) the player wishes to enter flying 1511.1Sdholland 3 (Q_SCAN) the player wishes to enter scanning 1521.1Sdholland 1531.1Sdholland Any other value indicates that the player wishes to enter in 1541.1Sdholland 'normal' mode. 1551.1Sdholland 1561.1Sdholland A team value of 32 (space character) means no team, otherwise 1571.1Sdholland it is the ASCII value of a team's symbol. 1581.1Sdholland 1591.1Sdholland On successful allocation, the server will immediately enter the 1601.1Sdholland following phase of the protocol. 1611.1Sdholland 1621.1Sdholland Game play protocol 1631.1Sdholland 1641.1Sdholland The client provides a thin 'graphical' client to the server, and 1651.1Sdholland only ever relays keystrokes typed by the user: 1661.1Sdholland 1671.1Sdholland C: {char[]: user keystrokes} 1681.1Sdholland 1691.1Sdholland Each character must be sent by the client as soon as it is typed. 1701.1Sdholland 1711.1Sdholland 1721.1Sdholland The server only ever sends screen drawing commands to the client. 1731.1Sdholland The server assumes the initial state of the client is a clear 1741.1Sdholland 80x24 screen with the cursor at the top left (position y=0, x=0) 1751.1Sdholland 1761.1Sdholland Literal character 225 (ADDCH) 1771.1Sdholland 1781.1Sdholland S: {uint8: 225} {uint8: c} 1791.1Sdholland 1801.1Sdholland The client must draw the character with ASCII value c 1811.1Sdholland at the cursor position, then advance the cursor to the right. 1821.1Sdholland If the cursor goes past the rightmost column of the screen, 1831.1Sdholland it wraps, moving to the first column of the next line down. 1841.1Sdholland The cursor should never be advanced past the bottom row. 1851.1Sdholland 1861.1Sdholland (ADDCH is provided as an escape prefix.) 1871.1Sdholland 1881.1Sdholland Cursor motion 237 (MOVE) 1891.1Sdholland 1901.1Sdholland S: {uint8: 237} {uint8: y} {uint8: x} 1911.1Sdholland 1921.1Sdholland The client must move its cursor to the absolute screen 1931.1Sdholland location y, x, where y=0 is the top of the screen and 1941.1Sdholland x=0 is the left of the screen. 1951.1Sdholland 1961.1Sdholland Refresh screen 242 (REFRESH) 1971.1Sdholland 1981.1Sdholland S: {uint8: 242} 1991.1Sdholland 2001.1Sdholland This indicates to the client that a burst of screen 2011.1Sdholland drawing has ended. Typically the client will flush its 2021.1Sdholland own drawing output so that the user can see the results. 2031.1Sdholland 2041.1Sdholland Refreshing is the only time that the client must 2051.1Sdholland ensure that the user can see the current screen. (This 2061.1Sdholland is intended for use with curses' refresh() function.) 2071.1Sdholland 2081.1Sdholland Clear to end of line 227 (CLRTOEOL) 2091.1Sdholland 2101.1Sdholland S: {uint8: 227} 2111.1Sdholland 2121.1Sdholland The client must replace all columns underneath and 2131.1Sdholland to the right of the cursor (on the one row) with 2141.1Sdholland space characters. The cursor must not move. 2151.1Sdholland 2161.1Sdholland End game 229 (ENDWIN) 2171.1Sdholland 2181.1Sdholland S: {uint8: 229} {uint8: 32} 2191.1Sdholland S,C: <close> 2201.1Sdholland 2211.1Sdholland S: {uint8: 229} {uint8: 236} 2221.1Sdholland S,C: <close> 2231.1Sdholland 2241.1Sdholland The client and server must immediately close the connection. 2251.1Sdholland The client should also refresh the screen. 2261.1Sdholland If the second octet is 236 (LAST_PLAYER), then 2271.1Sdholland the client should give the user an opportunity to quickly 2281.1Sdholland re-enter the game. Otherwise the client should quit. 2291.1Sdholland 2301.1Sdholland Clear screen 195 (CLEAR) 2311.1Sdholland 2321.1Sdholland S: {uint8: 195} 2331.1Sdholland 2341.1Sdholland The client must erase all characters from the screen 2351.1Sdholland and move the cursor to the top left (x=0, y=0). 2361.1Sdholland 2371.1Sdholland Redraw screen 210 (REDRAW) 2381.1Sdholland 2391.1Sdholland S: {uint8: 210} 2401.1Sdholland 2411.1Sdholland The client should attempt to re-draw its screen. 2421.1Sdholland 2431.1Sdholland Audible bell 226 (BELL) 2441.1Sdholland 2451.1Sdholland S: {uint8: 226} 2461.1Sdholland 2471.1Sdholland The client should generate a short audible tone for 2481.1Sdholland the user. 2491.1Sdholland 2501.1Sdholland Server ready 231 (READY) 2511.1Sdholland 2521.1Sdholland S: {uint8: 231} {uint8: n} 2531.1Sdholland 2541.1Sdholland The client must refresh its screen. 2551.1Sdholland 2561.1Sdholland The server indicates to the client that it has 2571.1Sdholland processed n of its characters in order, and is ready 2581.1Sdholland for more commands. This permits the client to 2591.1Sdholland synchronise user actions with server responses if need be. 2601.1Sdholland 2611.1Sdholland Characters other than the above. 2621.1Sdholland 2631.1Sdholland S: {uint8: c} 2641.1Sdholland 2651.1Sdholland The client must draw the character with ASCII value c 2661.1Sdholland in the same way as if it were preceded with ADDCH 2671.1Sdholland (see above). 2681.1Sdholland 2691.1Sdholland 2701.1SdhollandDavid Leonard, 1999. 2711.1Sdholland 2721.1Sdholland$OpenBSD: README.protocol,v 1.1 1999/12/12 14:51:03 d Exp $ 273