types.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator 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. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef TYPES_H
  17. #define TYPES_H
  18. #include <string>
  19. using namespace std;
  20. //atoi is not int32 or uint32 safe!!!!
  21. #define atoul(str) strtoul(str, NULL, 10)
  22. #ifdef WIN32
  23. #define atoi64(str) _atoi64(str)
  24. #else
  25. #define atoi64(str) strtoll(str, NULL, 10)
  26. #endif
  27. typedef unsigned char int8;
  28. typedef unsigned short int16;
  29. typedef unsigned int int32;
  30. typedef unsigned char uint8;
  31. typedef signed char sint8;
  32. typedef unsigned short uint16;
  33. typedef signed short sint16;
  34. typedef unsigned int uint32;
  35. typedef signed int sint32;
  36. #ifdef WIN32
  37. #if defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 64
  38. typedef unsigned __int64 int64;
  39. typedef unsigned __int64 uint64;
  40. typedef signed __int64 sint64;
  41. #else
  42. #error __int64 not supported
  43. #endif
  44. #else
  45. typedef unsigned long long int64;
  46. typedef unsigned long long uint64;
  47. typedef signed long long sint64;
  48. //typedef __u64 int64;
  49. //typedef __u64 uint64;
  50. //typedef __s64 sint64;
  51. #endif
  52. typedef unsigned long ulong;
  53. typedef unsigned short ushort;
  54. typedef unsigned char uchar;
  55. #ifdef WIN32
  56. #define snprintf _snprintf
  57. #define vsnprintf _vsnprintf
  58. #define strncasecmp _strnicmp
  59. #define strcasecmp _stricmp
  60. typedef void ThreadReturnType;
  61. // #define THREAD_RETURN(x) return;
  62. #define THREAD_RETURN(x) _endthread(); return;
  63. #else
  64. typedef void* ThreadReturnType;
  65. typedef int SOCKET;
  66. #define THREAD_RETURN(x) return(x);
  67. #endif
  68. #define safe_delete(d) if(d) { delete d; d=0; }
  69. #define safe_delete_array(d) if(d) { delete[] d; d=0; }
  70. #define L32(i) ((int32) i)
  71. #define H32(i) ((int32) (i >> 32))
  72. #define L16(i) ((int16) i)
  73. #ifndef WIN32
  74. // More WIN32 compatability
  75. typedef unsigned long DWORD;
  76. typedef unsigned char BYTE;
  77. typedef char CHAR;
  78. typedef unsigned short WORD;
  79. typedef float FLOAT;
  80. typedef FLOAT *PFLOAT;
  81. typedef BYTE *PBYTE,*LPBYTE;
  82. typedef int *PINT,*LPINT;
  83. typedef WORD *PWORD,*LPWORD;
  84. typedef long *LPLONG, LONG;
  85. typedef DWORD *PDWORD,*LPDWORD;
  86. typedef int INT;
  87. typedef unsigned int UINT,*PUINT,*LPUINT;
  88. #endif
  89. #ifdef WIN32
  90. #define DLLFUNC extern "C" __declspec(dllexport)
  91. #else
  92. #define DLLFUNC extern "C"
  93. #endif
  94. #pragma pack(1)
  95. struct uint16_breakdown {
  96. union {
  97. uint16 all;
  98. struct {
  99. uint8 b1;
  100. uint8 b2;
  101. } bytes;
  102. };
  103. inline uint16& operator=(const uint16& val) { return (all=val); }
  104. inline uint16* operator&() { return &all; }
  105. inline operator uint16&() { return all; }
  106. inline uint8& b1() { return bytes.b1; }
  107. inline uint8& b2() { return bytes.b2; }
  108. };
  109. struct uint32_breakdown {
  110. union {
  111. uint32 all;
  112. struct {
  113. uint16 w1;
  114. uint16 w2;
  115. } words;
  116. struct {
  117. uint8 b1;
  118. union {
  119. struct {
  120. uint8 b2;
  121. uint8 b3;
  122. } middle;
  123. uint16 w2_3; // word bytes 2 to 3
  124. };
  125. uint8 b4;
  126. } bytes;
  127. };
  128. inline uint32& operator=(const uint32& val) { return (all=val); }
  129. inline uint32* operator&() { return &all; }
  130. inline operator uint32&() { return all; }
  131. inline uint16& w1() { return words.w1; }
  132. inline uint16& w2() { return words.w2; }
  133. inline uint16& w2_3() { return bytes.w2_3; }
  134. inline uint8& b1() { return bytes.b1; }
  135. inline uint8& b2() { return bytes.middle.b2; }
  136. inline uint8& b3() { return bytes.middle.b3; }
  137. inline uint8& b4() { return bytes.b4; }
  138. };
  139. struct EQ2_32BitString{
  140. int32 size;
  141. string data;
  142. };
  143. struct EQ2_16BitString{
  144. int16 size;
  145. string data;
  146. };
  147. struct EQ2_8BitString{
  148. int8 size;
  149. string data;
  150. };
  151. struct EQ2_Color{
  152. int8 red;
  153. int8 green;
  154. int8 blue;
  155. };
  156. struct WorldTime{
  157. int16 year;
  158. int month;
  159. int day;
  160. int hour;
  161. int minute;
  162. };
  163. typedef enum QUERY_TYPE{ Q_SELECT, Q_UPDATE, Q_REPLACE, Q_INSERT, Q_DELETE, Q_DBMS} QUERY_TYPE;
  164. #pragma pack()
  165. #endif