-
Notifications
You must be signed in to change notification settings - Fork 473
/
Common.h
304 lines (258 loc) · 8.02 KB
/
Common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
/*
* Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/>
* Copyright (C) 2009-2011 MaNGOSZero <https://github.com/mangos/zero>
* Copyright (C) 2011-2016 Nostalrius <https://nostalrius.org>
* Copyright (C) 2016-2017 Elysium Project <https://github.com/elysium-project>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef MANGOSSERVER_COMMON_H
#define MANGOSSERVER_COMMON_H
// config.h needs to be included 1st
#ifdef HAVE_CONFIG_H
#ifdef PACKAGE
#undef PACKAGE
#endif //PACKAGE
#ifdef PACKAGE_BUGREPORT
#undef PACKAGE_BUGREPORT
#endif //PACKAGE_BUGREPORT
#ifdef PACKAGE_NAME
#undef PACKAGE_NAME
#endif //PACKAGE_NAME
#ifdef PACKAGE_STRING
#undef PACKAGE_STRING
#endif //PACKAGE_STRING
#ifdef PACKAGE_TARNAME
#undef PACKAGE_TARNAME
#endif //PACKAGE_TARNAME
#ifdef PACKAGE_VERSION
#undef PACKAGE_VERSION
#endif //PACKAGE_VERSION
# include "config.h"
#undef PACKAGE
#undef PACKAGE_BUGREPORT
#undef PACKAGE_NAME
#undef PACKAGE_STRING
#undef PACKAGE_TARNAME
#undef PACKAGE_VERSION
#endif //HAVE_CONFIG_H
#include "Platform/Define.h"
#if COMPILER == COMPILER_MICROSOFT
# pragma warning(disable:4996) // 'function': was declared deprecated
#ifndef __SHOW_STUPID_WARNINGS__
# pragma warning(disable:4244) // 'argument' : conversion from 'type1' to 'type2', possible loss of data
# pragma warning(disable:4355) // 'this' : used in base member initializer list
#endif // __SHOW_STUPID_WARNINGS__
#endif // __GNUC__
#include "Platform/CompilerDefs.h"
#include "Platform/Define.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <errno.h>
#include <signal.h>
#include <assert.h>
#if defined(__sun__)
#include <ieeefp.h> // finite() on Solaris
#endif
#include <set>
#include <list>
#include <string>
#include <map>
#include <unordered_map>
#include <queue>
#include <sstream>
#include <algorithm>
#include "Errors.h"
#include "LockedQueue.h"
#include "Threading.h"
#include <ace/Basic_Types.h>
#include <ace/Guard_T.h>
#include <ace/RW_Thread_Mutex.h>
#include <ace/Thread_Mutex.h>
#include <ace/OS_NS_arpa_inet.h>
// Old ACE versions (pre-ACE-5.5.4) not have this type (add for allow use at Unix side external old ACE versions)
#if PLATFORM != PLATFORM_WINDOWS
# ifndef ACE_OFF_T
typedef off_t ACE_OFF_T;
# endif
#endif
#if PLATFORM == PLATFORM_WINDOWS
# if !defined (FD_SETSIZE)
# define FD_SETSIZE 4096
# endif
# include <ace/config-all.h>
# include <ws2tcpip.h>
#else
# include <sys/types.h>
# include <sys/ioctl.h>
# include <sys/socket.h>
# include <netinet/in.h>
# include <unistd.h>
# include <netdb.h>
#endif
#if COMPILER == COMPILER_MICROSOFT
# include <float.h>
# define I32FMT "%08I32X"
# define I64FMT "%016I64X"
//# define snprintf _snprintf
# define vsnprintf _vsnprintf
# define finite(X) _finite(X)
#else
# define stricmp strcasecmp
# define strnicmp strncasecmp
# define I32FMT "%08X"
# if ACE_SIZEOF_LONG == 8
# define I64FMT "%016lX"
# else
# define I64FMT "%016llX"
# endif /* ACE_SIZEOF_LONG == 8 */
#endif
#define UI64FMTD ACE_UINT64_FORMAT_SPECIFIER
#define UI64LIT(N) ACE_UINT64_LITERAL(N)
#define SI64FMTD ACE_INT64_FORMAT_SPECIFIER
#define SI64LIT(N) ACE_INT64_LITERAL(N)
#define SIZEFMTD ACE_SIZE_T_FORMAT_SPECIFIER
inline float finiteAlways(float f) { return finite(f) ? f : 0.0f; }
#define atol(a) strtoul( a, NULL, 10)
#define STRINGIZE(a) #a
// used for creating values for respawn for example
#define MAKE_PAIR64(l, h) uint64( uint32(l) | ( uint64(h) << 32 ) )
#define PAIR64_HIPART(x) (uint32)((uint64(x) >> 32) & UI64LIT(0x00000000FFFFFFFF))
#define PAIR64_LOPART(x) (uint32)(uint64(x) & UI64LIT(0x00000000FFFFFFFF))
#define MAKE_PAIR32(l, h) uint32( uint16(l) | ( uint32(h) << 16 ) )
#define PAIR32_HIPART(x) (uint16)((uint32(x) >> 16) & 0x0000FFFF)
#define PAIR32_LOPART(x) (uint16)(uint32(x) & 0x0000FFFF)
// Game client builds
#define CLIENT_BUILD_1_2_4 4222
#define CLIENT_BUILD_1_3_1 4297
#define CLIENT_BUILD_1_4_2 4375
#define CLIENT_BUILD_1_5_1 4449
#define CLIENT_BUILD_1_6_1 4544
#define CLIENT_BUILD_1_7_1 4695
#define CLIENT_BUILD_1_8_4 4878
#define CLIENT_BUILD_1_9_4 5086
#define CLIENT_BUILD_1_10_2 5302
#define CLIENT_BUILD_1_11_2 5464
#define CLIENT_BUILD_1_12_1 5875
// Change this to define which version players can use
#define SUPPORTED_CLIENT_BUILD CLIENT_BUILD_1_12_1
#if SUPPORTED_CLIENT_BUILD > CLIENT_BUILD_1_11_2
#define MAX_CONTENT_PATCH 10
#elif SUPPORTED_CLIENT_BUILD > CLIENT_BUILD_1_10_2
#define MAX_CONTENT_PATCH 9
#elif SUPPORTED_CLIENT_BUILD > CLIENT_BUILD_1_9_4
#define MAX_CONTENT_PATCH 8
#else
#define MAX_CONTENT_PATCH 7
#endif
enum TimeConstants
{
MINUTE = 60,
HOUR = MINUTE*60,
DAY = HOUR*24,
WEEK = DAY*7,
MONTH = DAY*30,
YEAR = MONTH*12,
IN_MILLISECONDS = 1000
};
enum AccountTypes
{
SEC_PLAYER = 0,
SEC_MODERATOR = 1,
SEC_MODERATOR_CONF = 2,
SEC_GAMEMASTER = 3,
SEC_BASIC_ADMIN = 4,
SEC_DEVELOPPER = 5,
SEC_ADMINISTRATOR = 6,
SEC_CONSOLE = 7 // must be always last in list, accounts must have less security level always also
};
// Used in mangosd/realmd
enum RealmFlags
{
REALM_FLAG_NONE = 0x00,
REALM_FLAG_INVALID = 0x01,
REALM_FLAG_OFFLINE = 0x02,
REALM_FLAG_SPECIFYBUILD = 0x04, // client will show realm version in RealmList screen in form "RealmName (major.minor.revision.build)"
REALM_FLAG_UNK1 = 0x08,
REALM_FLAG_UNK2 = 0x10,
REALM_FLAG_NEW_PLAYERS = 0x20,
REALM_FLAG_RECOMMENDED = 0x40,
REALM_FLAG_FULL = 0x80
};
// Index returned by GetSessionDbcLocale.
enum LocaleConstant
{
LOCALE_enUS = 0, // also enGB
LOCALE_koKR = 1,
LOCALE_frFR = 2,
LOCALE_deDE = 3,
LOCALE_zhCN = 4,
LOCALE_zhTW = 5,
LOCALE_esES = 6,
LOCALE_esMX = 7,
LOCALE_ruRU = 8 // not in vanilla
};
// Index returned by GetSessionDbLocaleIndex.
enum DBLocaleConstant : int
{
DB_LOCALE_enUS = -1,
DB_LOCALE_frFR = 0,
DB_LOCALE_deDE = 1,
DB_LOCALE_koKR = 2,
DB_LOCALE_zhCN = 3,
DB_LOCALE_zhTW = 4,
DB_LOCALE_esES = 5,
DB_LOCALE_esMX = 6,
DB_LOCALE_ruRU = 7
};
#define MAX_DBC_LOCALE 8
#define MAX_LOCALE 9
LocaleConstant GetLocaleByName(const std::string& name);
LocaleConstant GetDbcLocaleFromDbLocale(DBLocaleConstant localeIndex);
extern char const* localeNames[MAX_LOCALE];
struct LocaleNameStr
{
char const* name;
LocaleConstant locale;
};
// used for iterate all names including alternative
extern LocaleNameStr const fullLocaleNameList[];
//operator new[] based version of strdup() function! Release memory by using operator delete[] !
inline char * mangos_strdup(const char * source)
{
char * dest = new char[strlen(source) + 1];
strcpy(dest, source);
return dest;
}
// we always use stdlibc++ std::max/std::min, undefine some not C++ standard defines (Win API and some pother platforms)
#ifdef max
# undef max
#endif
#ifdef min
# undef min
#endif
#ifndef M_PI
# define M_PI 3.14159265358979323846
#endif
#ifndef M_PI_F
# define M_PI_F float(M_PI)
#endif
#ifndef countof
#define countof(array) (sizeof(array) / sizeof((array)[0]))
#endif
#endif