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()
|
||||
{
|
||||
mysql_init(&mysql);
|
||||
pHost = 0;
|
||||
pUser = 0;
|
||||
pPassword = 0;
|
||||
pDatabase = 0;
|
||||
pCompress = false;
|
||||
pSSL = false;
|
||||
pStatus = Closed;
|
||||
pHost = nullptr;
|
||||
pUser = nullptr;
|
||||
pPassword = nullptr;
|
||||
pDatabase = nullptr;
|
||||
pCompress = false;
|
||||
pSSL = false;
|
||||
pStatus = Closed;
|
||||
connection_type = DATABASE_CONNECTION_DEFAULT;
|
||||
}
|
||||
|
||||
DBcore::~DBcore()
|
||||
@ -81,6 +82,8 @@ MySQLRequestResult DBcore::QueryDatabase(const char *query, uint32 querylen, boo
|
||||
Open();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// request query. != 0 indicates some kind of error.
|
||||
if (mysql_real_query(&mysql, query, querylen) != 0) {
|
||||
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
|
||||
|
||||
#ifdef _WINDOWS
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "../common/mutex.h"
|
||||
@ -13,38 +13,59 @@
|
||||
#include <mysql.h>
|
||||
#include <string.h>
|
||||
|
||||
const int8 DATABASE_CONNECTION_DEFAULT = 0;
|
||||
const int8 DATABASE_CONNECTION_CONTENT = 1;
|
||||
|
||||
class DBcore {
|
||||
public:
|
||||
enum eStatus { Closed, Connected, Error };
|
||||
enum eStatus {
|
||||
Closed, Connected, Error
|
||||
};
|
||||
|
||||
DBcore();
|
||||
~DBcore();
|
||||
eStatus GetStatus() { return pStatus; }
|
||||
MySQLRequestResult QueryDatabase(const char* query, uint32 querylen, bool retryOnFailureOnce = true);
|
||||
MySQLRequestResult QueryDatabase(std::string query, bool retryOnFailureOnce = true);
|
||||
eStatus GetStatus() { return pStatus; }
|
||||
MySQLRequestResult QueryDatabase(const char *query, uint32 querylen, bool retryOnFailureOnce = true);
|
||||
MySQLRequestResult QueryDatabase(std::string query, bool retryOnFailureOnce = true);
|
||||
void TransactionBegin();
|
||||
void TransactionCommit();
|
||||
void TransactionRollback();
|
||||
uint32 DoEscapeString(char* tobuf, const char* frombuf, uint32 fromlen);
|
||||
void ping();
|
||||
MYSQL* getMySQL(){ return &mysql; }
|
||||
uint32 DoEscapeString(char *tobuf, const char *frombuf, uint32 fromlen);
|
||||
void ping();
|
||||
MYSQL *getMySQL() { return &mysql; }
|
||||
void SetMysql(MYSQL *mysql);
|
||||
|
||||
int8 GetConnectionType() const;
|
||||
void SetConnectionType(int8 connection_type);
|
||||
|
||||
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);
|
||||
private:
|
||||
bool Open(uint32* errnum = 0, char* errbuf = 0);
|
||||
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
|
||||
);
|
||||
|
||||
MYSQL mysql;
|
||||
Mutex MDatabase;
|
||||
private:
|
||||
bool Open(uint32 *errnum = nullptr, char *errbuf = nullptr);
|
||||
|
||||
int8 connection_type;
|
||||
MYSQL mysql;
|
||||
Mutex MDatabase;
|
||||
eStatus pStatus;
|
||||
|
||||
char* pHost;
|
||||
char* pUser;
|
||||
char* pPassword;
|
||||
char* pDatabase;
|
||||
bool pCompress;
|
||||
uint32 pPort;
|
||||
bool pSSL;
|
||||
char *pHost;
|
||||
char *pUser;
|
||||
char *pPassword;
|
||||
char *pDatabase;
|
||||
bool pCompress;
|
||||
uint32 pPort;
|
||||
bool pSSL;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -104,6 +104,15 @@ void EQEmuConfig::parse_config()
|
||||
DatabasePort = atoi(_root["server"]["database"].get("port", "3306").asString().c_str());
|
||||
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
|
||||
*/
|
||||
|
||||
@ -74,6 +74,13 @@ class EQEmuConfig
|
||||
std::string DatabaseDB;
|
||||
uint16 DatabasePort;
|
||||
|
||||
// From <content_database/>
|
||||
std::string ContentDbHost;
|
||||
std::string ContentDbUsername;
|
||||
std::string ContentDbPassword;
|
||||
std::string ContentDbName;
|
||||
uint16 ContentDbPort;
|
||||
|
||||
// From <qsdatabase> // QueryServ
|
||||
std::string QSDatabaseHost;
|
||||
std::string QSDatabaseUsername;
|
||||
|
||||
@ -237,6 +237,29 @@ int main(int argc, char** argv) {
|
||||
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 */
|
||||
LogSys.SetGMSayHandler(&Zone::GMSayHookCallBackProcess);
|
||||
database.LoadLogSettings(LogSys.log_settings);
|
||||
@ -543,6 +566,7 @@ int main(int argc, char** argv) {
|
||||
if (InterserverTimer.Check()) {
|
||||
InterserverTimer.Start();
|
||||
database.ping();
|
||||
content_db.ping();
|
||||
entity_list.UpdateWho();
|
||||
}
|
||||
};
|
||||
|
||||
@ -20,6 +20,7 @@
|
||||
extern Zone* zone;
|
||||
|
||||
ZoneDatabase database;
|
||||
ZoneDatabase content_db;
|
||||
|
||||
ZoneDatabase::ZoneDatabase()
|
||||
: SharedDatabase()
|
||||
|
||||
@ -577,6 +577,7 @@ protected:
|
||||
};
|
||||
|
||||
extern ZoneDatabase database;
|
||||
extern ZoneDatabase content_db;
|
||||
|
||||
#endif /*ZONEDB_H_*/
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user