1 /* $Id: pack.h,v 5.4 2002/01/18 22:34:26 kimiko Exp $
2  *
3  * XPilot, a multiplayer gravity war game.  Copyright (C) 1991-2001 by
4  *
5  *      Bj�rn Stabell        <bjoern@xpilot.org>
6  *      Ken Ronny Schouten   <ken@xpilot.org>
7  *      Bert Gijsbers        <bert@xpilot.org>
8  *      Dick Balaska         <dick@xpilot.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  */
24 
25 #ifndef	PACK_H
26 #define	PACK_H
27 
28 #define CAP_LETTER(c)	((c) = ((c)>='a' && (c)<='z') ? (c)-'a'+'A' : (c))
29 
30 #define SERVER_PORT	15345		/* Port which server listens to. */
31 #define SERVER_PORT_STR	"15345"		/* ASCII version of server port. */
32 
33 /*
34  * Magic contact word.
35  * The low 16 bits are the real magic word.
36  * Bits 31-28 are the major version number.
37  * Bits 27-24 are the minor version number.
38  * Bits 23-20 are the patchlevel number.
39  * Bits 19-16 are free to mean beta release or so.
40  * These high bits only need to be changed when a new
41  * client can't talk to an old server or vise versa.
42  * Please don't change it more often than strictly necessary.
43  * PLEASE NOTE: if you make your own private incompatible changes
44  * justifying an increment of the version word then please
45  * set the 4th bit.  Like 0x3108 and 0x3109 till 0x310F, etc.
46  * This way we can use the lower 8 values for public releases.
47  *
48  * Reasons why it changed in the past:
49  * 3.0.1: rewrite of contact pack protocol, because of
50  * different structure layout rules on different architectures.
51  * 3.0.2: rewrite of setup transmit from server to client to
52  * make it possible for 64-bit machines and 32-bit machines
53  * to join in the same game.  This was the last hardcoded
54  * structure that was shared between client and server.
55  * 3.0.3: implemented a version awareness system, so that
56  * newer clients can join older servers and so that
57  * newer servers can support older clients.
58  * The client maintains a `version' variable indicating
59  * the version of the server it has joined and the server
60  * maintains for each connection a `connection_t->version'
61  * and a `player->version' variable.
62  * 3.0.4: the so-called `pizza-mode' introduced a new packet type.
63  * The score packet now also includes pl->mychar.
64  * 3.0.4.1: new laser weapon introduces another packet change.
65  * Because there is an unofficial (and forbidden) 3.0.4 version floating
66  * around the sub patchlevel number is used to distinguish versions.
67  * A new display packet to tell the server what the view sizes are
68  * and how many different debris intensities the client wants.
69  * 3.0.4.2: new player-self status byte in self packet.
70  * 3.0.4.3: different and incompatible laser packet.
71  * New eyes packet to tell the client through wich players eyes we're
72  * looking through in case the client is in game over move and it is locked
73  * on someone else.
74  * 3.1.0.0: new big patches implementing loads of new incompatible features.
75  * Major cleanup.  Old clients (before 310) can't join new servers anymore.
76  * 3.1.0.1: key-change-ids are now send as longs instead of bytes.
77  * 3.1.0.2: different player status byte.
78  * 3.1.0.3: different mine packet.
79  * 3.2.0.0: New ship shape definition and big patches.
80  * 3.2.0.1: Extended buffer for very large ship shape definitions.
81  * 3.2.0.2: New mouse pointer control packet.
82  * 3.2.5.0: Now client must ask for audio packets in order to get them.
83  * 3.2.6.0: New map update packet.
84  * 3.2.6.1: New player timing packet.
85  * 3.2.8.0: New asyn packet.
86  * 3.3.1.0: Different owner-only commands.
87  * 3.3.2.0: Map decorations.
88  * 3.4.0.0: Lose/drop item key.
89  * 3.5.0.0: Player waiting queue.
90  * 3.8.0.0: new items (deflector, hyperjump, phasing), keyboardsize and rounddelay.
91  * 4.1.0.0: new item (mirror).
92  * 4.2.0.0: new power/turnspeed behavior
93  * 4.2.0.1: new item (armor).
94  * 4.2.0.2: highest bit on in wreckagetype when deadly.
95  * 4.2.0.3: different way of sending player item info.
96  * 4.2.1.0: high bit in radar size means player is a teammate.
97  * 4.3.0.0: transmit phasing separately from cloaking
98  * 4.4.0.0: new object (asteroid)
99  * 4.4.0.1: fast radar packet
100  * 4.5.0.0: new team score packet; score packet made larger to send decimals
101  * 4.5.0.1: temporary wormholes
102  */
103 #define	MAGIC		0x4501F4ED
104 
105 #define MAGIC2VERSION(M)	(((M) >> 16) & 0xFFFF)
106 #define VERSION2MAGIC(V)	((((V) & 0xFFFF) << 16) | (MAGIC & 0xFFFF))
107 #define MY_VERSION		MAGIC2VERSION(MAGIC)
108 
109 /*
110  * Which client versions can join this server.
111  */
112 #define MIN_CLIENT_VERSION	0x3103
113 #define MAX_CLIENT_VERSION	MY_VERSION
114 
115 /*
116  * Which server versions can this client join.
117  */
118 #define MIN_SERVER_VERSION	0x3103
119 #define MAX_SERVER_VERSION	MY_VERSION
120 
121 #define	MAX_STR_LEN		4096
122 #define	MAX_DISP_LEN		80
123 #define	MAX_NAME_LEN		16
124 #define	MAX_HOST_LEN		64
125 
126 /*
127  * Different contact pack types.
128  */
129 #define	ENTER_GAME_pack		0x00
130 #define	ENTER_QUEUE_pack	0x01
131 #define	REPLY_pack		0x10
132 #define	REPORT_STATUS_pack	0x21
133 #define	OPTION_LIST_pack	0x28
134 #define	CORE_pack		0x30
135 #define	CONTACT_pack		0x31
136 /* The owner-only commands have a common bit high. */
137 #define PRIVILEGE_PACK_MASK	0x40
138 #define	LOCK_GAME_pack		0x62
139 #define	MESSAGE_pack		0x63
140 #define	SHUTDOWN_pack		0x64
141 #define	KICK_PLAYER_pack	0x65
142 #define	MAX_ROBOT_pack		0x66
143 #define	OPTION_TUNE_pack	0x67
144 #define	CREDENTIALS_pack	0x69
145 
146 /*
147  * Possible error codes returned.
148  */
149 #define	SUCCESS		0x00		/* Operation successful */
150 #define	E_NOT_OWNER	0x01		/* Permission denied, not owner */
151 #define	E_GAME_FULL	0x02		/* Game is full, play denied */
152 #define	E_TEAM_FULL	0x03		/* Team is full, play denied */
153 #define	E_TEAM_NOT_SET	0x04		/* Need to specify a team */
154 #define	E_GAME_LOCKED	0x05		/* Game is locked, entry denied */
155 #define	E_NOT_FOUND	0x07		/* Player was not found */
156 #define	E_IN_USE	0x08		/* Name is already in use */
157 #define	E_SOCKET	0x09		/* Can't setup socket */
158 #define	E_INVAL		0x0A		/* Invalid input parameters */
159 #define	E_VERSION	0x0C		/* Incompatible version */
160 #define	E_NOENT		0x0D		/* No such variable */
161 #define	E_UNDEFINED	0x0E		/* Operation undefined */
162 
163 #endif
164