Advertisement
Guest User

Untitled

a guest
Nov 13th, 2023
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.32 KB | None | 0 0
  1. #ifndef __INC_METIN_II_DB_MANAGER_H__
  2. #define __INC_METIN_II_DB_MANAGER_H__
  3.  
  4. #include "../../libsql/AsyncSQL.h"
  5. #include "any_function.h"
  6.  
  7. enum
  8. {
  9. QUERY_TYPE_RETURN = 1,
  10. QUERY_TYPE_FUNCTION = 2,
  11. QUERY_TYPE_AFTER_FUNCTION = 3,
  12. };
  13.  
  14. enum
  15. {
  16. QID_SAFEBOX_SIZE,
  17. QID_DB_STRING,
  18. QID_AUTH_LOGIN,
  19. QID_LOTTO,
  20. QID_HIGHSCORE_REGISTER,
  21. QID_HIGHSCORE_SHOW,
  22. QID_BILLING_GET_TIME,
  23. QID_BILLING_CHECK,
  24.  
  25. // BLOCK_CHAT
  26. QID_BLOCK_CHAT_LIST,
  27. // END_OF_BLOCK_CHAT
  28.  
  29. // PCBANG_IP_LIST
  30. QID_PCBANG_IP_LIST_CHECK,
  31. QID_PCBANG_IP_LIST_SELECT,
  32. // END_OF_PCBANG_IP_LIST
  33.  
  34. // PROTECT_CHILD_FOR_NEWCIBN
  35. QID_PROTECT_CHILD,
  36. // END_PROTECT_CHILD_FOR_NEWCIBN
  37.  
  38. QID_BRAZIL_CREATE_ID,
  39. };
  40.  
  41. typedef struct SUseTime
  42. {
  43. DWORD dwLoginKey;
  44. char szLogin[LOGIN_MAX_LEN+1];
  45. BYTE bBillType;
  46. DWORD dwUseSec;
  47. char szIP[MAX_HOST_LENGTH+1];
  48. } TUseTime;
  49.  
  50. class CQueryInfo
  51. {
  52. public:
  53. int iQueryType;
  54. };
  55.  
  56. class CReturnQueryInfo : public CQueryInfo
  57. {
  58. public:
  59. int iType;
  60. DWORD dwIdent;
  61. void * pvData;
  62. };
  63.  
  64. class CFuncQueryInfo : public CQueryInfo
  65. {
  66. public:
  67. any_function f;
  68. };
  69.  
  70. class CFuncAfterQueryInfo : public CQueryInfo
  71. {
  72. public:
  73. any_void_function f;
  74. };
  75.  
  76. class CLoginData;
  77.  
  78.  
  79. class DBManager : public singleton<DBManager>
  80. {
  81. public:
  82. DBManager();
  83. virtual ~DBManager();
  84.  
  85. bool IsConnected();
  86.  
  87. bool Connect(const char * host, const int port, const char * user, const char * pwd, const char * db);
  88. void Query(const char * c_pszFormat, ...);
  89.  
  90. SQLMsg * DirectQuery(const char * c_pszFormat, ...);
  91. void ReturnQuery(int iType, DWORD dwIdent, void* pvData, const char * c_pszFormat, ...);
  92.  
  93. void Process();
  94. void AnalyzeReturnQuery(SQLMsg * pmsg);
  95.  
  96. void SendMoneyLog(BYTE type, DWORD vnum, int gold);
  97.  
  98. void LoginPrepare(BYTE bBillType, DWORD dwBillID, long lRemainSecs, LPDESC d, DWORD * pdwClientKey, int * paiPremiumTimes = NULL);
  99. void SendAuthLogin(LPDESC d);
  100. void SendLoginPing(const char * c_pszLogin);
  101.  
  102. void InsertLoginData(CLoginData * pkLD);
  103. void DeleteLoginData(CLoginData * pkLD);
  104. CLoginData * GetLoginData(DWORD dwKey);
  105. void SetBilling(DWORD dwKey, bool bOn, bool bSkipPush = false);
  106. void PushBilling(CLoginData * pkLD);
  107. void FlushBilling(bool bForce=false);
  108. void CheckBilling();
  109.  
  110. void StopAllBilling();
  111.  
  112. DWORD CountQuery() { return m_sql.CountQuery(); }
  113. DWORD CountQueryResult() { return m_sql.CountResult(); }
  114. void ResetQueryResult() { m_sql.ResetQueryFinished(); }
  115.  
  116. // BLOCK EXCEPTION
  117. void RequestBlockException(const char *login, int cmd);
  118. // BLOCK EXCEPTION
  119.  
  120. void LoadDBString();
  121. const std::string & GetDBString(const std::string& key);
  122. const std::vector<std::string> & GetGreetMessage();
  123.  
  124. template<class Functor> void FuncQuery(Functor f, const char * c_pszFormat, ...);
  125. template<class Functor> void FuncAfterQuery(Functor f, const char * c_pszFormat, ...);
  126.  
  127. size_t EscapeString(char* dst, size_t dstSize, const char *src, size_t srcSize);
  128.  
  129. private:
  130. SQLMsg * PopResult();
  131.  
  132. CAsyncSQL m_sql;
  133. CAsyncSQL m_sql_direct;
  134. bool m_bIsConnect;
  135.  
  136. std::map<std::string, std::string> m_map_dbstring;
  137. std::vector<std::string> m_vec_GreetMessage;
  138. std::map<DWORD, CLoginData *> m_map_pkLoginData;
  139. std::map<std::string, CLoginData *> mapLDBilling;
  140. std::vector<TUseTime> m_vec_kUseTime;
  141. };
  142.  
  143. template <class Functor> void DBManager::FuncQuery(Functor f, const char* c_pszFormat, ...)
  144. {
  145. char szQuery[4096];
  146. va_list args;
  147.  
  148. va_start(args, c_pszFormat);
  149. vsnprintf(szQuery, 4096, c_pszFormat, args);
  150. va_end(args);
  151.  
  152. CFuncQueryInfo * p = M2_NEW CFuncQueryInfo;
  153.  
  154. p->iQueryType = QUERY_TYPE_FUNCTION;
  155. p->f = f;
  156.  
  157. m_sql.ReturnQuery(szQuery, p);
  158. }
  159.  
  160. template <class Functor> void DBManager::FuncAfterQuery(Functor f, const char* c_pszFormat, ...)
  161. {
  162. char szQuery[4096];
  163. va_list args;
  164.  
  165. va_start(args, c_pszFormat);
  166. vsnprintf(szQuery, 4096, c_pszFormat, args);
  167. va_end(args);
  168.  
  169. CFuncAfterQueryInfo * p = M2_NEW CFuncAfterQueryInfo;
  170.  
  171. p->iQueryType = QUERY_TYPE_AFTER_FUNCTION;
  172. p->f = f;
  173.  
  174. m_sql.ReturnQuery(szQuery, p);
  175. }
  176.  
  177. ////////////////////////////////////////////////////////////////
  178. typedef struct SHighscoreRegisterQueryInfo
  179. {
  180. char szBoard[20+1];
  181. DWORD dwPID;
  182. int iValue;
  183. bool bOrder;
  184. } THighscoreRegisterQueryInfo;
  185.  
  186. extern void SendBillingExpire(const char * c_pszLogin, BYTE bBillType, int iSecs, CLoginData * pkLD);
  187. extern void VCardUse(LPCHARACTER CardOwner, LPCHARACTER CardTaker, LPITEM item);
  188.  
  189.  
  190. // ACCOUNT_DB
  191. class AccountDB : public singleton<AccountDB>
  192. {
  193. public:
  194. AccountDB();
  195.  
  196. bool IsConnected();
  197. bool Connect(const char * host, const int port, const char * user, const char * pwd, const char * db);
  198. bool ConnectAsync(const char * host, const int port, const char * user, const char * pwd, const char * db, const char * locale);
  199.  
  200. SQLMsg* DirectQuery(const char * query);
  201. void ReturnQuery(int iType, DWORD dwIdent, void * pvData, const char * c_pszFormat, ...);
  202. void AsyncQuery(const char* query);
  203.  
  204. void SetLocale(const std::string & stLocale);
  205.  
  206. void Process();
  207.  
  208. private:
  209. SQLMsg * PopResult();
  210. void AnalyzeReturnQuery(SQLMsg * pMsg);
  211.  
  212. CAsyncSQL2 m_sql_direct;
  213. CAsyncSQL2 m_sql;
  214. bool m_IsConnect;
  215.  
  216. };
  217. //END_ACCOUNT_DB
  218.  
  219. #endif
  220.  
  221.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement