forked from metin2/server
1
0
Fork 0

Removed hotbackup

This commit is contained in:
Exynox 2024-03-30 16:17:34 +02:00
parent 0101618d89
commit 42079d56b7
5 changed files with 0 additions and 174 deletions

View File

@ -6,11 +6,8 @@
#include "Main.h"
#include "QID.h"
#include "ItemAwardManager.h"
#include "HB.h"
#include "Cache.h"
extern bool g_bHotBackup;
extern std::string g_stLocale;
extern int g_test_server;
@ -195,9 +192,6 @@ void CClientManager::PutPlayerCache(TPlayerTable * pNew)
m_map_playerCache.insert(TPlayerTableCacheMap::value_type(pNew->id, c));
}
if (g_bHotBackup)
PlayerHB::instance().Put(pNew->id);
c->Put(pNew);
}

View File

@ -23,7 +23,6 @@ enum eSQL_SLOT
SQL_PLAYER,
SQL_ACCOUNT,
SQL_COMMON,
SQL_HOTBACKUP,
SQL_MAX_NUM,
};

View File

@ -1,86 +0,0 @@
#include "stdafx.h"
#include "HB.h"
#include "Main.h"
#include "DBManager.h"
#include <memory>
PlayerHB::PlayerHB()
{
m_iExpireTime = 3600; // 1 hour hotbackup default.
}
PlayerHB::~PlayerHB()
{
}
bool PlayerHB::Initialize()
{
char szQuery[128];
snprintf(szQuery, sizeof(szQuery), "SHOW CREATE TABLE player%s", GetTablePostfix());
std::unique_ptr<SQLMsg> pMsg(CDBManager::instance().DirectQuery(szQuery));
if (pMsg->Get()->uiNumRows == 0)
return false;
MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
m_stCreateTableQuery = row[1];
return true;
}
//
// @version 05/07/05 Bang2ni - id 에 해당하는 data 가 없을 때 쿼리하고 data 를 insert 하는코드 추가.
//
void PlayerHB::Put(DWORD id)
{
itertype(m_map_data) it = m_map_data.find(id);
if (it == m_map_data.end())
{
Query(id);
m_map_data.insert(std::pair< DWORD, time_t >(id, get_dword_time()));
return;
}
if (time(0) - it->second > m_iExpireTime)
Query(id);
}
//
// @version 05/07/05 Bang2ni - Query string 버퍼가 작아서 늘려줌.
//
bool PlayerHB::Query(DWORD id)
{
time_t ct = time(0);
struct tm curr_tm = *localtime(&ct);
char szTableName[64];
snprintf(szTableName, sizeof(szTableName), "hb_%02d%02d%02d%02d_player%s",
curr_tm.tm_year - 100, curr_tm.tm_mon + 1, curr_tm.tm_mday, curr_tm.tm_hour, GetTablePostfix());
char szQuery[4096];
if (m_stTableName.compare(szTableName))
{
char szFind[32];
snprintf(szFind, sizeof(szFind), "CREATE TABLE `player%s`", GetTablePostfix());
int pos = m_stCreateTableQuery.find(szFind);
if (pos < 0)
{
SPDLOG_ERROR("cannot find {} ", szFind);
// SPDLOG_ERROR("cannot find {} in {}", szFind, m_stCreateTableQuery.c_str());
return false;
}
snprintf(szQuery, sizeof(szQuery), "CREATE TABLE IF NOT EXISTS %s%s", szTableName, m_stCreateTableQuery.c_str() + strlen(szFind));
// SPDLOG_DEBUG("{}", szQuery);
std::unique_ptr<SQLMsg> pMsg(CDBManager::instance().DirectQuery(szQuery, SQL_HOTBACKUP));
m_stTableName = szTableName;
}
snprintf(szQuery, sizeof(szQuery), "REPLACE INTO %s SELECT * FROM %splayer%s WHERE id=%u", m_stTableName.c_str(), GetPlayerDBName(), GetTablePostfix(), id);
CDBManager::instance().AsyncQuery(szQuery, SQL_HOTBACKUP);
return true;
}

View File

@ -1,24 +0,0 @@
// vim:ts=8 sw=4
#ifndef __INC_METIN_II_PLAYERHB_H__
#define __INC_METIN_II_PLAYERHB_H__
class PlayerHB : public singleton<PlayerHB>
{
public:
PlayerHB();
virtual ~PlayerHB();
bool Initialize();
void Put(DWORD id);
private:
bool Query(DWORD id);
std::map<DWORD, time_t> m_map_data;
std::string m_stCreateTableQuery;
std::string m_stTableName;
int m_iExpireTime;
};
#endif

View File

@ -5,7 +5,6 @@
#include "ClientManager.h"
#include "GuildManager.h"
#include "ItemAwardManager.h"
#include "HB.h"
#include "PrivManager.h"
#include "MoneyLog.h"
#include "Marriage.h"
@ -28,7 +27,6 @@ std::string g_stLocale = "euckr";
std::string g_stPlayerDBName = "";
bool g_bHotBackup = false;
BOOL g_test_server = false;
//´ÜÀ§ ÃÊ
@ -70,7 +68,6 @@ int main()
CConfig Config;
CDBManager DBManager;
CClientManager ClientManager;
PlayerHB player_hb;
CGuildManager GuildManager;
CPrivManager PrivManager;
CMoneyLog MoneyLog;
@ -170,27 +167,8 @@ int Start()
{
g_stLocale = szBuf;
SPDLOG_INFO("LOCALE set to {}", g_stLocale.c_str());
// CHINA_DISABLE_HOTBACKUP
if ("gb2312" == g_stLocale)
{
SPDLOG_INFO("CIBN_LOCALE: DISABLE_HOTBACKUP");
g_bHotBackup = false;
}
// END_OF_CHINA_DISABLE_HOTBACKUP
}
int iDisableHotBackup;
if (CConfig::instance().GetValue("DISABLE_HOTBACKUP", &iDisableHotBackup))
{
if (iDisableHotBackup)
{
SPDLOG_INFO("CONFIG: DISABLE_HOTBACKUP");
g_bHotBackup = false;
}
}
if (!CConfig::instance().GetValue("TABLE_POSTFIX", szBuf, 256))
{
SPDLOG_WARN("TABLE_POSTFIX not configured use default");
@ -324,35 +302,6 @@ int Start()
return false;
}
if (CConfig::instance().GetValue("SQL_HOTBACKUP", line, 256))
{
sscanf(line, " %s %s %s %s %d ", szAddr, szDB, szUser, szPassword, &iPort);
SPDLOG_DEBUG("connecting to MySQL server (hotbackup)");
int iRetry = 5;
do
{
if (CDBManager::instance().Connect(SQL_HOTBACKUP, 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 HOTBACKUP");
}
else
{
SPDLOG_ERROR("SQL_HOTBACKUP not configured");
return false;
}
if (!CClientManager::instance().Initialize())
{
SPDLOG_ERROR("ClientManager initialization failed");
@ -361,12 +310,6 @@ int Start()
SPDLOG_INFO("ClientManager initialization OK");
if (!PlayerHB::instance().Initialize())
{
SPDLOG_ERROR("cannot initialize player hotbackup");
return false;
}
#ifndef __WIN32__
signal(SIGUSR1, emergency_sig);
#endif