ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/network.h
Revision: 1.38
Committed: Wed Dec 5 21:18:37 2018 UTC (5 years, 5 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.37: +1 -1 lines
Log Message:
nuke compiler.h

File Contents

# User Rev Content
1 root 1.1 /*
2 root 1.20 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 root 1.33 *
4 root 1.36 * Copyright (©) 2018 Marc Alexander Lehmann / the Deliantra team
5 root 1.34 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
6 root 1.28 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
7     * Copyright (©) 1992 Frank Tore Johansen
8 root 1.33 *
9 root 1.24 * Deliantra is free software: you can redistribute it and/or modify it under
10     * the terms of the Affero GNU General Public License as published by the
11     * Free Software Foundation, either version 3 of the License, or (at your
12     * option) any later version.
13 root 1.33 *
14 root 1.14 * This program is distributed in the hope that it will be useful,
15     * but WITHOUT ANY WARRANTY; without even the implied warranty of
16     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17     * GNU General Public License for more details.
18 root 1.33 *
19 root 1.24 * You should have received a copy of the Affero GNU General Public License
20     * and the GNU General Public License along with this program. If not, see
21     * <http://www.gnu.org/licenses/>.
22 root 1.33 *
23 root 1.20 * The authors can be reached via e-mail to <support@deliantra.net>
24 pippijn 1.8 */
25 root 1.1
26     /* This file defines various flags that both the new client and
27     * newserver uses. These should never be changed, only expanded.
28     * Changing them will likely cause all old clients to not work properly.
29     * While called newclient, it is really used by both the client and
30     * server to keep some values the same.
31     *
32     * Name format is CS_(command)_(flag)
33     * CS = Client/Server.
34     * (command) is protocol command, ie ITEM
35     * (flag) is the flag name
36     */
37    
38     /* It is trivial to keep a link of copy of this file in the client
39     * or server area. But keeping one common file should make things
40     * more reliable, as both the client and server will definately be
41     * talking about the same values.
42     */
43    
44 root 1.4 #ifndef NETWORK_H
45     #define NETWORK_H
46    
47 root 1.25 //+GPL
48    
49 root 1.4 #include <cstdarg>
50 root 1.1
51 root 1.38 #include "ecb.h"
52 root 1.26
53 root 1.6 /* Maximum size of any packet we expect.
54 root 1.1 *
55 root 1.17 * The size must be the same in the server and the client (stupid).
56 root 1.19 * TODO: make the actual network configurable per client and use 2**16.
57 root 1.1 */
58 root 1.17 #define MAXSOCKBUF 10239
59 root 1.1
60     #define CS_QUERY_YESNO 0x1 /* Yes/no question */
61     #define CS_QUERY_SINGLECHAR 0x2 /* Single character response expected */
62     #define CS_QUERY_HIDEINPUT 0x4 /* Hide input being entered */
63    
64 root 1.35 /* These are multiplication values that should be used when changing
65 root 1.1 * 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     /* CS_STAT_SKILLINFO is used as the starting index point. Skill number->name
127     * map is generated dynamically for the client, so a bunch of entries will
128     * be used here. CS_NUM_SKILLS does not match how many skills there really
129     * are - instead, it is used as a range of values so that the client
130     * can have some idea how many skill categories there may be.
131     */
132     #define CS_STAT_SKILLINFO 140
133     #define CS_NUM_SKILLS 50
134    
135     /* These are used with CS_STAT_FLAGS above to communicate S->C what the
136     * server thinks the fireon & runon states are.
137     */
138     #define SF_FIREON 0x01
139     #define SF_RUNON 0x02
140    
141     /* Flags for the item command */
142     enum {a_none, a_readied, a_wielded, a_worn, a_active, a_applied};
143 root 1.25
144 root 1.1 #define F_APPLIED 0x000F
145     #define F_LOCATION 0x00F0
146     #define F_UNPAID 0x0200
147     #define F_MAGIC 0x0400
148     #define F_CURSED 0x0800
149     #define F_DAMNED 0x1000
150     #define F_OPEN 0x2000
151     #define F_NOPICK 0x4000
152     #define F_LOCKED 0x8000
153    
154     #define CF_FACE_NONE 0
155     #define CF_FACE_BITMAP 1
156     #define CF_FACE_XPM 2
157     #define CF_FACE_PNG 3
158     #define CF_FACE_CACHE 0x10
159    
160     /* Used in the new_face structure on the magicmap field. Low bits
161     * are color informatin. For now, only high bit information we need
162     * is floor information.
163     */
164     #define FACE_FLOOR 0x80
165     #define FACE_WALL 0x40 /* Or'd into the color value by the server
166     * right before sending.
167     */
168     #define FACE_COLOR_MASK 0xf
169    
170     #define UPD_LOCATION 0x01
171     #define UPD_FLAGS 0x02
172     #define UPD_WEIGHT 0x04
173     #define UPD_FACE 0x08
174     #define UPD_NAME 0x10
175     #define UPD_ANIM 0x20
176     #define UPD_ANIMSPEED 0x40
177     #define UPD_NROF 0x80
178    
179     /* The flag values sent by the updspell command */
180     #define UPD_SP_MANA 0x01
181     #define UPD_SP_GRACE 0x02
182 root 1.27 #define UPD_SP_LEVEL 0x04 // was UPD_SP_DAMAGE in <= server 2.93, client 2.10
183 root 1.1
184     #define SOUND_NORMAL 0
185     #define SOUND_SPELL 1
186    
187 root 1.25 //-GPL
188    
189 root 1.36 template<int unique>
190     struct databuf
191 root 1.1 {
192     unsigned int len;
193     const void *ptr;
194    
195 root 1.36 databuf (const void *ptr, int len) : len (len), ptr (ptr) { }
196     databuf (const char *str) : len (strlen (str ? str : 0)), ptr ((void *)str) { }
197     databuf (shstr_tmp sh) : len (sh.length ()), ptr ((void *)&sh) { }
198     databuf (dynbuf &buf) : len (buf.size ()), ptr (buf.linearise ()) { }
199 root 1.1 };
200    
201 root 1.36 using data_n = databuf<0>;
202     using data8 = databuf<1>;
203     using data16 = databuf<2>;
204 root 1.1
205 root 1.9 struct ber32
206     {
207 root 1.10 enum { size = 5 }; // maximum length of an encoded ber32
208 root 1.9 uint32 val;
209    
210     ber32 (uint32 val) : val (val) { }
211 root 1.16
212     static int encoded_size (uint32 val)
213     {
214     if (val >= (1 << 7*4)) return 5;
215     if (val >= (1 << 7*3)) return 4;
216     if (val >= (1 << 7*2)) return 3;
217     if (val >= (1 << 7*1)) return 2;
218     return 1;
219     }
220 root 1.9 };
221    
222 root 1.1 /* Contains the base information we use to make up a packet we want to send. */
223     struct packet
224     {
225     enum { bufsize = MAXSOCKBUF };
226     enum { hdrlen = 2 }; // keep this many bytes free at the front
227    
228     // strategy: only check on variable-length adds
229     // and allow 256 bytes for any headers.
230     uint8 *cur;
231     uint8 buf_ [hdrlen + bufsize + 256];
232    
233 root 1.5 packet ()
234     {
235     reset ();
236     }
237    
238     packet (const char *name);
239 root 1.1
240     uint8 operator [](unsigned int i) const { return buf_ [i + hdrlen]; }
241     uint8 &operator [](unsigned int i) { return buf_ [i + hdrlen]; }
242    
243     uint8 *buf () { return buf_ + hdrlen; }
244     const uint8 *buf () const { return buf_ + hdrlen; }
245    
246     void reset (int offset = 0) { cur = buf () + offset; }
247     int length () const { return cur - buf (); }
248     int room () { return bufsize - (cur - buf ()); }
249    
250     // unchecked
251     packet &operator <<(uint8 v) { *cur++ = v; return *this; }
252    
253     packet &operator <<(uint16 v) { return *this << uint8 (v >> 8) << uint8 (v); }
254     packet &operator <<(uint32 v) { return *this << uint16 (v >> 16) << uint16 (v); }
255     packet &operator <<(uint64 v) { return *this << uint32 (v >> 32) << uint32 (v); }
256    
257     packet &operator <<(sint8 v) { return *this << (uint8 )v; }
258     packet &operator <<(sint16 v) { return *this << (uint16)v; }
259     packet &operator <<(sint32 v) { return *this << (uint32)v; }
260     packet &operator <<(sint64 v) { return *this << (uint64)v; }
261    
262     // checked
263 root 1.9 packet &operator <<(const ber32 v);
264    
265 root 1.36 packet &operator <<(const data_n &v);
266 root 1.1 packet &operator <<(const data8 &v);
267     packet &operator <<(const data16 &v);
268    
269     packet &operator <<(const char *v);
270 root 1.36 packet &operator <<(shstr_tmp sh) { return *this << data_n (sh); }
271     packet &operator <<(const std::string &s) { return *this << data_n (s.data (), s.size ()); }
272 root 1.1
273 root 1.4 void vprintf (const char *format, va_list ap);
274    
275 root 1.37 void printf (const char *format, ...) ecb_attribute ((format (printf, 2, 3)))
276 root 1.4 {
277     va_list ap;
278     va_start (ap, format);
279     vprintf (format, ap);
280     va_end (ap);
281     }
282 root 1.1 };
283    
284     inline uint16 net_uint16 (uint8 *data) { return (data [0] << 8) | data [1]; }
285     inline uint32 net_uint32 (uint8 *data) { return (net_uint16 (data) << 16) | net_uint16 (data + 2); }
286     inline sint16 net_sint16 (uint8 *data) { return sint16 (net_uint16 (data)); }
287     inline sint16 net_sint32 (uint8 *data) { return sint32 (net_uint32 (data)); }
288    
289     #endif
290