Updated Copyright year to 2013
[getmangos.git] / src / shared / Common.h
blob87b0b45dc4ab8df7d45361744be50c055ee4ff92
1 /*
2 * Copyright (C) 2005-2013 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef MANGOSSERVER_COMMON_H
20 #define MANGOSSERVER_COMMON_H
22 // config.h needs to be included 1st
23 #ifdef HAVE_CONFIG_H
24 #ifdef PACKAGE
25 #undef PACKAGE
26 #endif // PACKAGE
27 #ifdef PACKAGE_BUGREPORT
28 #undef PACKAGE_BUGREPORT
29 #endif // PACKAGE_BUGREPORT
30 #ifdef PACKAGE_NAME
31 #undef PACKAGE_NAME
32 #endif // PACKAGE_NAME
33 #ifdef PACKAGE_STRING
34 #undef PACKAGE_STRING
35 #endif // PACKAGE_STRING
36 #ifdef PACKAGE_TARNAME
37 #undef PACKAGE_TARNAME
38 #endif // PACKAGE_TARNAME
39 #ifdef PACKAGE_VERSION
40 #undef PACKAGE_VERSION
41 #endif // PACKAGE_VERSION
42 #ifdef VERSION
43 #undef VERSION
44 #endif // VERSION
45 # include "config.h"
46 #undef PACKAGE
47 #undef PACKAGE_BUGREPORT
48 #undef PACKAGE_NAME
49 #undef PACKAGE_STRING
50 #undef PACKAGE_TARNAME
51 #undef PACKAGE_VERSION
52 #undef VERSION
53 #endif // HAVE_CONFIG_H
55 #include "Platform/Define.h"
57 #if COMPILER == COMPILER_MICROSOFT
58 # pragma warning(disable:4996) // 'function': was declared deprecated
59 #ifndef __SHOW_STUPID_WARNINGS__
60 # pragma warning(disable:4244) // 'argument' : conversion from 'type1' to 'type2', possible loss of data
61 # pragma warning(disable:4355) // 'this' : used in base member initializer list
62 #endif // __SHOW_STUPID_WARNINGS__
63 #endif // __GNUC__
65 #include "Utilities/UnorderedMapSet.h"
66 #include <stdio.h>
67 #include <stdlib.h>
68 #include <string.h>
69 #include <time.h>
70 #include <math.h>
71 #include <errno.h>
72 #include <signal.h>
73 #include <assert.h>
75 #if defined(__sun__)
76 #include <ieeefp.h> // finite() on Solaris
77 #endif
79 #include <set>
80 #include <list>
81 #include <string>
82 #include <map>
83 #include <queue>
84 #include <sstream>
85 #include <algorithm>
87 #include "Errors.h"
88 #include "LockedQueue.h"
89 #include "Threading.h"
91 #include <ace/Basic_Types.h>
92 #include <ace/Guard_T.h>
93 #include <ace/RW_Thread_Mutex.h>
94 #include <ace/Thread_Mutex.h>
95 #include <ace/OS_NS_arpa_inet.h>
97 // Old ACE versions (pre-ACE-5.5.4) not have this type (add for allow use at Unix side external old ACE versions)
98 #if PLATFORM != PLATFORM_WINDOWS
99 # ifndef ACE_OFF_T
100 typedef off_t ACE_OFF_T;
101 # endif
102 #endif
104 #if PLATFORM == PLATFORM_WINDOWS
105 # if !defined (FD_SETSIZE)
106 # define FD_SETSIZE 4096
107 # endif
108 # include <ace/config-all.h>
109 # include <ws2tcpip.h>
110 #else
111 # include <sys/types.h>
112 # include <sys/ioctl.h>
113 # include <sys/socket.h>
114 # include <netinet/in.h>
115 # include <unistd.h>
116 # include <netdb.h>
117 #endif
119 #if COMPILER == COMPILER_MICROSOFT
121 # include <float.h>
123 # define I32FMT "%08I32X"
124 # define I64FMT "%016I64X"
125 # define snprintf _snprintf
126 # define vsnprintf _vsnprintf
127 # define finite(X) _finite(X)
129 #else
131 # define stricmp strcasecmp
132 # define strnicmp strncasecmp
134 # define I32FMT "%08X"
135 # if ACE_SIZEOF_LONG == 8
136 # define I64FMT "%016lX"
137 # else
138 # define I64FMT "%016llX"
139 # endif /* ACE_SIZEOF_LONG == 8 */
141 #endif
143 #define UI64FMTD ACE_UINT64_FORMAT_SPECIFIER
144 #define UI64LIT(N) ACE_UINT64_LITERAL(N)
146 #define SI64FMTD ACE_INT64_FORMAT_SPECIFIER
147 #define SI64LIT(N) ACE_INT64_LITERAL(N)
149 #define SIZEFMTD ACE_SIZE_T_FORMAT_SPECIFIER
151 inline float finiteAlways(float f) { return finite(f) ? f : 0.0f; }
153 #define atol(a) strtoul( a, NULL, 10)
155 #define STRINGIZE(a) #a
157 // used for creating values for respawn for example
158 #define MAKE_PAIR64(l, h) uint64( uint32(l) | ( uint64(h) << 32 ) )
159 #define PAIR64_HIPART(x) (uint32)((uint64(x) >> 32) & UI64LIT(0x00000000FFFFFFFF))
160 #define PAIR64_LOPART(x) (uint32)(uint64(x) & UI64LIT(0x00000000FFFFFFFF))
162 #define MAKE_PAIR32(l, h) uint32( uint16(l) | ( uint32(h) << 16 ) )
163 #define PAIR32_HIPART(x) (uint16)((uint32(x) >> 16) & 0x0000FFFF)
164 #define PAIR32_LOPART(x) (uint16)(uint32(x) & 0x0000FFFF)
166 enum TimeConstants
168 MINUTE = 60,
169 HOUR = MINUTE * 60,
170 DAY = HOUR * 24,
171 WEEK = DAY * 7,
172 MONTH = DAY * 30,
173 YEAR = MONTH * 12,
174 IN_MILLISECONDS = 1000
177 enum AccountTypes
179 SEC_PLAYER = 0,
180 SEC_MODERATOR = 1,
181 SEC_GAMEMASTER = 2,
182 SEC_ADMINISTRATOR = 3,
183 SEC_CONSOLE = 4 // must be always last in list, accounts must have less security level always also
186 // Used in mangosd/realmd
187 enum RealmFlags
189 REALM_FLAG_NONE = 0x00,
190 REALM_FLAG_INVALID = 0x01,
191 REALM_FLAG_OFFLINE = 0x02,
192 REALM_FLAG_SPECIFYBUILD = 0x04, // client will show realm version in RealmList screen in form "RealmName (major.minor.revision.build)"
193 REALM_FLAG_UNK1 = 0x08,
194 REALM_FLAG_UNK2 = 0x10,
195 REALM_FLAG_NEW_PLAYERS = 0x20,
196 REALM_FLAG_RECOMMENDED = 0x40,
197 REALM_FLAG_FULL = 0x80
200 enum LocaleConstant
202 LOCALE_enUS = 0, // also enGB
203 LOCALE_koKR = 1,
204 LOCALE_frFR = 2,
205 LOCALE_deDE = 3,
206 LOCALE_zhCN = 4,
207 LOCALE_zhTW = 5,
208 LOCALE_esES = 6,
209 LOCALE_esMX = 7,
210 LOCALE_ruRU = 8
213 #define MAX_LOCALE 9
215 LocaleConstant GetLocaleByName(const std::string& name);
217 extern char const* localeNames[MAX_LOCALE];
219 struct LocaleNameStr
221 char const* name;
222 LocaleConstant locale;
225 // used for iterate all names including alternative
226 extern LocaleNameStr const fullLocaleNameList[];
228 // operator new[] based version of strdup() function! Release memory by using operator delete[] !
229 inline char* mangos_strdup(const char* source)
231 char* dest = new char[strlen(source) + 1];
232 strcpy(dest, source);
233 return dest;
236 // we always use stdlibc++ std::max/std::min, undefine some not C++ standard defines (Win API and some pother platforms)
237 #ifdef max
238 # undef max
239 #endif
241 #ifdef min
242 # undef min
243 #endif
245 #ifndef M_PI
246 # define M_PI 3.14159265358979323846
247 #endif
249 #ifndef M_PI_F
250 # define M_PI_F float(M_PI)
251 #endif
253 #ifndef countof
254 #define countof(array) (sizeof(array) / sizeof((array)[0]))
255 #endif
257 #endif