Advertisement
Guest User

Common.H

a guest
May 26th, 2013
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.43 KB | None | 0 0
  1. /*
  2.  * Copyright (C) 2008-2013 TrinityCore <http://www.trinitycore.org/>
  3.  * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
  4.  *
  5.  * This program is free software; you can redistribute it and/or modify it
  6.  * under the terms of the GNU General Public License as published by the
  7.  * Free Software Foundation; either version 2 of the License, or (at your
  8.  * option) any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful, but WITHOUT
  11.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12.  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13.  * more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License along
  16.  * with this program. If not, see <http://www.gnu.org/licenses/>.
  17.  */
  18.  
  19. #ifndef TRINITYCORE_COMMON_H
  20. #define TRINITYCORE_COMMON_H
  21.  
  22. // config.h needs to be included 1st
  23. /// @todo this thingy looks like hack, but its not, need to
  24. // make separate header however, because It makes mess here.
  25. #ifdef HAVE_CONFIG_H
  26. // Remove Some things that we will define
  27. // This is in case including another config.h
  28. // before trinity config.h
  29. #ifdef PACKAGE
  30. #undef PACKAGE
  31. #endif //PACKAGE
  32. #ifdef PACKAGE_BUGREPORT
  33. #undef PACKAGE_BUGREPORT
  34. #endif //PACKAGE_BUGREPORT
  35. #ifdef PACKAGE_NAME
  36. #undef PACKAGE_NAME
  37. #endif //PACKAGE_NAME
  38. #ifdef PACKAGE_STRING
  39. #undef PACKAGE_STRING
  40. #endif //PACKAGE_STRING
  41. #ifdef PACKAGE_TARNAME
  42. #undef PACKAGE_TARNAME
  43. #endif //PACKAGE_TARNAME
  44. #ifdef PACKAGE_VERSION
  45. #undef PACKAGE_VERSION
  46. #endif //PACKAGE_VERSION
  47. #ifdef VERSION
  48. #undef VERSION
  49. #endif //VERSION
  50.  
  51. # include "Config.h"
  52.  
  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.  
  62. #include "Define.h"
  63.  
  64. #include "Dynamic/UnorderedMap.h"
  65. #include <stdio.h>
  66. #include <stdlib.h>
  67. #include <string.h>
  68. #include <time.h>
  69. #include <math.h>
  70. #include <errno.h>
  71. #include <signal.h>
  72. #include <assert.h>
  73.  
  74. #if PLATFORM == PLATFORM_WINDOWS
  75. #define STRCASECMP stricmp
  76. #else
  77. #define STRCASECMP strcasecmp
  78. #endif
  79.  
  80. #include <set>
  81. #include <list>
  82. #include <string>
  83. #include <map>
  84. #include <queue>
  85. #include <sstream>
  86. #include <algorithm>
  87.  
  88. #include "Threading/LockedQueue.h"
  89. #include "Threading/Threading.h"
  90.  
  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.  
  96. #if PLATFORM == PLATFORM_WINDOWS
  97. #  include <ace/config-all.h>
  98. // XP winver - needed to compile with standard leak check in MemoryLeaks.h
  99. // uncomment later if needed
  100. //#define _WIN32_WINNT 0x0501
  101. #  include <ws2tcpip.h>
  102. //#undef WIN32_WINNT
  103. #else
  104. #  include <sys/types.h>
  105. #  include <sys/ioctl.h>
  106. #  include <sys/socket.h>
  107. #  include <netinet/in.h>
  108. #  include <unistd.h>
  109. #  include <netdb.h>
  110. #endif
  111.  
  112. #if COMPILER == COMPILER_MICROSOFT
  113.  
  114. #include <float.h>
  115.  
  116. #define I32FMT "%08I32X"
  117. #define I64FMT "%016I64X"
  118. #define snprintf _snprintf
  119. #define atoll _atoi64
  120. #define vsnprintf _vsnprintf
  121. #define finite(X) _finite(X)
  122. #define llabs _abs64
  123.  
  124. #else
  125.  
  126. #define stricmp strcasecmp
  127. #define strnicmp strncasecmp
  128. #define I32FMT "%08X"
  129. #define I64FMT "%016llX"
  130.  
  131. #endif
  132.  
  133. inline float finiteAlways(float f) { return finite(f) ? f : 0.0f; }
  134.  
  135. #define atol(a) strtoul( a, NULL, 10)
  136.  
  137. #define STRINGIZE(a) #a
  138.  
  139. enum TimeConstants
  140. {
  141.     MINUTE          = 60,
  142.     HOUR            = MINUTE*60,
  143.     DAY             = HOUR*24,
  144.     WEEK            = DAY*7,
  145.     MONTH           = DAY*30,
  146.     YEAR            = MONTH*12,
  147.     IN_MILLISECONDS = 1000
  148. };
  149.  
  150.  enum AccountTypes
  151. {
  152.     SEC_PLAYER          = 0,
  153.     SEC_VIP             = 1,
  154.     SEC_MODERATOR       = 2,
  155.     SEC_GAMEMASTER      = 3,
  156.     SEC_EVENTGM         = 4,
  157.     SEC_HEADGM          = 5,
  158.     SEC_DEVELOPER       = 6,
  159.     SEC_ADMINISTRATOR   = 7,
  160.     SEC_CONSOLE = 8 // must be always last in list, accounts must have less security level always also
  161. };
  162.  
  163. enum LocaleConstant
  164. {
  165.     LOCALE_enUS = 0,
  166.     LOCALE_koKR = 1,
  167.     LOCALE_frFR = 2,
  168.     LOCALE_deDE = 3,
  169.     LOCALE_zhCN = 4,
  170.     LOCALE_zhTW = 5,
  171.     LOCALE_esES = 6,
  172.     LOCALE_esMX = 7,
  173.     LOCALE_ruRU = 8
  174. };
  175.  
  176. const uint8 TOTAL_LOCALES = 9;
  177. #define DEFAULT_LOCALE LOCALE_enUS
  178.  
  179. #define MAX_LOCALES 8
  180. #define MAX_ACCOUNT_TUTORIAL_VALUES 8
  181.  
  182. extern char const* localeNames[TOTAL_LOCALES];
  183.  
  184. LocaleConstant GetLocaleByName(const std::string& name);
  185.  
  186. typedef std::vector<std::string> StringVector;
  187.  
  188. // we always use stdlibc++ std::max/std::min, undefine some not C++ standard defines (Win API and some other platforms)
  189. #ifdef max
  190. #undef max
  191. #endif
  192.  
  193. #ifdef min
  194. #undef min
  195. #endif
  196.  
  197. #ifndef M_PI
  198. #define M_PI            3.14159265358979323846f
  199. #endif
  200.  
  201. #define MAX_QUERY_LEN 32*1024
  202.  
  203. #define TRINITY_GUARD(MUTEX, LOCK) \
  204.   ACE_Guard< MUTEX > TRINITY_GUARD_OBJECT (LOCK); \
  205.     if (TRINITY_GUARD_OBJECT.locked() == 0) ASSERT(false);
  206.  
  207. //! For proper implementation of multiple-read, single-write pattern, use
  208. //! ACE_RW_Mutex as underlying @MUTEX
  209. # define TRINITY_WRITE_GUARD(MUTEX, LOCK) \
  210.   ACE_Write_Guard< MUTEX > TRINITY_GUARD_OBJECT (LOCK); \
  211.     if (TRINITY_GUARD_OBJECT.locked() == 0) ASSERT(false);
  212.  
  213. //! For proper implementation of multiple-read, single-write pattern, use
  214. //! ACE_RW_Mutex as underlying @MUTEX
  215. # define TRINITY_READ_GUARD(MUTEX, LOCK) \
  216.   ACE_Read_Guard< MUTEX > TRINITY_GUARD_OBJECT (LOCK); \
  217.     if (TRINITY_GUARD_OBJECT.locked() == 0) ASSERT(false);
  218.  
  219. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement