OregonCore  revision 3611e8a-git
Your Favourite TBC server
Common.h
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore Project. See AUTHORS file for Copyright information
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef OREGONCORE_COMMON_H
19 #define OREGONCORE_COMMON_H
20 
21 // config.h needs to be included 1st
22 // TODO this thingy looks like hack ,but its not, need to
23 // make separate header however, because It makes mess here.
24 #ifdef HAVE_CONFIG_H
25 // Remove Some things that we will define
26 // This is in case including another config.h
27 // before Oregon config.h
28 #ifdef PACKAGE
29 #undef PACKAGE
30 #endif //PACKAGE
31 #ifdef PACKAGE_BUGREPORT
32 #undef PACKAGE_BUGREPORT
33 #endif //PACKAGE_BUGREPORT
34 #ifdef PACKAGE_NAME
35 #undef PACKAGE_NAME
36 #endif //PACKAGE_NAME
37 #ifdef PACKAGE_STRING
38 #undef PACKAGE_STRING
39 #endif //PACKAGE_STRING
40 #ifdef PACKAGE_TARNAME
41 #undef PACKAGE_TARNAME
42 #endif //PACKAGE_TARNAME
43 #ifdef PACKAGE_VERSION
44 #undef PACKAGE_VERSION
45 #endif //PACKAGE_VERSION
46 #ifdef VERSION
47 #undef VERSION
48 #endif //VERSION
49 # include "config.h"
50 #undef PACKAGE
51 #undef PACKAGE_BUGREPORT
52 #undef PACKAGE_NAME
53 #undef PACKAGE_STRING
54 #undef PACKAGE_TARNAME
55 #undef PACKAGE_VERSION
56 #undef VERSION
57 #endif //HAVE_CONFIG_H
58 
59 #include "Platform/Define.h"
60 
61 #define STRINGIFY(x) #x
62 
63 #if COMPILER == COMPILER_MICROSOFT
64 # pragma warning(disable:4996) // 'function': was declared deprecated
65 #ifndef __SHOW_STUPID_WARNINGS__
66 # pragma warning(disable:4005) // 'identifier' : macro redefinition
67 # pragma warning(disable:4018) // 'expression' : signed/unsigned mismatch
68 # pragma warning(disable:4244) // 'argument' : conversion from 'type1' to 'type2', possible loss of data
69 # pragma warning(disable:4267) // 'var' : conversion from 'size_t' to 'type', possible loss of data
70 # pragma warning(disable:4305) // 'identifier' : truncation from 'type1' to 'type2'
71 # pragma warning(disable:4311) // 'variable' : pointer truncation from 'type' to 'type'
72 # pragma warning(disable:4355) // 'this' : used in base member initializer list
73 # pragma warning(disable:4800) // 'type' : forcing value to bool 'true' or 'false' (performance warning)
74 # pragma warning(disable:4522) // warning when class has 2 constructors
75 #endif // __SHOW_STUPID_WARNINGS__
76 #endif // __GNUC__
77 
78 #include "Utilities/UnorderedMap.h"
79 #include <stdio.h>
80 #include <stdlib.h>
81 #include <string.h>
82 #include <time.h>
83 #include <math.h>
84 #include <errno.h>
85 #include <signal.h>
86 #include <assert.h>
87 
88 #if PLATFORM == PLATFORM_WINDOWS
89 #define STRCASECMP stricmp
90 #else
91 #define STRCASECMP strcasecmp
92 #endif
93 
94 #include <set>
95 #include <list>
96 #include <string>
97 #include <map>
98 #include <queue>
99 #include <sstream>
100 #include <algorithm>
101 
102 #include "LockedQueue.h"
103 #include "Threading.h"
104 
105 #include <ace/Basic_Types.h>
106 #include <ace/Guard_T.h>
107 #include <ace/RW_Thread_Mutex.h>
108 #include <ace/Thread_Mutex.h>
109 
110 #if PLATFORM == PLATFORM_WINDOWS
111 # include <windows.h>
112 # include <ace/config-all.h>
113 # include <ws2tcpip.h>
114 #else
115 # include <sys/types.h>
116 # include <sys/ioctl.h>
117 # include <sys/socket.h>
118 # include <netinet/in.h>
119 # include <unistd.h>
120 # include <netdb.h>
121 #endif
122 
123 #if COMPILER == COMPILER_MICROSOFT
124 
125 #include <float.h>
126 
127 #define I32FMT "%08I32X"
128 #define I64FMT "%016I64X"
129 #define snprintf _snprintf
130 #define atoll __atoi64
131 #define vsnprintf _vsnprintf
132 #define finite(X) _finite(X)
133 #define strtoull _strtoui64
134 #define strtoll _strtoi64
135 #define fileno _fileno
136 #define dup2 _dup2
137 #define STRTOF strtod
138 
139 #else
140 
141 #define stricmp strcasecmp
142 #define strnicmp strncasecmp
143 #define I32FMT "%08X"
144 #define I64FMT "%016llX"
145 #define STRTOF strtof
146 
147 #endif
148 
149 #define UI64FMTD ACE_UINT64_FORMAT_SPECIFIER
150 #define UI64LIT(N) ACE_UINT64_LITERAL(N)
151 
152 #define SI64FMTD ACE_INT64_FORMAT_SPECIFIER
153 #define SI64LIT(N) ACE_INT64_LITERAL(N)
154 
155 #define SIZEFMTD ACE_SIZE_T_FORMAT_SPECIFIER
156 
157 inline float finiteAlways(float f)
158 {
159  return finite(f) ? f : 0.0f;
160 }
161 
162 #define atol(a) strtoul( a, NULL, 10)
163 
164 #define STRINGIZE(a) #a
165 
166 // used for creating values for respawn for example
167 #define MAKE_PAIR64(l, h) uint64(uint32(l) | (uint64(h) << 32))
168 #define PAIR64_HIPART(x) (uint32)((uint64(x) >> 32) & UI64LIT(0x00000000FFFFFFFF))
169 #define PAIR64_LOPART(x) (uint32)(uint64(x) & UI64LIT(0x00000000FFFFFFFF))
170 
171 #define MAKE_PAIR32(l, h) uint32(uint16(l) | (uint32(h) << 16))
172 #define PAIR32_HIPART(x) (uint16)((uint32(x) >> 16) & 0x0000FFFF)
173 #define PAIR32_LOPART(x) (uint16)(uint32(x) & 0x0000FFFF)
174 
175 #define UNUSED(x) (void)(x)
176 
178 {
179  MINUTE = 60,
180  HOUR = MINUTE * 60,
181  DAY = HOUR * 24,
182  WEEK = DAY * 7,
183  MONTH = DAY * 30,
184  YEAR = MONTH * 12,
186 };
187 
189 {
194  SEC_CONSOLE = 4 // must be always last in list, accounts must have less security level always also
195 };
196 
197 // Used in core/realm
199 {
203  REALM_FLAG_SPECIFYBUILD = 0x04, // client will show realm version in RealmList screen in form "RealmName (major.minor.revision.build)"
209 };
210 
212 {
213  LOCALE_enUS = 0, // also enGB
222 };
223 
224 const uint8 MAX_LOCALE = 9;
225 
226 extern char const* localeNames[MAX_LOCALE];
227 
228 LocaleConstant GetLocaleByName(const std::string& name);
229 
230 #define DEFAULT_LOCALE LOCALE_enUS
231 
232 typedef std::vector<std::string> StringVector;
233 
234 // we always use stdlibc++ std::max/std::min, undefine some not C++ standard defines (Win API and some other platforms)
235 #ifdef max
236 #undef max
237 #endif
238 
239 #ifdef min
240 #undef min
241 #endif
242 
243 #ifndef M_PI
244 #define M_PI 3.14159265358979323846
245 #endif
246 
247 #endif
248 
float finiteAlways(float f)
Definition: Common.h:157
AccountTypes
Definition: Common.h:188
#define finite(X)
Definition: Common.h:132
Definition: Common.h:184
Definition: Common.h:181
Definition: Common.h:179
Definition: Common.h:182
ACE_UINT8 uint8
Definition: Define.h:73
const uint8 MAX_LOCALE
Definition: Common.h:224
std::vector< std::string > StringVector
Definition: Common.h:232
LocaleConstant GetLocaleByName(const std::string &name)
Definition: Common.cpp:33
Definition: Common.h:183
TimeConstants
Definition: Common.h:177
char const * localeNames[MAX_LOCALE]
Definition: Common.cpp:20
Definition: Common.h:180
LocaleConstant
Definition: Common.h:211
RealmFlags
Definition: Common.h:198