1 | /* |
---|
2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
3 | * |
---|
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. |
---|
8 | * |
---|
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. |
---|
13 | * |
---|
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 |
---|
17 | */ |
---|
18 | |
---|
19 | #ifndef MANGOSSERVER_COMMON_H |
---|
20 | #define MANGOSSERVER_COMMON_H |
---|
21 | |
---|
22 | #include "Platform/Define.h" |
---|
23 | |
---|
24 | #if COMPILER == COMPILER_MICROSOFT |
---|
25 | |
---|
26 | #pragma warning(disable:4996) |
---|
27 | |
---|
28 | #ifndef __SHOW_STUPID_WARNINGS__ |
---|
29 | |
---|
30 | #pragma warning(disable:4244) |
---|
31 | |
---|
32 | #pragma warning(disable:4267) |
---|
33 | |
---|
34 | #pragma warning(disable:4800) |
---|
35 | |
---|
36 | #pragma warning(disable:4018) |
---|
37 | |
---|
38 | #pragma warning(disable:4311) |
---|
39 | |
---|
40 | #pragma warning(disable:4305) |
---|
41 | |
---|
42 | #pragma warning(disable:4005) |
---|
43 | #endif // __SHOW_STUPID_WARNINGS__ |
---|
44 | #endif // __GNUC__ |
---|
45 | |
---|
46 | #ifdef HAVE_CONFIG_H |
---|
47 | # include <config.h> |
---|
48 | #endif |
---|
49 | |
---|
50 | #include "Utilities/HashMap.h" |
---|
51 | #include <stdio.h> |
---|
52 | #include <stdlib.h> |
---|
53 | #include <string.h> |
---|
54 | #include <time.h> |
---|
55 | #include <math.h> |
---|
56 | #include <errno.h> |
---|
57 | #include <signal.h> |
---|
58 | |
---|
59 | #if PLATFORM == PLATFORM_WINDOWS |
---|
60 | #define STRCASECMP stricmp |
---|
61 | #else |
---|
62 | #define STRCASECMP strcasecmp |
---|
63 | #endif |
---|
64 | |
---|
65 | #include <set> |
---|
66 | #include <list> |
---|
67 | #include <string> |
---|
68 | #include <map> |
---|
69 | #include <queue> |
---|
70 | #include <sstream> |
---|
71 | #include <algorithm> |
---|
72 | |
---|
73 | #include <zthread/FastMutex.h> |
---|
74 | #include <zthread/LockedQueue.h> |
---|
75 | #include <zthread/Runnable.h> |
---|
76 | #include <zthread/Thread.h> |
---|
77 | |
---|
78 | #if PLATFORM == PLATFORM_WINDOWS |
---|
79 | # define FD_SETSIZE 1024 |
---|
80 | # include <winsock2.h> |
---|
81 | // XP winver - needed to compile with standard leak check in MemoryLeaks.h |
---|
82 | // uncomment later if needed |
---|
83 | //#define _WIN32_WINNT 0x0501 |
---|
84 | # include <ws2tcpip.h> |
---|
85 | //#undef WIN32_WINNT |
---|
86 | #else |
---|
87 | # include <sys/types.h> |
---|
88 | # include <sys/ioctl.h> |
---|
89 | # include <sys/socket.h> |
---|
90 | # include <netinet/in.h> |
---|
91 | # include <unistd.h> |
---|
92 | # include <netdb.h> |
---|
93 | #endif |
---|
94 | |
---|
95 | #if COMPILER == COMPILER_MICROSOFT |
---|
96 | |
---|
97 | #include <float.h> |
---|
98 | |
---|
99 | #define I64FMT "%016I64X" |
---|
100 | #define I64FMTD "%I64u" |
---|
101 | #define SI64FMTD "%I64d" |
---|
102 | #define snprintf _snprintf |
---|
103 | #define atoll __atoi64 |
---|
104 | #define vsnprintf _vsnprintf |
---|
105 | #define strdup _strdup |
---|
106 | #define finite(X) _finite(X) |
---|
107 | |
---|
108 | #else |
---|
109 | |
---|
110 | #define stricmp strcasecmp |
---|
111 | #define strnicmp strncasecmp |
---|
112 | #define I64FMT "%016llX" |
---|
113 | #define I64FMTD "%llu" |
---|
114 | #define SI64FMTD "%lld" |
---|
115 | #endif |
---|
116 | |
---|
117 | inline float finiteAlways(float f) { return finite(f) ? f : 0.0f; } |
---|
118 | |
---|
119 | #define atol(a) strtoul( a, NULL, 10) |
---|
120 | |
---|
121 | #define STRINGIZE(a) #a |
---|
122 | |
---|
123 | enum TimeConstants |
---|
124 | { |
---|
125 | MINUTE = 60, |
---|
126 | HOUR = MINUTE*60, |
---|
127 | DAY = HOUR*24, |
---|
128 | MONTH = DAY*30 |
---|
129 | }; |
---|
130 | |
---|
131 | enum AccountTypes |
---|
132 | { |
---|
133 | SEC_PLAYER = 0, |
---|
134 | SEC_MODERATOR = 1, |
---|
135 | SEC_GAMEMASTER = 2, |
---|
136 | SEC_ADMINISTRATOR = 3 |
---|
137 | }; |
---|
138 | |
---|
139 | enum LocaleConstant |
---|
140 | { |
---|
141 | LOCALE_enUS = 0, |
---|
142 | LOCALE_koKR = 1, |
---|
143 | LOCALE_frFR = 2, |
---|
144 | LOCALE_deDE = 3, |
---|
145 | LOCALE_zhCN = 4, |
---|
146 | LOCALE_zhTW = 5, |
---|
147 | LOCALE_esES = 6, |
---|
148 | LOCALE_esMX = 7, |
---|
149 | LOCALE_ruRU = 8 |
---|
150 | }; |
---|
151 | |
---|
152 | #define MAX_LOCALE 9 |
---|
153 | |
---|
154 | extern char const* localeNames[MAX_LOCALE]; |
---|
155 | |
---|
156 | LocaleConstant GetLocaleByName(std::string name); |
---|
157 | |
---|
158 | // we always use stdlibc++ std::max/std::min, undefine some not C++ standard defines (Win API and some pother platforms) |
---|
159 | #ifdef max |
---|
160 | #undef max |
---|
161 | #endif |
---|
162 | |
---|
163 | #ifdef min |
---|
164 | #undef min |
---|
165 | #endif |
---|
166 | |
---|
167 | #ifndef M_PI |
---|
168 | #define M_PI 3.14159265358979323846 |
---|
169 | #endif |
---|
170 | |
---|
171 | #endif |
---|