[2] | 1 | /* |
---|
[102] | 2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
| 3 | * |
---|
[44] | 4 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
---|
[2] | 5 | * |
---|
| 6 | * This program is free software; you can redistribute it and/or modify |
---|
| 7 | * it under the terms of the GNU General Public License as published by |
---|
| 8 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 9 | * (at your option) any later version. |
---|
| 10 | * |
---|
| 11 | * This program is distributed in the hope that it will be useful, |
---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
[44] | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
[2] | 14 | * GNU General Public License for more details. |
---|
| 15 | * |
---|
| 16 | * You should have received a copy of the GNU General Public License |
---|
| 17 | * along with this program; if not, write to the Free Software |
---|
[44] | 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
[2] | 19 | */ |
---|
| 20 | |
---|
[44] | 21 | #ifndef TRINITYCORE_COMMON_H |
---|
| 22 | #define TRINITYCORE_COMMON_H |
---|
[2] | 23 | |
---|
[6] | 24 | // config.h needs to be included 1st |
---|
| 25 | // TODO this thingy looks like hack ,but its not, need to |
---|
| 26 | // make separate header however, because It makes mess here. |
---|
| 27 | #ifdef HAVE_CONFIG_H |
---|
| 28 | // Remove Some things that we will define |
---|
| 29 | // This is in case including another config.h |
---|
| 30 | // before trinity config.h |
---|
| 31 | #ifdef PACKAGE |
---|
| 32 | #undef PACKAGE |
---|
| 33 | #endif //PACKAGE |
---|
| 34 | #ifdef PACKAGE_BUGREPORT |
---|
| 35 | #undef PACKAGE_BUGREPORT |
---|
| 36 | #endif //PACKAGE_BUGREPORT |
---|
| 37 | #ifdef PACKAGE_NAME |
---|
| 38 | #undef PACKAGE_NAME |
---|
| 39 | #endif //PACKAGE_NAME |
---|
| 40 | #ifdef PACKAGE_STRING |
---|
| 41 | #undef PACKAGE_STRING |
---|
| 42 | #endif //PACKAGE_STRING |
---|
| 43 | #ifdef PACKAGE_TARNAME |
---|
| 44 | #undef PACKAGE_TARNAME |
---|
| 45 | #endif //PACKAGE_TARNAME |
---|
| 46 | #ifdef PACKAGE_VERSION |
---|
| 47 | #undef PACKAGE_VERSION |
---|
| 48 | #endif //PACKAGE_VERSION |
---|
| 49 | #ifdef VERSION |
---|
| 50 | #undef VERSION |
---|
| 51 | #endif //VERSION |
---|
| 52 | # include "config.h" |
---|
| 53 | #undef PACKAGE |
---|
| 54 | #undef PACKAGE_BUGREPORT |
---|
| 55 | #undef PACKAGE_NAME |
---|
| 56 | #undef PACKAGE_STRING |
---|
| 57 | #undef PACKAGE_TARNAME |
---|
| 58 | #undef PACKAGE_VERSION |
---|
| 59 | #undef VERSION |
---|
| 60 | #endif //HAVE_CONFIG_H |
---|
| 61 | |
---|
[2] | 62 | #include "Platform/Define.h" |
---|
| 63 | |
---|
| 64 | #if COMPILER == COMPILER_MICROSOFT |
---|
| 65 | |
---|
| 66 | #pragma warning(disable:4996) |
---|
| 67 | |
---|
| 68 | #ifndef __SHOW_STUPID_WARNINGS__ |
---|
| 69 | |
---|
| 70 | #pragma warning(disable:4244) |
---|
| 71 | |
---|
| 72 | #pragma warning(disable:4267) |
---|
| 73 | |
---|
| 74 | #pragma warning(disable:4800) |
---|
| 75 | |
---|
| 76 | #pragma warning(disable:4018) |
---|
| 77 | |
---|
| 78 | #pragma warning(disable:4311) |
---|
| 79 | |
---|
| 80 | #pragma warning(disable:4305) |
---|
| 81 | |
---|
| 82 | #pragma warning(disable:4005) |
---|
| 83 | #endif // __SHOW_STUPID_WARNINGS__ |
---|
| 84 | #endif // __GNUC__ |
---|
| 85 | |
---|
[206] | 86 | #include "Utilities/UnorderedMap.h" |
---|
[2] | 87 | #include <stdio.h> |
---|
| 88 | #include <stdlib.h> |
---|
| 89 | #include <string.h> |
---|
| 90 | #include <time.h> |
---|
| 91 | #include <math.h> |
---|
| 92 | #include <errno.h> |
---|
| 93 | #include <signal.h> |
---|
| 94 | |
---|
| 95 | #if PLATFORM == PLATFORM_WINDOWS |
---|
| 96 | #define STRCASECMP stricmp |
---|
| 97 | #else |
---|
| 98 | #define STRCASECMP strcasecmp |
---|
| 99 | #endif |
---|
| 100 | |
---|
| 101 | #include <set> |
---|
| 102 | #include <list> |
---|
| 103 | #include <string> |
---|
| 104 | #include <map> |
---|
| 105 | #include <queue> |
---|
| 106 | #include <sstream> |
---|
| 107 | #include <algorithm> |
---|
| 108 | |
---|
| 109 | #include <zthread/FastMutex.h> |
---|
| 110 | #include <zthread/LockedQueue.h> |
---|
| 111 | #include <zthread/Runnable.h> |
---|
| 112 | #include <zthread/Thread.h> |
---|
| 113 | |
---|
| 114 | #if PLATFORM == PLATFORM_WINDOWS |
---|
[6] | 115 | # define FD_SETSIZE 4096 |
---|
| 116 | # include <ace/config-all.h> |
---|
[2] | 117 | // XP winver - needed to compile with standard leak check in MemoryLeaks.h |
---|
| 118 | // uncomment later if needed |
---|
| 119 | //#define _WIN32_WINNT 0x0501 |
---|
| 120 | # include <ws2tcpip.h> |
---|
| 121 | //#undef WIN32_WINNT |
---|
| 122 | #else |
---|
| 123 | # include <sys/types.h> |
---|
| 124 | # include <sys/ioctl.h> |
---|
| 125 | # include <sys/socket.h> |
---|
| 126 | # include <netinet/in.h> |
---|
| 127 | # include <unistd.h> |
---|
| 128 | # include <netdb.h> |
---|
| 129 | #endif |
---|
| 130 | |
---|
| 131 | #if COMPILER == COMPILER_MICROSOFT |
---|
| 132 | |
---|
| 133 | #include <float.h> |
---|
| 134 | |
---|
| 135 | #define I64FMT "%016I64X" |
---|
| 136 | #define I64FMTD "%I64u" |
---|
| 137 | #define SI64FMTD "%I64d" |
---|
| 138 | #define snprintf _snprintf |
---|
| 139 | #define atoll __atoi64 |
---|
| 140 | #define vsnprintf _vsnprintf |
---|
| 141 | #define strdup _strdup |
---|
| 142 | #define finite(X) _finite(X) |
---|
| 143 | |
---|
| 144 | #else |
---|
| 145 | |
---|
| 146 | #define stricmp strcasecmp |
---|
| 147 | #define strnicmp strncasecmp |
---|
| 148 | #define I64FMT "%016llX" |
---|
[257] | 149 | #define I64FMTD "%I64u" |
---|
[2] | 150 | #define SI64FMTD "%lld" |
---|
| 151 | #endif |
---|
| 152 | |
---|
| 153 | inline float finiteAlways(float f) { return finite(f) ? f : 0.0f; } |
---|
| 154 | |
---|
| 155 | #define atol(a) strtoul( a, NULL, 10) |
---|
| 156 | |
---|
| 157 | #define STRINGIZE(a) #a |
---|
| 158 | |
---|
| 159 | enum TimeConstants |
---|
| 160 | { |
---|
| 161 | MINUTE = 60, |
---|
| 162 | HOUR = MINUTE*60, |
---|
| 163 | DAY = HOUR*24, |
---|
| 164 | MONTH = DAY*30 |
---|
| 165 | }; |
---|
| 166 | |
---|
| 167 | enum AccountTypes |
---|
| 168 | { |
---|
| 169 | SEC_PLAYER = 0, |
---|
| 170 | SEC_MODERATOR = 1, |
---|
| 171 | SEC_GAMEMASTER = 2, |
---|
[112] | 172 | SEC_ADMINISTRATOR = 3, |
---|
| 173 | SEC_CONSOLE = 4 // must be always last in list, accounts must have less security level always also |
---|
[2] | 174 | }; |
---|
| 175 | |
---|
| 176 | enum LocaleConstant |
---|
| 177 | { |
---|
| 178 | LOCALE_enUS = 0, |
---|
| 179 | LOCALE_koKR = 1, |
---|
| 180 | LOCALE_frFR = 2, |
---|
| 181 | LOCALE_deDE = 3, |
---|
| 182 | LOCALE_zhCN = 4, |
---|
| 183 | LOCALE_zhTW = 5, |
---|
| 184 | LOCALE_esES = 6, |
---|
| 185 | LOCALE_esMX = 7, |
---|
| 186 | LOCALE_ruRU = 8 |
---|
| 187 | }; |
---|
| 188 | |
---|
| 189 | #define MAX_LOCALE 9 |
---|
| 190 | |
---|
| 191 | extern char const* localeNames[MAX_LOCALE]; |
---|
| 192 | |
---|
| 193 | LocaleConstant GetLocaleByName(std::string name); |
---|
| 194 | |
---|
| 195 | // we always use stdlibc++ std::max/std::min, undefine some not C++ standard defines (Win API and some pother platforms) |
---|
| 196 | #ifdef max |
---|
| 197 | #undef max |
---|
| 198 | #endif |
---|
| 199 | |
---|
| 200 | #ifdef min |
---|
| 201 | #undef min |
---|
| 202 | #endif |
---|
| 203 | |
---|
| 204 | #ifndef M_PI |
---|
| 205 | #define M_PI 3.14159265358979323846 |
---|
| 206 | #endif |
---|
| 207 | |
---|
| 208 | #endif |
---|