xref: /dflybsd-src/games/hunt/README.protocol (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
186d7f5d3SJohn Marino
286d7f5d3SJohn MarinoTHE HUNT PROTOCOL
386d7f5d3SJohn Marino=================
486d7f5d3SJohn Marino
586d7f5d3SJohn MarinoThese are some notes on the traditional INET protocol between hunt(6) and
686d7f5d3SJohn Marinohuntd(6) as divined from the source code.
786d7f5d3SJohn Marino
886d7f5d3SJohn Marino(In the original hunt, AF_UNIX sockets were used, but they are not
986d7f5d3SJohn Marinoconsidered here.)
1086d7f5d3SJohn Marino
1186d7f5d3SJohn MarinoThe game of hunt is played with one server and several clients. The clients
1286d7f5d3SJohn Marinoact as dumb 'graphics' clients in that they mostly only ever relay the
1386d7f5d3SJohn Marinouser's keystrokes to the server, and the server usually only ever sends
1486d7f5d3SJohn Marinoscreen-drawing commands to the client. ie, the server does all the work.
1586d7f5d3SJohn Marino
1686d7f5d3SJohn MarinoThe game server (huntd) listens on three different network ports which
1786d7f5d3SJohn MarinoI'll refer to as W, S and P, described as follows:
1886d7f5d3SJohn Marino
1986d7f5d3SJohn Marino	W	well known UDP port (26740, or 'udp/hunt' in netdb)
2086d7f5d3SJohn Marino	S	statistics TCP port
2186d7f5d3SJohn Marino	P	game play TCP port
2286d7f5d3SJohn Marino
2386d7f5d3SJohn MarinoThe protocol on each port is different and are described separately in
2486d7f5d3SJohn Marinothe following sections.
2586d7f5d3SJohn Marino
2686d7f5d3SJohn MarinoLines starting with "C:" and "S:" will indicate messages sent from the
2786d7f5d3SJohn Marinoclient (hunt) or server (huntd) respectively.
2886d7f5d3SJohn Marino
2986d7f5d3SJohn MarinoW - well known port
3086d7f5d3SJohn Marino-------------------
3186d7f5d3SJohn Marino	This server port is used only to query simple information about the
3286d7f5d3SJohn Marino	game such as the port numbers of the other two ports (S and P),
3386d7f5d3SJohn Marino	and to find out how many players are still in the game.
3486d7f5d3SJohn Marino
3586d7f5d3SJohn Marino	All datagrams sent to (and possibly from) this UDP port consist of
3686d7f5d3SJohn Marino	a single unsigned 16-bit integer, encoded in network byte order.
3786d7f5d3SJohn Marino
3886d7f5d3SJohn Marino	Server response datagrams should be sent to the source address
3986d7f5d3SJohn Marino	of the client request datagrams.
4086d7f5d3SJohn Marino
4186d7f5d3SJohn Marino	It is not useful to run multiple hunt servers on the one host
4286d7f5d3SJohn Marino	interface, each of which perhaps listen to the well known port and
4386d7f5d3SJohn Marino	respond appropriately. This is because clients will not be able to
4486d7f5d3SJohn Marino	disambiguate which game is which.
4586d7f5d3SJohn Marino
4686d7f5d3SJohn Marino	It is reasonable (and expected) to have servers listen to a
4786d7f5d3SJohn Marino	broadcast or multicast network address and respond, since the
4886d7f5d3SJohn Marino	clients can extract a particular server's network address from
4986d7f5d3SJohn Marino	the reply packet's source field.
5086d7f5d3SJohn Marino
5186d7f5d3SJohn Marino    Player port request
5286d7f5d3SJohn Marino
5386d7f5d3SJohn Marino	A client requests the game play port P with the C_PLAYER message.
5486d7f5d3SJohn Marino	This is useful for clients broadcasting for any available games. eg:
5586d7f5d3SJohn Marino
5686d7f5d3SJohn Marino		C: {uint16: 0 (C_PLAYER)}
5786d7f5d3SJohn Marino		S: {uint16: P (TCP port number for the game play port)}
5886d7f5d3SJohn Marino
5986d7f5d3SJohn Marino	The TCP address of the game play port should be formed from the
6086d7f5d3SJohn Marino	transmitted port number and the source address as received by
6186d7f5d3SJohn Marino	the client.
6286d7f5d3SJohn Marino
6386d7f5d3SJohn Marino    Monitor port request
6486d7f5d3SJohn Marino
6586d7f5d3SJohn Marino	A client can request the game play port P with the C_MONITOR message.
6686d7f5d3SJohn Marino	However, the server will NOT reply if there are no players in
6786d7f5d3SJohn Marino	the game. This is useful for broadcasting for 'active' games. eg:
6886d7f5d3SJohn Marino
6986d7f5d3SJohn Marino		C: {uint16: 1 (C_MONITOR)}
7086d7f5d3SJohn Marino		S: {uint16: P (TCP port number for the game play port)}
7186d7f5d3SJohn Marino
7286d7f5d3SJohn Marino    Message port request
7386d7f5d3SJohn Marino
7486d7f5d3SJohn Marino	If the server receives the C_MESSAGE message it will
7586d7f5d3SJohn Marino	respond with the number of players currently in its game, unless
7686d7f5d3SJohn Marino	there are 0 players, in which case it remains silent. This
7786d7f5d3SJohn Marino	is used when a player wishes to send a text message to all other
7886d7f5d3SJohn Marino	players, but doesn't want to connect if the game is over. eg:
7986d7f5d3SJohn Marino
8086d7f5d3SJohn Marino		C: {uint16: 2 (C_MESSAGE)}
8186d7f5d3SJohn Marino		S: {uint16: n (positive number of players)}
8286d7f5d3SJohn Marino
8386d7f5d3SJohn Marino    Statistics port request
8486d7f5d3SJohn Marino
8586d7f5d3SJohn Marino	The server's statistics port is queried with the C_SCORES message.
8686d7f5d3SJohn Marino	eg:
8786d7f5d3SJohn Marino
8886d7f5d3SJohn Marino		C: {uint16: 3 (C_SCORES)}
8986d7f5d3SJohn Marino		S: {uint16: S (TCP port number for the statistics port)}
9086d7f5d3SJohn Marino
9186d7f5d3SJohn Marino
9286d7f5d3SJohn MarinoS - statistics port
9386d7f5d3SJohn Marino-------------------
9486d7f5d3SJohn Marino	The statistics port accepts a TCP connection, and keeps
9586d7f5d3SJohn Marino	it alive for long enough to send a text stream to the client.
9686d7f5d3SJohn Marino	This text consists of the game statistics. Lines in the
9786d7f5d3SJohn Marino	text message are terminated with the \n (LF) character.
9886d7f5d3SJohn Marino
9986d7f5d3SJohn Marino		C: <connect>
10086d7f5d3SJohn Marino		S: <accept>
10186d7f5d3SJohn Marino		S: {char[]: lines of text, each terminated with <LF>}
10286d7f5d3SJohn Marino		S: <close>
10386d7f5d3SJohn Marino
10486d7f5d3SJohn Marino	The client is not to send any data to the server with this
10586d7f5d3SJohn Marino	connection.
10686d7f5d3SJohn Marino
10786d7f5d3SJohn MarinoP - game play port
10886d7f5d3SJohn Marino------------------
10986d7f5d3SJohn Marino	This port provides the TCP channel for the main game play between
11086d7f5d3SJohn Marino	the client and the server.
11186d7f5d3SJohn Marino
11286d7f5d3SJohn Marino	All integers are unsigned, 32-bit and in network byte order.
11386d7f5d3SJohn Marino	All fixed sized octet strings are ASCII encoded, NUL terminated.
11486d7f5d3SJohn Marino
11586d7f5d3SJohn Marino    Initial connection
11686d7f5d3SJohn Marino
11786d7f5d3SJohn Marino	The initial setup protocol between the client and server is as follows.
11886d7f5d3SJohn Marino	The client sends some of its own details, and then the server replies
11986d7f5d3SJohn Marino	with the version number of the server (currently (uint32)-1).
12086d7f5d3SJohn Marino
12186d7f5d3SJohn Marino		C: <connect>
12286d7f5d3SJohn Marino		S: <accept>
12386d7f5d3SJohn Marino		C: {uint32:   uid}
12486d7f5d3SJohn Marino		C: {char[20]: name}
12586d7f5d3SJohn Marino		C: {char[1]:  team}
12686d7f5d3SJohn Marino		C: {uint32:   'enter status'}
12786d7f5d3SJohn Marino		C: {char[20]: ttyname}
12886d7f5d3SJohn Marino		C: {uint32:   'connect mode'}
12986d7f5d3SJohn Marino		S: {uint32:   server version (-1)}
13086d7f5d3SJohn Marino
13186d7f5d3SJohn Marino	If the 'connect mode' is C_MESSAGE (2) then the server will wait
13286d7f5d3SJohn Marino	for a single packet (no longer than 1024 bytes) containing
13386d7f5d3SJohn Marino	a text message to be displayed to all players. (The message is not
13486d7f5d3SJohn Marino	nul-terminated.)
13586d7f5d3SJohn Marino
13686d7f5d3SJohn Marino		C: {char[]:	client's witty message of abuse}
13786d7f5d3SJohn Marino		S: <close>
13886d7f5d3SJohn Marino
13986d7f5d3SJohn Marino	The only other valid 'connect mode's are C_MONITOR and C_PLAYER.
14086d7f5d3SJohn Marino	The server will attempt to allocate a slot for the client.
14186d7f5d3SJohn Marino	If allocation fails, the server will reply immediately with
14286d7f5d3SJohn Marino	"Too many monitors\n" or "Too many players\n', e.g.:
14386d7f5d3SJohn Marino
14486d7f5d3SJohn Marino		S: Too many players<LF>
14586d7f5d3SJohn Marino		S: <close>
14686d7f5d3SJohn Marino
14786d7f5d3SJohn Marino	The 'enter status' integer is one of the following:
14886d7f5d3SJohn Marino
14986d7f5d3SJohn Marino		1 (Q_CLOAK)	the player wishes to enter cloaked
15086d7f5d3SJohn Marino		2 (Q_FLY)	the player wishes to enter flying
15186d7f5d3SJohn Marino		3 (Q_SCAN)	the player wishes to enter scanning
15286d7f5d3SJohn Marino
15386d7f5d3SJohn Marino	Any other value indicates that the player wishes to enter in
15486d7f5d3SJohn Marino	'normal' mode.
15586d7f5d3SJohn Marino
15686d7f5d3SJohn Marino	A team value of 32 (space character) means no team, otherwise
15786d7f5d3SJohn Marino	it is the ASCII value of a team's symbol.
15886d7f5d3SJohn Marino
15986d7f5d3SJohn Marino	On successful allocation, the server will immediately enter the
16086d7f5d3SJohn Marino	following phase of the protocol.
16186d7f5d3SJohn Marino
16286d7f5d3SJohn Marino    Game play protocol
16386d7f5d3SJohn Marino
16486d7f5d3SJohn Marino	The client provides a thin 'graphical' client to the server, and
16586d7f5d3SJohn Marino	only ever relays keystrokes typed by the user:
16686d7f5d3SJohn Marino
16786d7f5d3SJohn Marino		C: {char[]:	user keystrokes}
16886d7f5d3SJohn Marino
16986d7f5d3SJohn Marino	Each character must be sent by the client as soon as it is typed.
17086d7f5d3SJohn Marino
17186d7f5d3SJohn Marino
17286d7f5d3SJohn Marino	The server only ever sends screen drawing commands to the client.
17386d7f5d3SJohn Marino	The server assumes the initial state of the client is a clear
17486d7f5d3SJohn Marino	80x24 screen with the cursor at the top left (position y=0, x=0)
17586d7f5d3SJohn Marino
17686d7f5d3SJohn Marino	    Literal character	225 (ADDCH)
17786d7f5d3SJohn Marino
17886d7f5d3SJohn Marino		S: {uint8: 225} {uint8: c}
17986d7f5d3SJohn Marino
18086d7f5d3SJohn Marino		The client must draw the character with ASCII value c
18186d7f5d3SJohn Marino		at the cursor position, then advance the cursor to the right.
18286d7f5d3SJohn Marino		If the cursor goes past the rightmost column of the screen,
18386d7f5d3SJohn Marino		it wraps, moving to the first column of the next line down.
18486d7f5d3SJohn Marino		The cursor should never be advanced past the bottom row.
18586d7f5d3SJohn Marino
18686d7f5d3SJohn Marino		(ADDCH is provided as an escape prefix.)
18786d7f5d3SJohn Marino
18886d7f5d3SJohn Marino	    Cursor motion	237 (MOVE)
18986d7f5d3SJohn Marino
19086d7f5d3SJohn Marino		S: {uint8: 237} {uint8: y} {uint8: x}
19186d7f5d3SJohn Marino
19286d7f5d3SJohn Marino		The client must move its cursor to the absolute screen
19386d7f5d3SJohn Marino		location y, x, where y=0 is the top of the screen and
19486d7f5d3SJohn Marino		x=0 is the left of the screen.
19586d7f5d3SJohn Marino
19686d7f5d3SJohn Marino	    Refresh screen	242 (REFRESH)
19786d7f5d3SJohn Marino
19886d7f5d3SJohn Marino		S: {uint8: 242}
19986d7f5d3SJohn Marino
20086d7f5d3SJohn Marino		This indicates to the client that a burst of screen
20186d7f5d3SJohn Marino		drawing has ended. Typically the client will flush its
20286d7f5d3SJohn Marino		own drawing output so that the user can see the results.
20386d7f5d3SJohn Marino
20486d7f5d3SJohn Marino		Refreshing is the only time that the client must
20586d7f5d3SJohn Marino		ensure that the user can see the current screen. (This
20686d7f5d3SJohn Marino		is intended for use with curses' refresh() function.)
20786d7f5d3SJohn Marino
20886d7f5d3SJohn Marino	    Clear to end of line 227 (CLRTOEOL)
20986d7f5d3SJohn Marino
21086d7f5d3SJohn Marino		S: {uint8: 227}
21186d7f5d3SJohn Marino
21286d7f5d3SJohn Marino		The client must replace all columns underneath and
21386d7f5d3SJohn Marino		to the right of the cursor (on the one row) with
21486d7f5d3SJohn Marino		space characters. The cursor must not move.
21586d7f5d3SJohn Marino
21686d7f5d3SJohn Marino	    End game		229 (ENDWIN)
21786d7f5d3SJohn Marino
21886d7f5d3SJohn Marino		S: {uint8: 229} {uint8: 32}
21986d7f5d3SJohn Marino		S,C: <close>
22086d7f5d3SJohn Marino
22186d7f5d3SJohn Marino		S: {uint8: 229} {uint8: 236}
22286d7f5d3SJohn Marino		S,C: <close>
22386d7f5d3SJohn Marino
22486d7f5d3SJohn Marino		The client and server must immediately close the connection.
22586d7f5d3SJohn Marino		The client should also refresh the screen.
22686d7f5d3SJohn Marino		If the second octet is 236 (LAST_PLAYER), then
22786d7f5d3SJohn Marino		the client should give the user an opportunity to quickly
22886d7f5d3SJohn Marino		re-enter the game. Otherwise the client should quit.
22986d7f5d3SJohn Marino
23086d7f5d3SJohn Marino	    Clear screen	195 (CLEAR)
23186d7f5d3SJohn Marino
23286d7f5d3SJohn Marino		S: {uint8: 195}
23386d7f5d3SJohn Marino
23486d7f5d3SJohn Marino		The client must erase all characters from the screen
23586d7f5d3SJohn Marino		and move the cursor to the top left (x=0, y=0).
23686d7f5d3SJohn Marino
23786d7f5d3SJohn Marino	    Redraw screen	210 (REDRAW)
23886d7f5d3SJohn Marino
23986d7f5d3SJohn Marino		S: {uint8: 210}
24086d7f5d3SJohn Marino
24186d7f5d3SJohn Marino		The client should attempt to re-draw its screen.
24286d7f5d3SJohn Marino
24386d7f5d3SJohn Marino	    Audible bell	226 (BELL)
24486d7f5d3SJohn Marino
24586d7f5d3SJohn Marino		S: {uint8: 226}
24686d7f5d3SJohn Marino
24786d7f5d3SJohn Marino		The client should generate a short audible tone for
24886d7f5d3SJohn Marino		the user.
24986d7f5d3SJohn Marino
25086d7f5d3SJohn Marino	    Server ready	231 (READY)
25186d7f5d3SJohn Marino
25286d7f5d3SJohn Marino		S: {uint8: 231} {uint8: n}
25386d7f5d3SJohn Marino
25486d7f5d3SJohn Marino		The client must refresh its screen.
25586d7f5d3SJohn Marino
25686d7f5d3SJohn Marino		The server indicates to the client that it has
25786d7f5d3SJohn Marino		processed n of its characters in order, and is ready
25886d7f5d3SJohn Marino		for more commands. This permits the client to
25986d7f5d3SJohn Marino		synchronise user actions with server responses if need be.
26086d7f5d3SJohn Marino
26186d7f5d3SJohn Marino	    Characters other than the above.
26286d7f5d3SJohn Marino
26386d7f5d3SJohn Marino		S: {uint8: c}
26486d7f5d3SJohn Marino
26586d7f5d3SJohn Marino		The client must draw the character with ASCII value c
26686d7f5d3SJohn Marino		in the same way as if it were preceded with ADDCH
26786d7f5d3SJohn Marino		(see above).
26886d7f5d3SJohn Marino
26986d7f5d3SJohn Marino
27086d7f5d3SJohn MarinoDavid Leonard, 1999.
27186d7f5d3SJohn Marino
27286d7f5d3SJohn Marino$OpenBSD: README.protocol,v 1.1 1999/12/12 14:51:03 d Exp $
27386d7f5d3SJohn Marino$DragonFly: src/games/hunt/README.protocol,v 1.1 2008/09/02 21:50:18 dillon Exp $
274