[BACK]Return to README.protocol CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / games / hunt

File: [cvs.NetBSD.org] / src / games / hunt / README.protocol (download)

Revision 1.1, Sat Jul 4 05:06:06 2009 UTC (12 years, 5 months ago) by dholland
Branch: MAIN
CVS Tags: yamt-pagecache-tag8, yamt-pagecache-base9, yamt-pagecache-base8, yamt-pagecache-base7, yamt-pagecache-base6, yamt-pagecache-base5, yamt-pagecache-base4, yamt-pagecache-base3, yamt-pagecache-base2, yamt-pagecache-base, yamt-pagecache, tls-maxphys-base, tls-maxphys, tls-earlyentropy-base, tls-earlyentropy, riastradh-xf86-video-intel-2-7-1-pre-2-21-15, riastradh-drm2-base3, riastradh-drm2-base2, riastradh-drm2-base1, riastradh-drm2-base, riastradh-drm2, prg-localcount2-base3, prg-localcount2-base2, prg-localcount2-base1, prg-localcount2-base, prg-localcount2, phil-wifi-base, phil-wifi-20200421, phil-wifi-20200411, phil-wifi-20200406, phil-wifi-20191119, phil-wifi-20190609, phil-wifi, pgoyette-localcount-base, pgoyette-localcount-20170426, pgoyette-localcount-20170320, pgoyette-localcount-20170107, pgoyette-localcount-20161104, pgoyette-localcount-20160806, pgoyette-localcount-20160726, pgoyette-localcount, pgoyette-compat-merge-20190127, pgoyette-compat-base, pgoyette-compat-20190127, pgoyette-compat-20190118, pgoyette-compat-1226, pgoyette-compat-1126, pgoyette-compat-1020, pgoyette-compat-0930, pgoyette-compat-0906, pgoyette-compat-0728, pgoyette-compat-0625, pgoyette-compat-0521, pgoyette-compat-0502, pgoyette-compat-0422, pgoyette-compat-0415, pgoyette-compat-0407, pgoyette-compat-0330, pgoyette-compat-0322, pgoyette-compat-0315, pgoyette-compat, perseant-stdc-iso10646-base, perseant-stdc-iso10646, netbsd-9-base, netbsd-9-2-RELEASE, netbsd-9-1-RELEASE, netbsd-9-0-RELEASE, netbsd-9-0-RC2, netbsd-9-0-RC1, netbsd-9, netbsd-8-base, netbsd-8-2-RELEASE, netbsd-8-1-RELEASE, netbsd-8-1-RC1, netbsd-8-0-RELEASE, netbsd-8-0-RC2, netbsd-8-0-RC1, netbsd-8, netbsd-7-nhusb-base-20170116, netbsd-7-nhusb-base, netbsd-7-nhusb, netbsd-7-base, netbsd-7-2-RELEASE, netbsd-7-1-RELEASE, netbsd-7-1-RC2, netbsd-7-1-RC1, netbsd-7-1-2-RELEASE, netbsd-7-1-1-RELEASE, netbsd-7-1, netbsd-7-0-RELEASE, netbsd-7-0-RC3, netbsd-7-0-RC2, netbsd-7-0-RC1, netbsd-7-0-2-RELEASE, netbsd-7-0-1-RELEASE, netbsd-7-0, netbsd-7, netbsd-6-base, netbsd-6-1-RELEASE, netbsd-6-1-RC4, netbsd-6-1-RC3, netbsd-6-1-RC2, netbsd-6-1-RC1, netbsd-6-1-5-RELEASE, netbsd-6-1-4-RELEASE, netbsd-6-1-3-RELEASE, netbsd-6-1-2-RELEASE, netbsd-6-1-1-RELEASE, netbsd-6-1, netbsd-6-0-RELEASE, netbsd-6-0-RC2, netbsd-6-0-RC1, netbsd-6-0-6-RELEASE, netbsd-6-0-5-RELEASE, netbsd-6-0-4-RELEASE, netbsd-6-0-3-RELEASE, netbsd-6-0-2-RELEASE, netbsd-6-0-1-RELEASE, netbsd-6-0, netbsd-6, matt-premerge-20091211, matt-nb8-mediatek-base, matt-nb8-mediatek, matt-nb6-plus-nbase, matt-nb6-plus-base, matt-nb6-plus, matt-mips64-premerge-20101231, localcount-20160914, is-mlppp-base, is-mlppp, cjep_sun2x-base1, cjep_sun2x-base, cjep_sun2x, cjep_staticlib_x-base1, cjep_staticlib_x-base, cjep_staticlib_x, cherry-xenmp-base, cherry-xenmp, bouyer-socketcan-base1, bouyer-socketcan-base, bouyer-socketcan, bouyer-quota2-nbase, bouyer-quota2-base, bouyer-quota2, agc-symver-base, agc-symver, HEAD

Notes on the protocol used by hunt, from OpenBSD.

THE HUNT PROTOCOL
=================

These are some notes on the traditional INET protocol between hunt(6) and 
huntd(6) as divined from the source code.

(In the original hunt, AF_UNIX sockets were used, but they are not 
considered here.)

The game of hunt is played with one server and several clients. The clients
act as dumb 'graphics' clients in that they mostly only ever relay the
user's keystrokes to the server, and the server usually only ever sends
screen-drawing commands to the client. ie, the server does all the work.

The game server (huntd) listens on three different network ports which 
I'll refer to as W, S and P, described as follows:

	W	well known UDP port (26740, or 'udp/hunt' in netdb)
	S	statistics TCP port
	P	game play TCP port

The protocol on each port is different and are described separately in
the following sections.

Lines starting with "C:" and "S:" will indicate messages sent from the 
client (hunt) or server (huntd) respectively.

W - well known port
-------------------
	This server port is used only to query simple information about the 
	game such as the port numbers of the other two ports (S and P),
	and to find out how many players are still in the game.

	All datagrams sent to (and possibly from) this UDP port consist of 
	a single unsigned 16-bit integer, encoded in network byte order.

	Server response datagrams should be sent to the source address
	of the client request datagrams.

	It is not useful to run multiple hunt servers on the one host
	interface, each of which perhaps listen to the well known port and
	respond appropriately. This is because clients will not be able to
	disambiguate which game is which.

	It is reasonable (and expected) to have servers listen to a 
	broadcast or multicast network address and respond, since the
	clients can extract a particular server's network address from
	the reply packet's source field.

    Player port request

	A client requests the game play port P with the C_PLAYER message.
	This is useful for clients broadcasting for any available games. eg:
		
		C: {uint16: 0 (C_PLAYER)}
		S: {uint16: P (TCP port number for the game play port)}

	The TCP address of the game play port should be formed from the
	transmitted port number and the source address as received by
	the client.

    Monitor port request

	A client can request the game play port P with the C_MONITOR message.
	However, the server will NOT reply if there are no players in
	the game. This is useful for broadcasting for 'active' games. eg:

		C: {uint16: 1 (C_MONITOR)}
		S: {uint16: P (TCP port number for the game play port)}

    Message port request

	If the server receives the C_MESSAGE message it will
	respond with the number of players currently in its game, unless
	there are 0 players, in which case it remains silent. This
	is used when a player wishes to send a text message to all other
	players, but doesn't want to connect if the game is over. eg:

		C: {uint16: 2 (C_MESSAGE)}
		S: {uint16: n (positive number of players)}

    Statistics port request

	The server's statistics port is queried with the C_SCORES message.
	eg:

		C: {uint16: 3 (C_SCORES)}
		S: {uint16: S (TCP port number for the statistics port)}


S - statistics port
-------------------
	The statistics port accepts a TCP connection, and keeps
	it alive for long enough to send a text stream to the client.
	This text consists of the game statistics. Lines in the
	text message are terminated with the \n (LF) character. 

		C: <connect>
		S: <accept>
		S: {char[]: lines of text, each terminated with <LF>}
		S: <close>

	The client is not to send any data to the server with this
	connection.

P - game play port
------------------
	This port provides the TCP channel for the main game play between
	the client and the server.

	All integers are unsigned, 32-bit and in network byte order.
	All fixed sized octet strings are ASCII encoded, NUL terminated.

    Initial connection

	The initial setup protocol between the client and server is as follows.
	The client sends some of its own details, and then the server replies
	with the version number of the server (currently (uint32)-1).

		C: <connect>
		S: <accept>
		C: {uint32:   uid}
		C: {char[20]: name}
		C: {char[1]:  team}
		C: {uint32:   'enter status'}
		C: {char[20]: ttyname}
		C: {uint32:   'connect mode'}
		S: {uint32:   server version (-1)}

	If the 'connect mode' is C_MESSAGE (2) then the server will wait
	for a single packet (no longer than 1024 bytes) containing
	a text message to be displayed to all players. (The message is not
	nul-terminated.)

		C: {char[]:	client's witty message of abuse}
		S: <close>

	The only other valid 'connect mode's are C_MONITOR and C_PLAYER.
	The server will attempt to allocate a slot for the client. 
	If allocation fails, the server will reply immediately with 
	"Too many monitors\n" or "Too many players\n', e.g.:

		S: Too many players<LF>
		S: <close>

	The 'enter status' integer is one of the following:

		1 (Q_CLOAK)	the player wishes to enter cloaked
		2 (Q_FLY)	the player wishes to enter flying
		3 (Q_SCAN)	the player wishes to enter scanning

	Any other value indicates that the player wishes to enter in
	'normal' mode.

	A team value of 32 (space character) means no team, otherwise
	it is the ASCII value of a team's symbol.

	On successful allocation, the server will immediately enter the 
	following phase of the protocol.

    Game play protocol

	The client provides a thin 'graphical' client to the server, and
	only ever relays keystrokes typed by the user:

		C: {char[]:	user keystrokes}

	Each character must be sent by the client as soon as it is typed.


	The server only ever sends screen drawing commands to the client.
	The server assumes the initial state of the client is a clear
	80x24 screen with the cursor at the top left (position y=0, x=0)

	    Literal character	225 (ADDCH)

		S: {uint8: 225} {uint8: c}

		The client must draw the character with ASCII value c
		at the cursor position, then advance the cursor to the right.
		If the cursor goes past the rightmost column of the screen,
		it wraps, moving to the first column of the next line down.
		The cursor should never be advanced past the bottom row.

		(ADDCH is provided as an escape prefix.)

	    Cursor motion	237 (MOVE)

		S: {uint8: 237} {uint8: y} {uint8: x}

		The client must move its cursor to the absolute screen
		location y, x, where y=0 is the top of the screen and
		x=0 is the left of the screen.

	    Refresh screen	242 (REFRESH)

		S: {uint8: 242}

		This indicates to the client that a burst of screen
		drawing has ended. Typically the client will flush its
		own drawing output so that the user can see the results.

		Refreshing is the only time that the client must
		ensure that the user can see the current screen. (This
		is intended for use with curses' refresh() function.)

	    Clear to end of line 227 (CLRTOEOL)

		S: {uint8: 227}

		The client must replace all columns underneath and
		to the right of the cursor (on the one row) with 
		space characters. The cursor must not move.

	    End game		229 (ENDWIN)

		S: {uint8: 229} {uint8: 32}
		S,C: <close>

		S: {uint8: 229} {uint8: 236}
		S,C: <close>

		The client and server must immediately close the connection.
		The client should also refresh the screen.
		If the second octet is 236 (LAST_PLAYER), then 
		the client should give the user an opportunity to quickly 
		re-enter the game. Otherwise the client should quit.

	    Clear screen	195 (CLEAR)

		S: {uint8: 195}

		The client must erase all characters from the screen
		and move the cursor to the top left (x=0, y=0).

	    Redraw screen	210 (REDRAW)

		S: {uint8: 210}

		The client should attempt to re-draw its screen.

	    Audible bell	226 (BELL)

		S: {uint8: 226}

		The client should generate a short audible tone for
		the user.

	    Server ready	231 (READY)

		S: {uint8: 231} {uint8: n}

		The client must refresh its screen.

		The server indicates to the client that it has
		processed n of its characters in order, and is ready
		for more commands. This permits the client to 
		synchronise user actions with server responses if need be.

	    Characters other than the above.

		S: {uint8: c}

		The client must draw the character with ASCII value c
		in the same way as if it were preceded with ADDCH
		(see above).


David Leonard, 1999.

$OpenBSD: README.protocol,v 1.1 1999/12/12 14:51:03 d Exp $