1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
|
|
4 | * Copyright (©) 2018 Marc Alexander Lehmann / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
8 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * the terms of the Affero GNU General Public License as published by the |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
12 | * option) any later version. |
12 | * |
13 | * |
13 | * This program is distributed in the hope that it will be useful, |
14 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
17 | * GNU General Public License for more details. |
17 | * |
18 | * |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * You should have received a copy of the Affero GNU General Public License |
19 | * and the GNU General Public License along with this program. If not, see |
20 | * and the GNU General Public License along with this program. If not, see |
20 | * <http://www.gnu.org/licenses/>. |
21 | * <http://www.gnu.org/licenses/>. |
21 | * |
22 | * |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
24 | */ |
24 | |
25 | |
25 | /* This file defines various flags that both the new client and |
26 | /* This file defines various flags that both the new client and |
26 | * newserver uses. These should never be changed, only expanded. |
27 | * newserver uses. These should never be changed, only expanded. |
… | |
… | |
45 | |
46 | |
46 | //+GPL |
47 | //+GPL |
47 | |
48 | |
48 | #include <cstdarg> |
49 | #include <cstdarg> |
49 | |
50 | |
50 | #include "compiler.h" |
51 | #include "ecb.h" |
51 | |
52 | |
52 | /* Maximum size of any packet we expect. |
53 | /* Maximum size of any packet we expect. |
53 | * |
54 | * |
54 | * The size must be the same in the server and the client (stupid). |
55 | * The size must be the same in the server and the client (stupid). |
55 | * TODO: make the actual network configurable per client and use 2**16. |
56 | * TODO: make the actual network configurable per client and use 2**16. |
… | |
… | |
58 | |
59 | |
59 | #define CS_QUERY_YESNO 0x1 /* Yes/no question */ |
60 | #define CS_QUERY_YESNO 0x1 /* Yes/no question */ |
60 | #define CS_QUERY_SINGLECHAR 0x2 /* Single character response expected */ |
61 | #define CS_QUERY_SINGLECHAR 0x2 /* Single character response expected */ |
61 | #define CS_QUERY_HIDEINPUT 0x4 /* Hide input being entered */ |
62 | #define CS_QUERY_HIDEINPUT 0x4 /* Hide input being entered */ |
62 | |
63 | |
63 | /* These are multiplication values that should be used when changing |
64 | /* These are multiplication values that should be used when changing |
64 | * floats to ints, and vice version. MULTI is integer representatin |
65 | * floats to ints, and vice version. MULTI is integer representatin |
65 | * (float to int), MULTF is float, for going from int to float. |
66 | * (float to int), MULTF is float, for going from int to float. |
66 | */ |
67 | */ |
67 | #define FLOAT_MULTI 100000 |
68 | #define FLOAT_MULTI 100000 |
68 | #define FLOAT_MULTF 100000.0 |
69 | #define FLOAT_MULTF 100000.0 |
… | |
… | |
120 | #define CS_STAT_RES_DEPLETE 114 |
121 | #define CS_STAT_RES_DEPLETE 114 |
121 | #define CS_STAT_RES_DEATH 115 |
122 | #define CS_STAT_RES_DEATH 115 |
122 | #define CS_STAT_RES_HOLYWORD 116 |
123 | #define CS_STAT_RES_HOLYWORD 116 |
123 | #define CS_STAT_RES_BLIND 117 |
124 | #define CS_STAT_RES_BLIND 117 |
124 | |
125 | |
125 | /* Start & end of skill experience + skill level, inclusive. */ |
|
|
126 | #define CS_STAT_SKILLEXP_START 118 |
|
|
127 | #define CS_STAT_SKILLEXP_END 129 |
|
|
128 | #define CS_STAT_SKILLEXP_AGILITY 118 |
|
|
129 | #define CS_STAT_SKILLEXP_AGLEVEL 119 |
|
|
130 | #define CS_STAT_SKILLEXP_PERSONAL 120 |
|
|
131 | #define CS_STAT_SKILLEXP_PELEVEL 121 |
|
|
132 | #define CS_STAT_SKILLEXP_MENTAL 122 |
|
|
133 | #define CS_STAT_SKILLEXP_MELEVEL 123 |
|
|
134 | #define CS_STAT_SKILLEXP_PHYSIQUE 124 |
|
|
135 | #define CS_STAT_SKILLEXP_PHLEVEL 125 |
|
|
136 | #define CS_STAT_SKILLEXP_MAGIC 126 |
|
|
137 | #define CS_STAT_SKILLEXP_MALEVEL 127 |
|
|
138 | #define CS_STAT_SKILLEXP_WISDOM 128 |
|
|
139 | #define CS_STAT_SKILLEXP_WILEVEL 129 |
|
|
140 | |
|
|
141 | /* CS_STAT_SKILLINFO is used as the starting index point. Skill number->name |
126 | /* CS_STAT_SKILLINFO is used as the starting index point. Skill number->name |
142 | * map is generated dynamically for the client, so a bunch of entries will |
127 | * map is generated dynamically for the client, so a bunch of entries will |
143 | * be used here. CS_NUM_SKILLS does not match how many skills there really |
128 | * be used here. CS_NUM_SKILLS does not match how many skills there really |
144 | * are - instead, it is used as a range of values so that the client |
129 | * are - instead, it is used as a range of values so that the client |
145 | * can have some idea how many skill categories there may be. |
130 | * can have some idea how many skill categories there may be. |
… | |
… | |
199 | #define SOUND_NORMAL 0 |
184 | #define SOUND_NORMAL 0 |
200 | #define SOUND_SPELL 1 |
185 | #define SOUND_SPELL 1 |
201 | |
186 | |
202 | //-GPL |
187 | //-GPL |
203 | |
188 | |
|
|
189 | template<int unique> |
204 | struct data |
190 | struct databuf |
205 | { |
191 | { |
206 | unsigned int len; |
192 | unsigned int len; |
207 | const void *ptr; |
193 | const void *ptr; |
208 | |
194 | |
209 | data (const void *ptr, int len) : len (len), ptr (ptr) { } |
195 | databuf (const void *ptr, int len) : len (len), ptr (ptr) { } |
210 | data (const char *str) : len (strlen (str ? str : 0)), ptr ((void *)str) { } |
196 | databuf (const char *str) : len (strlen (str ? str : 0)), ptr ((void *)str) { } |
211 | data (shstr_tmp sh) : len (sh.length ()), ptr ((void *)&sh) { } |
197 | databuf (shstr_tmp sh) : len (sh.length ()), ptr ((void *)&sh) { } |
212 | data (dynbuf &buf) : len (buf.size ()), ptr (buf.linearise ()) { } |
198 | databuf (dynbuf &buf) : len (buf.size ()), ptr (buf.linearise ()) { } |
213 | }; |
199 | }; |
214 | |
200 | |
215 | struct data8 |
201 | using data_n = databuf<0>; |
216 | { |
202 | using data8 = databuf<1>; |
217 | unsigned int len; |
203 | using data16 = databuf<2>; |
218 | const void *ptr; |
|
|
219 | |
|
|
220 | data8 (const void *ptr, int len) : len (len), ptr (ptr) { } |
|
|
221 | data8 (const char *str) : len (strlen (str ? str : 0)), ptr ((void *)str) { } |
|
|
222 | data8 (shstr_tmp sh) : len (sh.length ()), ptr ((void *)&sh) { } |
|
|
223 | data8 (dynbuf &buf) : len (buf.size ()), ptr (buf.linearise ()) { } |
|
|
224 | }; |
|
|
225 | |
|
|
226 | struct data16 |
|
|
227 | { |
|
|
228 | unsigned int len; |
|
|
229 | const void *ptr; |
|
|
230 | |
|
|
231 | data16 (const void *ptr, int len) : len (len), ptr (ptr) { } |
|
|
232 | data16 (const char *str) : len (strlen (str ? str : 0)), ptr ((void *)str) { } |
|
|
233 | data16 (shstr_tmp sh) : len (sh.length ()), ptr ((void *)&sh) { } |
|
|
234 | data16 (dynbuf &buf) : len (buf.size ()), ptr (buf.linearise ()) { } |
|
|
235 | }; |
|
|
236 | |
204 | |
237 | struct ber32 |
205 | struct ber32 |
238 | { |
206 | { |
239 | enum { size = 5 }; // maximum length of an encoded ber32 |
207 | enum { size = 5 }; // maximum length of an encoded ber32 |
240 | uint32 val; |
208 | uint32 val; |
… | |
… | |
292 | packet &operator <<(sint64 v) { return *this << (uint64)v; } |
260 | packet &operator <<(sint64 v) { return *this << (uint64)v; } |
293 | |
261 | |
294 | // checked |
262 | // checked |
295 | packet &operator <<(const ber32 v); |
263 | packet &operator <<(const ber32 v); |
296 | |
264 | |
297 | packet &operator <<(const data &v); |
265 | packet &operator <<(const data_n &v); |
298 | packet &operator <<(const data8 &v); |
266 | packet &operator <<(const data8 &v); |
299 | packet &operator <<(const data16 &v); |
267 | packet &operator <<(const data16 &v); |
300 | |
268 | |
301 | packet &operator <<(const char *v); |
269 | packet &operator <<(const char *v); |
302 | packet &operator <<(shstr_tmp sh) { return *this << data (sh); } |
270 | packet &operator <<(shstr_tmp sh) { return *this << data_n (sh); } |
303 | packet &operator <<(const std::string &s) { return *this << data (s.data (), s.size ()); } |
271 | packet &operator <<(const std::string &s) { return *this << data_n (s.data (), s.size ()); } |
304 | |
272 | |
305 | void vprintf (const char *format, va_list ap); |
273 | void vprintf (const char *format, va_list ap); |
306 | |
274 | |
307 | void printf (const char *format, ...) attribute ((format (printf, 2, 3))) |
275 | void printf (const char *format, ...) ecb_attribute ((format (printf, 2, 3))) |
308 | { |
276 | { |
309 | va_list ap; |
277 | va_list ap; |
310 | va_start (ap, format); |
278 | va_start (ap, format); |
311 | vprintf (format, ap); |
279 | vprintf (format, ap); |
312 | va_end (ap); |
280 | va_end (ap); |