63 lines
1.7 KiB
C++
63 lines
1.7 KiB
C++
// Copyright (C) 2007-2025 EQ2EMulator
|
|
// Licensed under GPL v3
|
|
#ifndef DBCORE_H
|
|
#define DBCORE_H
|
|
|
|
#ifdef WIN32
|
|
#include <WinSock2.h>
|
|
#include <windows.h>
|
|
//#include <WinSock2.h>
|
|
#endif
|
|
#include <mysql.h>
|
|
#include "../common/types.h"
|
|
#include "../common/Mutex.h"
|
|
#include "../common/linked_list.h"
|
|
#include "../common/queue.h"
|
|
#include "../common/timer.h"
|
|
#ifdef LOGIN
|
|
#define DB_INI_FILE "login_db.ini"
|
|
#endif
|
|
#ifdef WORLD
|
|
#define DB_INI_FILE "world_db.ini"
|
|
#endif
|
|
#ifdef PARSER
|
|
#define DB_INI_FILE "parser_db.ini"
|
|
#endif
|
|
#ifdef PATCHER
|
|
#define DB_INI_FILE "patcher_db.ini"
|
|
#endif
|
|
class DBcore{
|
|
public:
|
|
enum eStatus { Closed, Connected, Error };
|
|
DBcore();
|
|
~DBcore();
|
|
eStatus GetStatus() { return pStatus; }
|
|
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);
|
|
int32 DoEscapeString(char* tobuf, const char* frombuf, int32 fromlen);
|
|
void ping();
|
|
char* getEscapeString(const char* from_string);
|
|
string getSafeEscapeString(const char* from_string);
|
|
string getSafeEscapeString(string* from_string);
|
|
|
|
protected:
|
|
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);
|
|
bool ReadDBINI(char *host, char *user, char *pass, char *db, unsigned int* port, bool* compress, bool *items);
|
|
private:
|
|
bool Open(int32* errnum = 0, char* errbuf = 0);
|
|
|
|
MYSQL mysql;
|
|
Mutex MDatabase;
|
|
eStatus pStatus;
|
|
|
|
char* pHost;
|
|
char* pUser;
|
|
char* pPassword;
|
|
char* pDatabase;
|
|
bool pCompress;
|
|
int32 pPort;
|
|
bool pSSL;
|
|
};
|
|
#endif
|
|
|
|
|