Restructure repository to include all source folders
Move git root from Client/ to src/ to track all source code: - Client: Game client source (moved to Client/Client/) - Server: Game server source - GameTools: Development tools - CryptoSource: Encryption utilities - database: Database scripts - Script: Game scripts - rylCoder_16.02.2008_src: Legacy coder tools - GMFont, Game: Additional resources 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
425
Server/DBProcess/ConvertAccessory/ConvertAccessory.cpp
Normal file
425
Server/DBProcess/ConvertAccessory/ConvertAccessory.cpp
Normal file
@@ -0,0 +1,425 @@
|
||||
// ConvertAccessory.cpp : <20>ܼ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD>α<CEB1><D7B7><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>մϴ<D5B4>.
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include <RylDBLibrary/RylDBLibrary.h>
|
||||
#include <RylDBLibrary/RylDBStoreCommand.h>
|
||||
#include <RylDBLibrary/RylDBCharCommand.h>
|
||||
#include <Log/ServerLog.h>
|
||||
#include <Utility/TokenlizedFile.h>
|
||||
#include <Item/Item.h>
|
||||
|
||||
CServerLog g_ItemLog("ConvertAccessory");
|
||||
|
||||
#define LOG_CONVERT0(str) { ERRLOG0(g_Log, (str)); printf(str "\n"); }
|
||||
#define LOG_CONVERT1(str, arg1) { ERRLOG1(g_Log, (str), (arg1)); printf(str "\n", (arg1)); }
|
||||
#define LOG_CONVERT2(str, arg1, arg2) { ERRLOG2(g_Log, (str), (arg1), (arg2)); printf(str "\n", (arg1), (arg2)); }
|
||||
|
||||
class CDBConvertAccessory : public IDBCharItemProcess, public IDBCharItemExProcess, public IDBStoreProcess
|
||||
{
|
||||
public:
|
||||
|
||||
struct ConvertID
|
||||
{
|
||||
unsigned short m_wBeforeID;
|
||||
unsigned short m_wAffterID;
|
||||
|
||||
ConvertID() : m_wBeforeID(0), m_wAffterID(0) { }
|
||||
};
|
||||
|
||||
struct ParseData
|
||||
{
|
||||
typedef bool(*ParseFunc) (ConvertID& convertID, const char* szValue);
|
||||
|
||||
const char* m_szColumnName;
|
||||
ParseFunc m_fnParseFunc;
|
||||
|
||||
ParseData(const char* szColumnName, ParseFunc fnParseFunc)
|
||||
: m_szColumnName(szColumnName), m_fnParseFunc(fnParseFunc) { }
|
||||
};
|
||||
|
||||
typedef std::vector<ParseData> ParseDataArray;
|
||||
typedef std::map<unsigned short, ConvertID*> ConvertMap;
|
||||
|
||||
public:
|
||||
|
||||
CDBConvertAccessory(ATL::CSession& session) : m_Session(session) { }
|
||||
|
||||
virtual ConvertResult operator() (RylDBCommand::CCharItem& charItem_InOut);
|
||||
virtual ConvertResult operator() (RylDBCommand::CCharItemEx& charItemEx_InOut);
|
||||
|
||||
virtual ConvertResult operator() (RylDBCommand::CUnifiedStore1& unifiedStore1_InOut);
|
||||
virtual ConvertResult operator() (RylDBCommand::CUnifiedStore2& unifiedStore2_InOut);
|
||||
|
||||
bool ConvertItem(char* szData, unsigned long dwSize);
|
||||
|
||||
bool Initialize();
|
||||
bool Release();
|
||||
|
||||
private:
|
||||
|
||||
ConvertMap m_cConverMap;
|
||||
|
||||
ATL::CSession& m_Session;
|
||||
};
|
||||
|
||||
class CParseDelimitedData
|
||||
{
|
||||
public:
|
||||
|
||||
CParseDelimitedData(CTokenlizedFile& TokenlizedFile) : m_TokenlizedFile(TokenlizedFile) { }
|
||||
|
||||
bool operator() (CDBConvertAccessory::ParseDataArray& ParserArray, CDBConvertAccessory::ConvertID& convertID)
|
||||
{
|
||||
for (CDBConvertAccessory::ParseDataArray::iterator itr = ParserArray.begin(); itr != ParserArray.end(); ++itr)
|
||||
{
|
||||
const char* szValue = m_TokenlizedFile.GetStringValue(itr->m_szColumnName);
|
||||
|
||||
if (NULL == szValue)
|
||||
{
|
||||
ERRLOG2(g_Log, "Data Load Fail Line:%d, ColumnName:%s",
|
||||
m_TokenlizedFile.GetCurrentLine(), itr->m_szColumnName);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (false == itr->m_fnParseFunc(convertID, szValue))
|
||||
{
|
||||
ERRLOG2(g_Log, "Data Fail Line:%d, ColumnName:%s",
|
||||
m_TokenlizedFile.GetCurrentLine(), itr->m_szColumnName);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
CTokenlizedFile& m_TokenlizedFile;
|
||||
};
|
||||
|
||||
bool ReadBeforeID(CDBConvertAccessory::ConvertID& convertID, const char* szValue)
|
||||
{
|
||||
convertID.m_wBeforeID = static_cast<unsigned short>(atoi(szValue));
|
||||
|
||||
if(!convertID.m_wBeforeID)
|
||||
{
|
||||
LOG_CONVERT1("[Item ID Error] ID:0x%08x", convertID.m_wBeforeID);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool ReadAfterID(CDBConvertAccessory::ConvertID& convertID, const char* szValue)
|
||||
{
|
||||
convertID.m_wAffterID = static_cast<unsigned short>(atoi(szValue));
|
||||
|
||||
if(!convertID.m_wAffterID)
|
||||
{
|
||||
LOG_CONVERT1("[Item ID Error] ID:0x%08x", convertID.m_wAffterID);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void PrintUsage()
|
||||
{
|
||||
printf("ConvertAccessory DBAddress DBName DBAccount DBPassword");
|
||||
}
|
||||
|
||||
int _tmain(int argc, _TCHAR* argv[])
|
||||
{
|
||||
if(5 != argc)
|
||||
{
|
||||
PrintUsage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
CoInitialize(0);
|
||||
|
||||
HRESULT hr = S_OK;
|
||||
|
||||
ATL::CDataSource dataSource;
|
||||
ATL::CSession Session;
|
||||
|
||||
if(FAILED(hr = CRylDBProcess::ConnectDB(dataSource, argv[1], argv[2], argv[3], argv[4])))
|
||||
{
|
||||
LOG_CONVERT1("Connect DB failed : hr:0x%08X", hr);
|
||||
}
|
||||
else if(FAILED(hr = Session.Open(dataSource)))
|
||||
{
|
||||
LOG_CONVERT1("Open session failed : hr:0x%08X", hr);
|
||||
}
|
||||
else if (FAILED(hr = Session.StartTransaction()))
|
||||
{
|
||||
LOG_CONVERT1("Start transaction failed : hr:0x%08x", hr);
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
CRylDBProcess dbProcess(Session);
|
||||
CConsoleCounter consoleCounter(1000);
|
||||
CDBConvertAccessory accessory(Session);
|
||||
|
||||
if(!accessory.Initialize())
|
||||
{
|
||||
LOG_CONVERT0("Initialize failed");
|
||||
}
|
||||
else if(FAILED(hr = dbProcess.CharItem(accessory, consoleCounter)))
|
||||
{
|
||||
LOG_CONVERT1("CharItem process failed : hr:0x%08X", hr);
|
||||
}
|
||||
else if(FAILED(hr = dbProcess.CharItemEx(accessory, consoleCounter)))
|
||||
{
|
||||
LOG_CONVERT1("CharItemEx process failed : hr:0x%08X", hr);
|
||||
}
|
||||
else if(FAILED(hr = dbProcess.UnifiedStore1(accessory, consoleCounter)))
|
||||
{
|
||||
LOG_CONVERT1("UnifiedStore1 process failed : hr:0x%08X", hr);
|
||||
}
|
||||
else if(FAILED(hr = dbProcess.UnifiedStore2(accessory, consoleCounter)))
|
||||
{
|
||||
LOG_CONVERT1("UnifiedStore2 process failed : hr:0x%08X", hr);
|
||||
}
|
||||
|
||||
accessory.Release();
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
LOG_CONVERT0("Exception occured! rollback transaction now!");
|
||||
LOG_CONVERT2("Rollback transaction %s! : hr:0x%08x",
|
||||
FAILED(hr = Session.Abort()) ? "failed" : "succeeded", hr);
|
||||
}
|
||||
|
||||
LOG_CONVERT0("Commit transaction now!");
|
||||
LOG_CONVERT2("Commit transaction %s! : hr:0x%08x",
|
||||
FAILED(hr = Session.Commit()) ? "failed" : "succeeded", hr);
|
||||
}
|
||||
|
||||
Session.Close();
|
||||
dataSource.Close();
|
||||
|
||||
CoUninitialize();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool CDBConvertAccessory::Initialize()
|
||||
{
|
||||
const char* szFileName = "ConverScript.txt";
|
||||
|
||||
CTokenlizedFile TokenlizedFile;
|
||||
|
||||
if(!TokenlizedFile.Open(szFileName))
|
||||
{
|
||||
LOG_CONVERT0("ConverScript <20>ε<EFBFBD> <20><><EFBFBD><EFBFBD>");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (false == TokenlizedFile.ReadColumn())
|
||||
{
|
||||
LOG_CONVERT0("ConverScript <20>÷<EFBFBD> <20>ε<EFBFBD> <20><><EFBFBD><EFBFBD>");
|
||||
return false;
|
||||
}
|
||||
|
||||
ParseDataArray parseDataArray;
|
||||
|
||||
parseDataArray.reserve(2);
|
||||
parseDataArray.push_back(ParseData("Before", ReadBeforeID));
|
||||
parseDataArray.push_back(ParseData("After", ReadAfterID));
|
||||
|
||||
m_cConverMap.clear();
|
||||
|
||||
ConvertID convertID;
|
||||
ConvertID* pConverID;
|
||||
|
||||
CParseDelimitedData ParseData(TokenlizedFile);
|
||||
|
||||
while (TokenlizedFile.ReadLine())
|
||||
{
|
||||
if (false == ParseData(parseDataArray, convertID))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
pConverID = new ConvertID;
|
||||
memcpy(pConverID, &convertID, sizeof(ConvertID));
|
||||
|
||||
bool bInsert = m_cConverMap.insert(std::make_pair(pConverID->m_wBeforeID, pConverID)).second;
|
||||
|
||||
if(!bInsert)
|
||||
{
|
||||
LOG_CONVERT0("ConverMap Insert Fail");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CDBConvertAccessory::Release()
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
ConvertMap::iterator begin = m_cConverMap.begin();
|
||||
ConvertMap::iterator end = m_cConverMap.end();
|
||||
|
||||
for(ConvertMap::iterator itr = begin; itr!=end; itr++)
|
||||
{
|
||||
if(itr->second)
|
||||
{
|
||||
delete itr->second;
|
||||
}
|
||||
}
|
||||
|
||||
m_cConverMap.clear();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
ConvertResult CDBConvertAccessory::operator()(RylDBCommand::CCharItem& charItem_InOut)
|
||||
{
|
||||
// Inven <20>˻<EFBFBD>.
|
||||
|
||||
INVEN inven;
|
||||
memset(&inven, 0, sizeof(INVEN));
|
||||
memcpy(&inven, &charItem_InOut.GetInven(), sizeof(INVEN));
|
||||
|
||||
if(inven.dwSize>INVEN::MAX_INVEN_SIZE)
|
||||
{
|
||||
return CONVERT_FAILED;
|
||||
}
|
||||
|
||||
ConvertItem(inven.Data, inven.dwSize);
|
||||
charItem_InOut.SetInven(inven);
|
||||
|
||||
// Equip <20>˻<EFBFBD>.
|
||||
|
||||
EQUIP equip;
|
||||
memset(&equip, 0, sizeof(EQUIP));
|
||||
memcpy(&equip, &charItem_InOut.GetEquip(), sizeof(EQUIP));
|
||||
|
||||
if(equip.dwSize>EQUIP::MAX_EQUIP_SIZE)
|
||||
{
|
||||
return CONVERT_FAILED;
|
||||
}
|
||||
|
||||
ConvertItem(equip.Data, equip.dwSize);
|
||||
charItem_InOut.SetEquip(equip);
|
||||
|
||||
// Extra <20>˻<EFBFBD>.
|
||||
|
||||
EXTRA extra;
|
||||
memset(&extra, 0, sizeof(EXTRA));
|
||||
memcpy(&extra, &charItem_InOut.GetExtra(), sizeof(EXTRA));
|
||||
|
||||
if(extra.dwSize>EXTRA::MAX_EXTRA_SIZE)
|
||||
{
|
||||
return CONVERT_FAILED;
|
||||
}
|
||||
|
||||
ConvertItem(extra.Data, extra.dwSize);
|
||||
charItem_InOut.SetExtra(extra);
|
||||
|
||||
return CONVERT_SUCCEEDED;
|
||||
}
|
||||
|
||||
ConvertResult CDBConvertAccessory::operator()(RylDBCommand::CCharItemEx& charItemEx_InOut)
|
||||
{
|
||||
// Exchage <20>˻<EFBFBD>.
|
||||
|
||||
EXCHANGE exchange;
|
||||
memset(&exchange, 0, sizeof(EXCHANGE));
|
||||
memcpy(&exchange, &charItemEx_InOut.GetExchange(), sizeof(EXCHANGE));
|
||||
|
||||
if(exchange.dwSize>EXCHANGE::MAX_EXCHANGE_SIZE)
|
||||
{
|
||||
return CONVERT_FAILED;
|
||||
}
|
||||
|
||||
ConvertItem(exchange.Data, exchange.dwSize);
|
||||
charItemEx_InOut.SetExchange(exchange);
|
||||
|
||||
// Temp Inven <20>˻<EFBFBD>.
|
||||
|
||||
TEMPINVEN tempinven;
|
||||
memset(&tempinven, 0, sizeof(TEMPINVEN));
|
||||
memcpy(&tempinven, &charItemEx_InOut.GetTempInven(), sizeof(TEMPINVEN));
|
||||
|
||||
if(tempinven.dwSize>TEMPINVEN::MAX_TEMPINVEN_SIZE)
|
||||
{
|
||||
return CONVERT_FAILED;
|
||||
}
|
||||
|
||||
ConvertItem(tempinven.Data, tempinven.dwSize);
|
||||
charItemEx_InOut.SetTempInven(tempinven);
|
||||
|
||||
return CONVERT_SUCCEEDED;
|
||||
}
|
||||
|
||||
ConvertResult CDBConvertAccessory::operator()(RylDBCommand::CUnifiedStore1& unifiedStore1_InOut)
|
||||
{
|
||||
// Store <20>˻<EFBFBD>.
|
||||
|
||||
STORE store;
|
||||
memset(&store, 0, sizeof(STORE));
|
||||
memcpy(&store, &unifiedStore1_InOut.GetStore(), sizeof(STORE));
|
||||
|
||||
if(store.dwSize>STORE::MAX_STORE_SIZE)
|
||||
{
|
||||
return CONVERT_FAILED;
|
||||
}
|
||||
|
||||
ConvertItem(store.Data, store.dwSize);
|
||||
unifiedStore1_InOut.SetStore(store);
|
||||
|
||||
return CONVERT_SUCCEEDED;
|
||||
}
|
||||
|
||||
ConvertResult CDBConvertAccessory::operator()(RylDBCommand::CUnifiedStore2& unifiedStore2_InOut)
|
||||
{
|
||||
// Store <20>˻<EFBFBD>.
|
||||
|
||||
STORE store;
|
||||
memset(&store, 0, sizeof(STORE));
|
||||
memcpy(&store, &unifiedStore2_InOut.GetStore(), sizeof(STORE));
|
||||
|
||||
if(store.dwSize>STORE::MAX_STORE_SIZE)
|
||||
{
|
||||
return CONVERT_FAILED;
|
||||
}
|
||||
|
||||
ConvertItem(store.Data, store.dwSize);
|
||||
unifiedStore2_InOut.SetStore(store);
|
||||
|
||||
return CONVERT_SUCCEEDED;
|
||||
}
|
||||
|
||||
bool CDBConvertAccessory::ConvertItem(char* szData, unsigned long dwSize)
|
||||
{
|
||||
char* szPos = szData;
|
||||
char* szEnd = szData + dwSize;
|
||||
|
||||
for(; szPos < szEnd; )
|
||||
{
|
||||
Item::ItemData* lpItemData = reinterpret_cast<Item::ItemData*>(szPos);
|
||||
|
||||
if(lpItemData)
|
||||
{
|
||||
// <20>Ǽ<EFBFBD><C7BC>縮 <20><><EFBFBD>̵<EFBFBD> <20>˻<EFBFBD>.
|
||||
ConvertMap::iterator find = m_cConverMap.find(lpItemData->m_usProtoTypeID);
|
||||
|
||||
if(find!=m_cConverMap.end())
|
||||
{
|
||||
lpItemData->m_usProtoTypeID = find->second->m_wAffterID;
|
||||
}
|
||||
}
|
||||
|
||||
szPos += lpItemData->m_cItemSize;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user