ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/newclient.h
Revision: 1.19
Committed: Fri Dec 15 19:59:19 2006 UTC (17 years, 5 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.18: +0 -0 lines
State: FILE REMOVED
Log Message:
the rename for sanity campaign hits
you died
- renamed stuff
- partially updated copyrights
- some cleanups

File Contents

# Content
1 /*
2 CrossFire, A Multiplayer game for X-windows
3
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 The authors can be reached via e-mail at crossfire-devel@real-time.com
22 */
23
24 /* This file defines various flags that both the new client and
25 * newserver uses. These should never be changed, only expanded.
26 * Changing them will likely cause all old clients to not work properly.
27 * While called newclient, it is really used by both the client and
28 * server to keep some values the same.
29 *
30 * Name format is CS_(command)_(flag)
31 * CS = Client/Server.
32 * (command) is protocol command, ie ITEM
33 * (flag) is the flag name
34 */
35
36 /* It is trivial to keep a link of copy of this file in the client
37 * or server area. But keeping one common file should make things
38 * more reliable, as both the client and server will definately be
39 * talking about the same values.
40 */
41
42
43 #ifndef NEWCLIENT_H
44 #define NEWCLIENT_H
45
46 /* Maximum size of any packet we expect. Using this makes it so we don't need to
47 * allocated and deallocated the same buffer over and over again and the price
48 * of using a bit of extra memory. It also makes the code simpler.
49 *
50 * The size must be the same in the server and the client (stupid), and its also NOT
51 * the maximum buffer size as one would expect, but the maximum buffer size + 1.
52 */
53 #define MAXSOCKBUF 10240
54
55
56 #define CS_QUERY_YESNO 0x1 /* Yes/no question */
57 #define CS_QUERY_SINGLECHAR 0x2 /* Single character response expected */
58 #define CS_QUERY_HIDEINPUT 0x4 /* Hide input being entered */
59
60 #define CS_SAY_NORMAL 0x1 /* Normal say command */
61 #define CS_SAY_SHOUT 0x2 /* Text is shouted. */
62 #define CS_SAY_GSAY 0x4 /* Text is group say command */
63
64 /* These are multiplication values that should be used when changing
65 * floats to ints, and vice version. MULTI is integer representatin
66 * (float to int), MULTF is float, for going from int to float.
67 */
68 #define FLOAT_MULTI 100000
69 #define FLOAT_MULTF 100000.0
70
71 /* ID's for the various stats that get sent across. */
72
73 #define CS_STAT_HP 1
74 #define CS_STAT_MAXHP 2
75 #define CS_STAT_SP 3
76 #define CS_STAT_MAXSP 4
77 #define CS_STAT_STR 5
78 #define CS_STAT_INT 6
79 #define CS_STAT_WIS 7
80 #define CS_STAT_DEX 8
81 #define CS_STAT_CON 9
82 #define CS_STAT_CHA 10
83 #define CS_STAT_EXP 11
84 #define CS_STAT_LEVEL 12
85 #define CS_STAT_WC 13
86 #define CS_STAT_AC 14
87 #define CS_STAT_DAM 15
88 #define CS_STAT_ARMOUR 16
89 #define CS_STAT_SPEED 17
90 #define CS_STAT_FOOD 18
91 #define CS_STAT_WEAP_SP 19
92 #define CS_STAT_RANGE 20
93 #define CS_STAT_TITLE 21
94 #define CS_STAT_POW 22
95 #define CS_STAT_GRACE 23
96 #define CS_STAT_MAXGRACE 24
97 #define CS_STAT_FLAGS 25
98 #define CS_STAT_WEIGHT_LIM 26
99 #define CS_STAT_EXP64 28
100 #define CS_STAT_SPELL_ATTUNE 29
101 #define CS_STAT_SPELL_REPEL 30
102 #define CS_STAT_SPELL_DENY 31
103
104 /* Start & end of resistances, inclusive. */
105 #define CS_STAT_RESIST_START 100
106 #define CS_STAT_RESIST_END 117
107 #define CS_STAT_RES_PHYS 100
108 #define CS_STAT_RES_MAG 101
109 #define CS_STAT_RES_FIRE 102
110 #define CS_STAT_RES_ELEC 103
111 #define CS_STAT_RES_COLD 104
112 #define CS_STAT_RES_CONF 105
113 #define CS_STAT_RES_ACID 106
114 #define CS_STAT_RES_DRAIN 107
115 #define CS_STAT_RES_GHOSTHIT 108
116 #define CS_STAT_RES_POISON 109
117 #define CS_STAT_RES_SLOW 110
118 #define CS_STAT_RES_PARA 111
119 #define CS_STAT_TURN_UNDEAD 112
120 #define CS_STAT_RES_FEAR 113
121 #define CS_STAT_RES_DEPLETE 114
122 #define CS_STAT_RES_DEATH 115
123 #define CS_STAT_RES_HOLYWORD 116
124 #define CS_STAT_RES_BLIND 117
125
126 /* Start & end of skill experience + skill level, inclusive. */
127 #define CS_STAT_SKILLEXP_START 118
128 #define CS_STAT_SKILLEXP_END 129
129 #define CS_STAT_SKILLEXP_AGILITY 118
130 #define CS_STAT_SKILLEXP_AGLEVEL 119
131 #define CS_STAT_SKILLEXP_PERSONAL 120
132 #define CS_STAT_SKILLEXP_PELEVEL 121
133 #define CS_STAT_SKILLEXP_MENTAL 122
134 #define CS_STAT_SKILLEXP_MELEVEL 123
135 #define CS_STAT_SKILLEXP_PHYSIQUE 124
136 #define CS_STAT_SKILLEXP_PHLEVEL 125
137 #define CS_STAT_SKILLEXP_MAGIC 126
138 #define CS_STAT_SKILLEXP_MALEVEL 127
139 #define CS_STAT_SKILLEXP_WISDOM 128
140 #define CS_STAT_SKILLEXP_WILEVEL 129
141
142 /* CS_STAT_SKILLINFO is used as the starting index point. Skill number->name
143 * map is generated dynamically for the client, so a bunch of entries will
144 * be used here. CS_NUM_SKILLS does not match how many skills there really
145 * are - instead, it is used as a range of values so that the client
146 * can have some idea how many skill categories there may be.
147 */
148 #define CS_STAT_SKILLINFO 140
149 #define CS_NUM_SKILLS 50
150
151 /* These are used with CS_STAT_FLAGS above to communicate S->C what the
152 * server thinks the fireon & runon states are.
153 */
154 #define SF_FIREON 0x01
155 #define SF_RUNON 0x02
156
157 /* The following are the color flags passed to new_draw_info.
158 *
159 * We also set up some control flags
160 *
161 * NDI = New Draw Info
162 */
163
164 /* Color specifications - note these match the order in xutil.c */
165 /* Note 2: Black, the default color, is 0. Thus, it does not need to
166 * be implicitly specified.
167 */
168 #define NDI_BLACK 0
169 #define NDI_WHITE 1
170 #define NDI_NAVY 2
171 #define NDI_RED 3
172 #define NDI_ORANGE 4
173 #define NDI_BLUE 5 /* Actually, it is Dodger Blue */
174 #define NDI_DK_ORANGE 6 /* DarkOrange2 */
175 #define NDI_GREEN 7 /* SeaGreen */
176 #define NDI_LT_GREEN 8 /* DarkSeaGreen, which is actually paler */
177 /* Than seagreen - also background color */
178 #define NDI_GREY 9
179 #define NDI_BROWN 10 /* Sienna */
180 #define NDI_GOLD 11
181 #define NDI_TAN 12 /* Khaki */
182
183 #define NDI_MAX_COLOR 12 /* Last value in */
184 #define NDI_COLOR_MASK 0xff /* Gives lots of room for expansion - we are */
185 /* using an int anyways, so we have the space */
186 /* to still do all the flags */
187
188
189 #define NDI_UNIQUE 0x100 /* Print this out immediately, don't buffer */
190 #define NDI_ALL 0x200 /* Inform all players of this message */
191
192 /* Flags for the item command */
193 enum {a_none, a_readied, a_wielded, a_worn, a_active, a_applied};
194 #define F_APPLIED 0x000F
195 #define F_LOCATION 0x00F0
196 #define F_UNPAID 0x0200
197 #define F_MAGIC 0x0400
198 #define F_CURSED 0x0800
199 #define F_DAMNED 0x1000
200 #define F_OPEN 0x2000
201 #define F_NOPICK 0x4000
202 #define F_LOCKED 0x8000
203
204 #define CF_FACE_NONE 0
205 #define CF_FACE_BITMAP 1
206 #define CF_FACE_XPM 2
207 #define CF_FACE_PNG 3
208 #define CF_FACE_CACHE 0x10
209
210 /* Used in the new_face structure on the magicmap field. Low bits
211 * are color informatin. For now, only high bit information we need
212 * is floor information.
213 */
214 #define FACE_FLOOR 0x80
215 #define FACE_WALL 0x40 /* Or'd into the color value by the server
216 * right before sending.
217 */
218 #define FACE_COLOR_MASK 0xf
219
220 #define UPD_LOCATION 0x01
221 #define UPD_FLAGS 0x02
222 #define UPD_WEIGHT 0x04
223 #define UPD_FACE 0x08
224 #define UPD_NAME 0x10
225 #define UPD_ANIM 0x20
226 #define UPD_ANIMSPEED 0x40
227 #define UPD_NROF 0x80
228
229 /* The flag values sent by the updspell command */
230 #define UPD_SP_MANA 0x01
231 #define UPD_SP_GRACE 0x02
232 #define UPD_SP_DAMAGE 0x04
233
234 #define SOUND_NORMAL 0
235 #define SOUND_SPELL 1
236
237 struct data
238 {
239 unsigned int len;
240 const void *ptr;
241
242 data (const void *ptr, int len) : len (len), ptr (ptr) { }
243 data (const char *str) : len (strlen (str ? str : 0)), ptr ((void *)str) { }
244 data (const shstr &sh) : len (sh.length ()), ptr ((void *)&sh) { }
245 };
246
247 struct data8
248 {
249 unsigned int len;
250 const void *ptr;
251
252 data8 (const void *ptr, int len) : len (len), ptr (ptr) { }
253 data8 (const char *str) : len (strlen (str ? str : 0)), ptr ((void *)str) { }
254 data8 (const shstr &sh) : len (sh.length ()), ptr ((void *)&sh) { }
255 };
256
257 struct data16
258 {
259 unsigned int len;
260 const void *ptr;
261
262 data16 (const void *ptr, int len) : len (len), ptr (ptr) { }
263 data16 (const char *str) : len (strlen (str ? str : 0)), ptr ((void *)str) { }
264 data16 (const shstr &sh) : len (sh.length ()), ptr ((void *)&sh) { }
265 };
266
267 /* Contains the base information we use to make up a packet we want to send. */
268 struct packet
269 {
270 enum { bufsize = MAXSOCKBUF };
271 enum { hdrlen = 2 }; // keep this many bytes free at the front
272
273 // strategy: only check on variable-length adds
274 // and allow 256 bytes for any headers.
275 uint8 *cur;
276 uint8 buf_ [hdrlen + bufsize + 256];
277
278 packet () { reset (); }
279
280 uint8 operator [](unsigned int i) const { return buf_ [i + hdrlen]; }
281 uint8 &operator [](unsigned int i) { return buf_ [i + hdrlen]; }
282
283 uint8 *buf () { return buf_ + hdrlen; }
284 const uint8 *buf () const { return buf_ + hdrlen; }
285
286 void reset (int offset = 0) { cur = buf () + offset; }
287 int length () const { return cur - buf (); }
288 int room () { return bufsize - (cur - buf ()); }
289
290 // unchecked
291 packet &operator <<(uint8 v) { *cur++ = v; return *this; }
292
293 packet &operator <<(uint16 v) { return *this << uint8 (v >> 8) << uint8 (v); }
294 packet &operator <<(uint32 v) { return *this << uint16 (v >> 16) << uint16 (v); }
295 packet &operator <<(uint64 v) { return *this << uint32 (v >> 32) << uint32 (v); }
296
297 packet &operator <<(sint8 v) { return *this << (uint8 )v; }
298 packet &operator <<(sint16 v) { return *this << (uint16)v; }
299 packet &operator <<(sint32 v) { return *this << (uint32)v; }
300 packet &operator <<(sint64 v) { return *this << (uint64)v; }
301
302 // checked
303 packet &operator <<(const data &v);
304 packet &operator <<(const data8 &v);
305 packet &operator <<(const data16 &v);
306
307 packet &operator <<(const char *v);
308 packet &operator <<(const shstr &sh) { return *this << data (&sh, sh.length ()); }
309
310 void printf (const char *format, ...);
311 };
312
313 inline uint16 net_uint16 (uint8 *data) { return (data [0] << 8) | data [1]; }
314 inline uint32 net_uint32 (uint8 *data) { return (net_uint16 (data) << 16) | net_uint16 (data + 2); }
315 inline sint16 net_sint16 (uint8 *data) { return sint16 (net_uint16 (data)); }
316 inline sint16 net_sint32 (uint8 *data) { return sint32 (net_uint32 (data)); }
317
318 struct CS_Stats
319 {
320 int ibytes; /* ibytes, obytes are bytes in, out */
321 int obytes;
322 short max_conn; /* Maximum connections received */
323 time_t time_start; /* When we started logging this */
324 };
325
326 extern CS_Stats cst_tot, cst_lst;
327
328 #endif
329