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:
219
Server/ManageTool/ManageLibrary/Setup/RylServerBindRunID.cpp
Normal file
219
Server/ManageTool/ManageLibrary/Setup/RylServerBindRunID.cpp
Normal file
@@ -0,0 +1,219 @@
|
||||
#include "stdafx.h"
|
||||
#include "RylServerBindRunID.h"
|
||||
#include <Log/ServerLog.h>
|
||||
|
||||
#include <ServerManage/ManageClientManager.h>
|
||||
|
||||
|
||||
CRylServerBindRunID& CRylServerBindRunID::GetInstance()
|
||||
{
|
||||
static CRylServerBindRunID bindRunID;
|
||||
return bindRunID;
|
||||
}
|
||||
|
||||
|
||||
CRylServerBindRunID::CRylServerBindRunID()
|
||||
{
|
||||
_sntprintf(m_szDefaultSetupFileName, MAX_PATH - 1, "%s",
|
||||
_T("./RylSetupBindServerID.ini"));
|
||||
|
||||
m_szDefaultSetupFileName[MAX_PATH - 1] = 0;
|
||||
|
||||
Load();
|
||||
}
|
||||
|
||||
CRylServerBindRunID::~CRylServerBindRunID()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool CRylServerBindRunID::SetID(unsigned long dwRunID, unsigned long dwServerID)
|
||||
{
|
||||
std::pair<BindIDTable::iterator, bool> runIDpair =
|
||||
m_RunID.insert(BindIDTable::value_type(dwRunID, dwServerID));
|
||||
|
||||
if(runIDpair.second)
|
||||
{
|
||||
std::pair<BindIDTable::iterator, bool> serverIDPair =
|
||||
m_ServerID.insert(BindIDTable::value_type(dwServerID, dwRunID));
|
||||
|
||||
if(serverIDPair.second)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
m_RunID.erase(runIDpair.first);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool CRylServerBindRunID::RemoveFromRunID(unsigned long dwRunID)
|
||||
{
|
||||
BindIDTable::iterator pos_runID = m_RunID.find(dwRunID);
|
||||
|
||||
if(pos_runID != m_RunID.end())
|
||||
{
|
||||
unsigned long dwServerID = pos_runID->second;
|
||||
|
||||
BindIDTable::iterator pos_serverID = m_ServerID.find(dwServerID);
|
||||
|
||||
if(pos_serverID != m_ServerID.end())
|
||||
{
|
||||
m_RunID.erase(pos_runID);
|
||||
m_ServerID.erase(pos_serverID);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CRylServerBindRunID::RemoveFromServerID(unsigned long dwServerID)
|
||||
{
|
||||
BindIDTable::iterator pos_serverID = m_ServerID.find(dwServerID);
|
||||
|
||||
if(pos_serverID != m_ServerID.end())
|
||||
{
|
||||
unsigned long dwRunID = pos_serverID->second;
|
||||
|
||||
BindIDTable::iterator pos_runID = m_RunID.find(dwRunID);
|
||||
|
||||
if(pos_runID != m_RunID.end())
|
||||
{
|
||||
m_RunID.erase(pos_runID);
|
||||
m_ServerID.erase(pos_serverID);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool CRylServerBindRunID::GetRunID(unsigned long dwServerID, unsigned long* lpdwRunID)
|
||||
{
|
||||
BindIDTable::iterator pos = m_ServerID.find(dwServerID);
|
||||
|
||||
if(0 != lpdwRunID && pos != m_ServerID.end())
|
||||
{
|
||||
*lpdwRunID = pos->second;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CRylServerBindRunID::GetServerID(unsigned long dwRunID, unsigned long* lpdwServerID)
|
||||
{
|
||||
BindIDTable::iterator pos = m_RunID.find(dwRunID);
|
||||
|
||||
if(0 != lpdwServerID && pos != m_RunID.end())
|
||||
{
|
||||
*lpdwServerID = pos->second;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CRylServerBindRunID::SetSetupFileName(const TCHAR* szSetupFileName)
|
||||
{
|
||||
if(0 != szSetupFileName)
|
||||
{
|
||||
_sntprintf(m_szDefaultSetupFileName, MAX_PATH - 1, "%s", szSetupFileName);
|
||||
m_szDefaultSetupFileName[MAX_PATH - 1] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool CRylServerBindRunID::Load()
|
||||
{
|
||||
HANDLE hFile = CreateFile(m_szDefaultSetupFileName,
|
||||
GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
|
||||
unsigned long dwWritten = 0;
|
||||
bool bResult = false;
|
||||
|
||||
if(INVALID_HANDLE_VALUE != hFile)
|
||||
{
|
||||
size_t nBindIDNum = 0;
|
||||
|
||||
m_RunID.clear();
|
||||
m_ServerID.clear();
|
||||
|
||||
if(ReadFile(hFile, &nBindIDNum, sizeof(size_t), &dwWritten, 0))
|
||||
{
|
||||
BindID bindID;
|
||||
|
||||
for(size_t nCount = 0; nCount < nBindIDNum; ++nCount)
|
||||
{
|
||||
if(ReadFile(hFile, &bindID, sizeof(BindID), &dwWritten, 0))
|
||||
{
|
||||
m_RunID.insert(bindID);
|
||||
std::swap(bindID.first, bindID.second);
|
||||
m_ServerID.insert(bindID);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(nCount == nBindIDNum)
|
||||
{
|
||||
bResult = true;
|
||||
}
|
||||
}
|
||||
|
||||
CloseHandle(hFile);
|
||||
};
|
||||
|
||||
return bResult;
|
||||
}
|
||||
|
||||
|
||||
bool CRylServerBindRunID::Save()
|
||||
{
|
||||
HANDLE hFile = CreateFile(m_szDefaultSetupFileName,
|
||||
GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
|
||||
unsigned long dwWritten = 0;
|
||||
bool bResult = false;
|
||||
|
||||
if(INVALID_HANDLE_VALUE != hFile)
|
||||
{
|
||||
size_t nBindIDNum = m_RunID.size();
|
||||
|
||||
if(WriteFile(hFile, &nBindIDNum, sizeof(size_t), &dwWritten, 0))
|
||||
{
|
||||
BindIDTable::iterator pos = m_RunID.begin();
|
||||
BindIDTable::iterator end = m_RunID.end();
|
||||
|
||||
BindID bindID;
|
||||
|
||||
for(; pos != end; ++pos)
|
||||
{
|
||||
bindID = *pos;
|
||||
|
||||
if(!WriteFile(hFile, &bindID, sizeof(BindID), &dwWritten, 0))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(pos == end)
|
||||
{
|
||||
bResult = true;
|
||||
}
|
||||
}
|
||||
|
||||
CloseHandle(hFile);
|
||||
};
|
||||
|
||||
return bResult;
|
||||
}
|
||||
Reference in New Issue
Block a user