Fixed db crash when MySQL connection wasn't possible
This commit is contained in:
parent
c6177d9c73
commit
7cc9550efc
|
@ -381,8 +381,8 @@ class CClientManager : public singleton<CClientManager>
|
|||
|
||||
private:
|
||||
int m_looping;
|
||||
event_base * m_base;
|
||||
evconnlistener * m_listener;
|
||||
event_base * m_base = nullptr;
|
||||
evconnlistener * m_listener = nullptr;
|
||||
TPeerList m_peerList;
|
||||
|
||||
CPeer * m_pkAuthPeer;
|
||||
|
|
|
@ -16,14 +16,12 @@
|
|||
#endif
|
||||
#include <signal.h>
|
||||
|
||||
void SetPlayerDBName(const char* c_pszPlayerDBName);
|
||||
void SetTablePostfix(const char* c_pszTablePostfix);
|
||||
int Start();
|
||||
|
||||
std::string g_stTablePostfix;
|
||||
std::string g_stLocaleNameColumn = "name";
|
||||
std::string g_stLocale = "euckr";
|
||||
std::string g_stPlayerDBName = "";
|
||||
|
||||
|
||||
BOOL g_test_server = false;
|
||||
|
@ -95,7 +93,7 @@ int main()
|
|||
DBManager.Quit();
|
||||
int iCount;
|
||||
|
||||
while (1)
|
||||
while (true)
|
||||
{
|
||||
iCount = 0;
|
||||
|
||||
|
@ -219,83 +217,56 @@ int Start()
|
|||
int iPort;
|
||||
char line[256+1];
|
||||
|
||||
if (CConfig::instance().GetValue("SQL_PLAYER", line, 256))
|
||||
{
|
||||
if (CConfig::instance().GetValue("SQL_PLAYER", line, 256)) {
|
||||
sscanf(line, " %s %s %s %s %d ", szAddr, szDB, szUser, szPassword, &iPort);
|
||||
SPDLOG_DEBUG("Connecting to MySQL server (player)");
|
||||
|
||||
int iRetry = 5;
|
||||
if (!CDBManager::instance().Connect(SQL_PLAYER, szAddr, iPort, szDB, szUser, szPassword)) {
|
||||
SPDLOG_CRITICAL("Connection to MySQL server (player) failed!");
|
||||
return false;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
if (CDBManager::instance().Connect(SQL_PLAYER, szAddr, iPort, szDB, szUser, szPassword))
|
||||
{
|
||||
SPDLOG_INFO("Connected to MySQL server (player)");
|
||||
break;
|
||||
}
|
||||
|
||||
SPDLOG_ERROR("Connection to MySQL server (player) failed, retrying in 5 seconds");
|
||||
sleep(5);
|
||||
} while (iRetry--);
|
||||
SetPlayerDBName(szDB);
|
||||
SPDLOG_INFO("Connected to MySQL server (player)");
|
||||
}
|
||||
else
|
||||
{
|
||||
SPDLOG_ERROR("SQL_PLAYER not configured");
|
||||
else {
|
||||
SPDLOG_CRITICAL("SQL_PLAYER not configured");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (CConfig::instance().GetValue("SQL_ACCOUNT", line, 256))
|
||||
{
|
||||
if (CConfig::instance().GetValue("SQL_ACCOUNT", line, 256)) {
|
||||
sscanf(line, " %s %s %s %s %d ", szAddr, szDB, szUser, szPassword, &iPort);
|
||||
SPDLOG_DEBUG("connecting to MySQL server (account)");
|
||||
SPDLOG_DEBUG("Connecting to MySQL server (account)");
|
||||
|
||||
int iRetry = 5;
|
||||
if (!CDBManager::instance().Connect(SQL_ACCOUNT, szAddr, iPort, szDB, szUser, szPassword)) {
|
||||
SPDLOG_CRITICAL("Connection to MySQL server (account) failed!");
|
||||
return false;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
if (CDBManager::instance().Connect(SQL_ACCOUNT, szAddr, iPort, szDB, szUser, szPassword))
|
||||
{
|
||||
SPDLOG_DEBUG(" OK");
|
||||
break;
|
||||
}
|
||||
|
||||
SPDLOG_DEBUG(" failed, retrying in 5 seconds");
|
||||
SPDLOG_ERROR(" failed, retrying in 5 seconds");
|
||||
sleep(5);
|
||||
} while (iRetry--);
|
||||
SPDLOG_INFO("Success ACCOUNT");
|
||||
SPDLOG_INFO("Connected to MySQL server (account)");
|
||||
}
|
||||
else
|
||||
{
|
||||
SPDLOG_ERROR("SQL_ACCOUNT not configured");
|
||||
SPDLOG_CRITICAL("SQL_ACCOUNT not configured");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (CConfig::instance().GetValue("SQL_COMMON", line, 256))
|
||||
{
|
||||
sscanf(line, " %s %s %s %s %d ", szAddr, szDB, szUser, szPassword, &iPort);
|
||||
SPDLOG_DEBUG("connecting to MySQL server (common)");
|
||||
SPDLOG_DEBUG("Connecting to MySQL server (common)");
|
||||
|
||||
int iRetry = 5;
|
||||
|
||||
do
|
||||
if (!CDBManager::instance().Connect(SQL_COMMON, szAddr, iPort, szDB, szUser, szPassword))
|
||||
{
|
||||
if (CDBManager::instance().Connect(SQL_COMMON, szAddr, iPort, szDB, szUser, szPassword))
|
||||
{
|
||||
SPDLOG_DEBUG(" OK");
|
||||
break;
|
||||
}
|
||||
SPDLOG_CRITICAL("Connection to MySQL server (common) failed!");
|
||||
return false;
|
||||
}
|
||||
|
||||
SPDLOG_DEBUG(" failed, retrying in 5 seconds");
|
||||
SPDLOG_ERROR(" failed, retrying in 5 seconds");
|
||||
sleep(5);
|
||||
} while (iRetry--);
|
||||
SPDLOG_INFO("Success COMMON");
|
||||
SPDLOG_INFO("Connected to MySQL server (common)");
|
||||
}
|
||||
else
|
||||
{
|
||||
SPDLOG_ERROR("SQL_COMMON not configured");
|
||||
SPDLOG_CRITICAL("SQL_COMMON not configured");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -326,20 +297,3 @@ const char * GetTablePostfix()
|
|||
{
|
||||
return g_stTablePostfix.c_str();
|
||||
}
|
||||
|
||||
void SetPlayerDBName(const char* c_pszPlayerDBName)
|
||||
{
|
||||
if (! c_pszPlayerDBName || ! *c_pszPlayerDBName)
|
||||
g_stPlayerDBName = "";
|
||||
else
|
||||
{
|
||||
g_stPlayerDBName = c_pszPlayerDBName;
|
||||
g_stPlayerDBName += ".";
|
||||
}
|
||||
}
|
||||
|
||||
const char * GetPlayerDBName()
|
||||
{
|
||||
return g_stPlayerDBName.c_str();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue