mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-12 05:21:29 +00:00
Beginning of multi-tenancy work
This commit is contained in:
parent
240d5c2a66
commit
dde9b98e4f
@ -35,13 +35,14 @@
|
|||||||
DBcore::DBcore()
|
DBcore::DBcore()
|
||||||
{
|
{
|
||||||
mysql_init(&mysql);
|
mysql_init(&mysql);
|
||||||
pHost = 0;
|
pHost = nullptr;
|
||||||
pUser = 0;
|
pUser = nullptr;
|
||||||
pPassword = 0;
|
pPassword = nullptr;
|
||||||
pDatabase = 0;
|
pDatabase = nullptr;
|
||||||
pCompress = false;
|
pCompress = false;
|
||||||
pSSL = false;
|
pSSL = false;
|
||||||
pStatus = Closed;
|
pStatus = Closed;
|
||||||
|
connection_type = DATABASE_CONNECTION_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
DBcore::~DBcore()
|
DBcore::~DBcore()
|
||||||
@ -81,6 +82,8 @@ MySQLRequestResult DBcore::QueryDatabase(const char *query, uint32 querylen, boo
|
|||||||
Open();
|
Open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// request query. != 0 indicates some kind of error.
|
// request query. != 0 indicates some kind of error.
|
||||||
if (mysql_real_query(&mysql, query, querylen) != 0) {
|
if (mysql_real_query(&mysql, query, querylen) != 0) {
|
||||||
unsigned int errorNumber = mysql_errno(&mysql);
|
unsigned int errorNumber = mysql_errno(&mysql);
|
||||||
@ -258,6 +261,21 @@ bool DBcore::Open(uint32 *errnum, char *errbuf)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DBcore::SetMysql(MYSQL *mysql)
|
||||||
|
{
|
||||||
|
DBcore::mysql = *mysql;
|
||||||
|
}
|
||||||
|
|
||||||
|
int8 DBcore::GetConnectionType() const
|
||||||
|
{
|
||||||
|
return connection_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DBcore::SetConnectionType(int8 connection_type)
|
||||||
|
{
|
||||||
|
DBcore::connection_type = connection_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -2,8 +2,8 @@
|
|||||||
#define DBCORE_H
|
#define DBCORE_H
|
||||||
|
|
||||||
#ifdef _WINDOWS
|
#ifdef _WINDOWS
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../common/mutex.h"
|
#include "../common/mutex.h"
|
||||||
@ -13,38 +13,59 @@
|
|||||||
#include <mysql.h>
|
#include <mysql.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
const int8 DATABASE_CONNECTION_DEFAULT = 0;
|
||||||
|
const int8 DATABASE_CONNECTION_CONTENT = 1;
|
||||||
|
|
||||||
class DBcore {
|
class DBcore {
|
||||||
public:
|
public:
|
||||||
enum eStatus { Closed, Connected, Error };
|
enum eStatus {
|
||||||
|
Closed, Connected, Error
|
||||||
|
};
|
||||||
|
|
||||||
DBcore();
|
DBcore();
|
||||||
~DBcore();
|
~DBcore();
|
||||||
eStatus GetStatus() { return pStatus; }
|
eStatus GetStatus() { return pStatus; }
|
||||||
MySQLRequestResult QueryDatabase(const char* query, uint32 querylen, bool retryOnFailureOnce = true);
|
MySQLRequestResult QueryDatabase(const char *query, uint32 querylen, bool retryOnFailureOnce = true);
|
||||||
MySQLRequestResult QueryDatabase(std::string query, bool retryOnFailureOnce = true);
|
MySQLRequestResult QueryDatabase(std::string query, bool retryOnFailureOnce = true);
|
||||||
void TransactionBegin();
|
void TransactionBegin();
|
||||||
void TransactionCommit();
|
void TransactionCommit();
|
||||||
void TransactionRollback();
|
void TransactionRollback();
|
||||||
uint32 DoEscapeString(char* tobuf, const char* frombuf, uint32 fromlen);
|
uint32 DoEscapeString(char *tobuf, const char *frombuf, uint32 fromlen);
|
||||||
void ping();
|
void ping();
|
||||||
MYSQL* getMySQL(){ return &mysql; }
|
MYSQL *getMySQL() { return &mysql; }
|
||||||
|
void SetMysql(MYSQL *mysql);
|
||||||
|
|
||||||
|
int8 GetConnectionType() const;
|
||||||
|
void SetConnectionType(int8 connection_type);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool Open(const char* iHost, const char* iUser, const char* iPassword, const char* iDatabase, uint32 iPort, uint32* errnum = 0, char* errbuf = 0, bool iCompress = false, bool iSSL = false);
|
bool Open(
|
||||||
private:
|
const char *iHost,
|
||||||
bool Open(uint32* errnum = 0, char* errbuf = 0);
|
const char *iUser,
|
||||||
|
const char *iPassword,
|
||||||
|
const char *iDatabase,
|
||||||
|
uint32 iPort,
|
||||||
|
uint32 *errnum = 0,
|
||||||
|
char *errbuf = 0,
|
||||||
|
bool iCompress = false,
|
||||||
|
bool iSSL = false
|
||||||
|
);
|
||||||
|
|
||||||
MYSQL mysql;
|
private:
|
||||||
Mutex MDatabase;
|
bool Open(uint32 *errnum = nullptr, char *errbuf = nullptr);
|
||||||
|
|
||||||
|
int8 connection_type;
|
||||||
|
MYSQL mysql;
|
||||||
|
Mutex MDatabase;
|
||||||
eStatus pStatus;
|
eStatus pStatus;
|
||||||
|
|
||||||
char* pHost;
|
char *pHost;
|
||||||
char* pUser;
|
char *pUser;
|
||||||
char* pPassword;
|
char *pPassword;
|
||||||
char* pDatabase;
|
char *pDatabase;
|
||||||
bool pCompress;
|
bool pCompress;
|
||||||
uint32 pPort;
|
uint32 pPort;
|
||||||
bool pSSL;
|
bool pSSL;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -104,6 +104,15 @@ void EQEmuConfig::parse_config()
|
|||||||
DatabasePort = atoi(_root["server"]["database"].get("port", "3306").asString().c_str());
|
DatabasePort = atoi(_root["server"]["database"].get("port", "3306").asString().c_str());
|
||||||
DatabaseDB = _root["server"]["database"].get("db", "eq").asString();
|
DatabaseDB = _root["server"]["database"].get("db", "eq").asString();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Content Database
|
||||||
|
*/
|
||||||
|
ContentDbUsername = _root["server"]["content_database"].get("username", "").asString();
|
||||||
|
ContentDbPassword = _root["server"]["content_database"].get("password", "").asString();
|
||||||
|
ContentDbHost = _root["server"]["content_database"].get("host", "").asString();
|
||||||
|
ContentDbPort = atoi(_root["server"]["content_database"].get("port", 0).asString().c_str());
|
||||||
|
ContentDbName = _root["server"]["content_database"].get("db", "").asString();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* QS
|
* QS
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -74,6 +74,13 @@ class EQEmuConfig
|
|||||||
std::string DatabaseDB;
|
std::string DatabaseDB;
|
||||||
uint16 DatabasePort;
|
uint16 DatabasePort;
|
||||||
|
|
||||||
|
// From <content_database/>
|
||||||
|
std::string ContentDbHost;
|
||||||
|
std::string ContentDbUsername;
|
||||||
|
std::string ContentDbPassword;
|
||||||
|
std::string ContentDbName;
|
||||||
|
uint16 ContentDbPort;
|
||||||
|
|
||||||
// From <qsdatabase> // QueryServ
|
// From <qsdatabase> // QueryServ
|
||||||
std::string QSDatabaseHost;
|
std::string QSDatabaseHost;
|
||||||
std::string QSDatabaseUsername;
|
std::string QSDatabaseUsername;
|
||||||
|
|||||||
@ -237,6 +237,29 @@ int main(int argc, char** argv) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Multi-tenancy: Content Database
|
||||||
|
*/
|
||||||
|
if (!Config->ContentDbHost.empty()) {
|
||||||
|
if (!content_db.Connect(
|
||||||
|
!Config->ContentDbHost.empty() ? Config->ContentDbHost.c_str() : Config->DatabaseHost.c_str(),
|
||||||
|
!Config->ContentDbUsername.empty() ? Config->ContentDbUsername.c_str() : Config->DatabaseUsername.c_str(),
|
||||||
|
!Config->ContentDbPassword.empty() ? Config->ContentDbPassword.c_str() : Config->DatabasePassword.c_str(),
|
||||||
|
!Config->ContentDbName.empty() ? Config->ContentDbName.c_str() : Config->DatabaseDB.c_str(),
|
||||||
|
Config->ContentDbPort != 0 ? Config->ContentDbPort : Config->DatabasePort
|
||||||
|
)) {
|
||||||
|
LogError("Cannot continue without a content database connection");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
content_db.SetMysql(database.getMySQL());
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// auto results = content_db.QueryDatabase("SELECT id FROM items limit 10");
|
||||||
|
// for (auto row = results.begin(); row != results.end(); ++row) {
|
||||||
|
// std::cout << row[0] << std::endl;
|
||||||
|
// }
|
||||||
|
|
||||||
/* Register Log System and Settings */
|
/* Register Log System and Settings */
|
||||||
LogSys.SetGMSayHandler(&Zone::GMSayHookCallBackProcess);
|
LogSys.SetGMSayHandler(&Zone::GMSayHookCallBackProcess);
|
||||||
database.LoadLogSettings(LogSys.log_settings);
|
database.LoadLogSettings(LogSys.log_settings);
|
||||||
@ -543,6 +566,7 @@ int main(int argc, char** argv) {
|
|||||||
if (InterserverTimer.Check()) {
|
if (InterserverTimer.Check()) {
|
||||||
InterserverTimer.Start();
|
InterserverTimer.Start();
|
||||||
database.ping();
|
database.ping();
|
||||||
|
content_db.ping();
|
||||||
entity_list.UpdateWho();
|
entity_list.UpdateWho();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -20,6 +20,7 @@
|
|||||||
extern Zone* zone;
|
extern Zone* zone;
|
||||||
|
|
||||||
ZoneDatabase database;
|
ZoneDatabase database;
|
||||||
|
ZoneDatabase content_db;
|
||||||
|
|
||||||
ZoneDatabase::ZoneDatabase()
|
ZoneDatabase::ZoneDatabase()
|
||||||
: SharedDatabase()
|
: SharedDatabase()
|
||||||
|
|||||||
@ -577,6 +577,7 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
extern ZoneDatabase database;
|
extern ZoneDatabase database;
|
||||||
|
extern ZoneDatabase content_db;
|
||||||
|
|
||||||
#endif /*ZONEDB_H_*/
|
#endif /*ZONEDB_H_*/
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user