9
3

dbcore.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 DBCORE_H
  17. #define DBCORE_H
  18. #ifdef WIN32
  19. #include <WinSock2.h>
  20. #include <windows.h>
  21. //#include <WinSock2.h>
  22. #endif
  23. #include <mysql.h>
  24. #include "../common/types.h"
  25. #include "../common/Mutex.h"
  26. #include "../common/linked_list.h"
  27. #include "../common/queue.h"
  28. #include "../common/timer.h"
  29. #include "../common/Condition.h"
  30. #ifdef LOGIN
  31. #define DB_INI_FILE "login_db.ini"
  32. #endif
  33. #ifdef WORLD
  34. #define DB_INI_FILE "world_db.ini"
  35. #endif
  36. #ifdef PARSER
  37. #define DB_INI_FILE "parser_db.ini"
  38. #endif
  39. #ifdef PATCHER
  40. #define DB_INI_FILE "patcher_db.ini"
  41. #endif
  42. class DBcore{
  43. public:
  44. enum eStatus { Closed, Connected, Error };
  45. DBcore();
  46. ~DBcore();
  47. eStatus GetStatus() { return pStatus; }
  48. bool RunQuery(const char* query, int32 querylen, char* errbuf = 0, MYSQL_RES** result = 0, int32* affected_rows = 0, int32* last_insert_id = 0, int32* errnum = 0, bool retry = true);
  49. int32 DoEscapeString(char* tobuf, const char* frombuf, int32 fromlen);
  50. void ping();
  51. char* getEscapeString(const char* from_string);
  52. string getSafeEscapeString(const char* from_string);
  53. string getSafeEscapeString(string* from_string);
  54. protected:
  55. bool Open(const char* iHost, const char* iUser, const char* iPassword, const char* iDatabase, int32 iPort, int32* errnum = 0, char* errbuf = 0, bool iCompress = false, bool iSSL = false);
  56. bool ReadDBINI(char *host, char *user, char *pass, char *db, unsigned int* port, bool* compress, bool *items);
  57. private:
  58. bool Open(int32* errnum = 0, char* errbuf = 0);
  59. MYSQL mysql;
  60. Mutex MDatabase;
  61. eStatus pStatus;
  62. char* pHost;
  63. char* pUser;
  64. char* pPassword;
  65. char* pDatabase;
  66. bool pCompress;
  67. int32 pPort;
  68. bool pSSL;
  69. };
  70. #endif