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:
597
Server/RylServerProject/RylDBAgentServer/Castle/CastleDB.cpp
Normal file
597
Server/RylServerProject/RylDBAgentServer/Castle/CastleDB.cpp
Normal file
@@ -0,0 +1,597 @@
|
||||
#include "stdafx.h"
|
||||
#include "CastleDB.h"
|
||||
|
||||
#include <Creature/Siege/SiegeObjectDB.h>
|
||||
#include <Creature/Siege/CastleGateDB.h>
|
||||
|
||||
#include <Community/Guild/GuildDB.h>
|
||||
#include <Community/Guild/GuildDBMgr.h>
|
||||
|
||||
#include <DB/DBComponent.h>
|
||||
#include <Castle/CastleDBComponent.h>
|
||||
#include <Castle/CastleDBMgr.h>
|
||||
#include <GameTime/GameTimeDBMgr.h>
|
||||
|
||||
#include <Network/Packet/WrapPacket.h>
|
||||
#include <Network/Packet/PacketCommand.h>
|
||||
#include <Network/Packet/PacketStruct/ServerInfo.h>
|
||||
#include <Network/Dispatch/GameDispatch.h>
|
||||
|
||||
#include <Utility/Setup/ServerSetup.h>
|
||||
#include <Log/ServerLog.h>
|
||||
|
||||
|
||||
CCastleDB::CCastleDB(CDBComponent& DBComponent, const CastleInfoDB& CastleInfo)
|
||||
: m_dwCastleID(Castle::CASTLE_BIT | CastleInfo.m_dwCastleID),
|
||||
m_cNation(CastleInfo.m_cNation),
|
||||
m_cZone(CastleInfo.m_cZone),
|
||||
m_cChannel(CastleInfo.m_cChannel),
|
||||
m_cNameID(CastleInfo.m_cNameID),
|
||||
m_cSiegeCount(CastleInfo.m_cSiegeCount),
|
||||
m_cInvincibleCount(CastleInfo.m_cInvincibleCount),
|
||||
m_wTotalSiegeCount(CastleInfo.m_wTotalSiegeCount),
|
||||
m_dwTotalTaxMoney(CastleInfo.m_dwTotalTaxMoney),
|
||||
m_wItemID(CastleInfo.m_wItemID),
|
||||
m_cItemNum(CastleInfo.m_cItemNum),
|
||||
m_bEnableSiege(false),
|
||||
m_DBComponent(DBComponent)
|
||||
{
|
||||
::memcpy(&m_CastleRight, CastleInfo.m_szRight, sizeof(CastleRight));
|
||||
|
||||
m_BackDoorPos[0] = CastleInfo.m_InPos;
|
||||
m_BackDoorPos[1] = CastleInfo.m_OutPos;
|
||||
|
||||
::memset(&m_CastleTax, 0, sizeof(CastleTaxInfo) * Castle::MAX_TAX_TYPE);
|
||||
|
||||
CheckEnableSiege( CGameTimeDBMgr::GetInstance().IsSiegeWarTime() );
|
||||
}
|
||||
|
||||
CCastleDB::~CCastleDB()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool CCastleDB::ChangeCastleMaster(unsigned char cNation)
|
||||
{
|
||||
m_cNation = cNation;
|
||||
m_cSiegeCount = 0;
|
||||
m_cInvincibleCount = Castle::INVINCIBLE_COUNT;
|
||||
m_wTotalSiegeCount = 0;
|
||||
m_dwTotalTaxMoney = 0;
|
||||
m_wItemID = 0;
|
||||
m_cItemNum = 0;
|
||||
|
||||
m_bEnableSiege = (m_cInvincibleCount > 0) ? false : true;
|
||||
|
||||
m_CastleRight = CastleRight();
|
||||
::memset(&m_CastleTax, 0, sizeof(CastleTaxInfo) * Castle::MAX_TAX_TYPE);
|
||||
m_AccumulatedMineralMap.clear();
|
||||
m_TemporaryMineralMap.clear();
|
||||
|
||||
// DB 에 정보 저장
|
||||
DBComponent::CastleDB::UpdateCastleInfo(m_DBComponent, m_dwCastleID, m_cNation, m_cSiegeCount, m_cInvincibleCount,
|
||||
m_wTotalSiegeCount, m_dwTotalTaxMoney, m_wItemID, m_cItemNum);
|
||||
DBComponent::CastleDB::DeleteCastleTaxInfo(m_DBComponent, m_dwCastleID);
|
||||
DBComponent::CastleDB::DeleteCastleMineralInfo(m_DBComponent, m_dwCastleID);
|
||||
DBComponent::CastleDB::UpdateCastleRight(m_DBComponent, m_dwCastleID, reinterpret_cast<char *>(&m_CastleRight), sizeof(CastleRight));
|
||||
|
||||
// 성 오브젝트들의 소유 국가들을 모두 변경한다.
|
||||
ChangeCastleObjectNation(cNation);
|
||||
|
||||
// 수성 병기를 병기 관리 NPC 로 돌려놓는다.
|
||||
DestroyAllCastleArms();
|
||||
|
||||
// 공성 가능 정보 변경 전송
|
||||
CGameTimeDBMgr::GetInstance().SendGameTimeInfo( GetCastleID() );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CCastleDB::InsertCastleObject(CSiegeObjectDB* lpCastleObject)
|
||||
{
|
||||
if (lpCastleObject)
|
||||
{
|
||||
lpCastleObject->SetNation(m_cNation);
|
||||
lpCastleObject->SetZoneChannel(m_cZone, m_cChannel);
|
||||
|
||||
return m_CastleObjectMap.insert(std::make_pair(lpCastleObject->GetCID(), lpCastleObject)).second;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool CCastleDB::DeleteCastleObject(unsigned long dwCID)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CCastleDB::DeleteCastleObject(CSiegeObjectDB* lpSiegeObject)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void CCastleDB::LoseOwnership()
|
||||
{
|
||||
m_cNation = 0;
|
||||
m_cSiegeCount = 0;
|
||||
m_cInvincibleCount = 0;
|
||||
m_wTotalSiegeCount = 0;
|
||||
m_dwTotalTaxMoney = 0;
|
||||
m_wItemID = 0;
|
||||
m_cItemNum = 0;
|
||||
m_bEnableSiege = true;
|
||||
|
||||
m_CastleRight = CastleRight();
|
||||
::memset(&m_CastleTax, 0, sizeof(CastleTaxInfo) * Castle::MAX_TAX_TYPE);
|
||||
m_AccumulatedMineralMap.clear();
|
||||
m_TemporaryMineralMap.clear();
|
||||
|
||||
// DB 업데이트..
|
||||
DBComponent::CastleDB::UpdateCastleInfo(m_DBComponent, m_dwCastleID, m_cNation, m_cSiegeCount, m_cInvincibleCount,
|
||||
m_wTotalSiegeCount, m_dwTotalTaxMoney, m_wItemID, m_cItemNum);
|
||||
DBComponent::CastleDB::DeleteCastleTaxInfo(m_DBComponent, m_dwCastleID);
|
||||
DBComponent::CastleDB::DeleteCastleMineralInfo(m_DBComponent, m_dwCastleID);
|
||||
DBComponent::CastleDB::UpdateCastleRight(m_DBComponent, m_dwCastleID, reinterpret_cast<char *>(&m_CastleRight), sizeof(CastleRight));
|
||||
|
||||
// 성 오브젝트 중립화
|
||||
ChangeCastleObjectNation(0);
|
||||
|
||||
// 수성 병기를 병기 관리 NPC 로 돌려놓는다.
|
||||
DestroyAllCastleArms();
|
||||
|
||||
// 성 소유 중립화 명령 전송
|
||||
CSiegeObjectDB* lpEmblem = GetCastleEmblem();
|
||||
if (lpEmblem)
|
||||
{
|
||||
lpEmblem->SendCastleCmd(0, PktCastleCmd::CASTLE_LOSE_OWNERSHIP);
|
||||
}
|
||||
|
||||
// 공성 가능 정보 변경 전송
|
||||
CGameTimeDBMgr::GetInstance().SendGameTimeInfo( GetCastleID() );
|
||||
}
|
||||
|
||||
void CCastleDB::CloseCastleGate()
|
||||
{
|
||||
CSiegeObjectDB* lpGate = GetCastleGate();
|
||||
if (lpGate)
|
||||
{
|
||||
// HP 를 Full 로 하는것은 게임 서버에서 얼마로 채울것인지 보내준다.
|
||||
static_cast<CCastleGateDB* >(lpGate)->ForceClose();
|
||||
}
|
||||
}
|
||||
|
||||
void CCastleDB::OpenCastleGate()
|
||||
{
|
||||
CSiegeObjectDB* lpGate = GetCastleGate();
|
||||
if (lpGate)
|
||||
{
|
||||
// HP 를 Full 로 하는것은 게임 서버에서 얼마로 채울것인지 보내준다.
|
||||
static_cast<CCastleGateDB* >(lpGate)->ForceOpen();
|
||||
}
|
||||
}
|
||||
|
||||
void CCastleDB::ChangeCastleObjectNation(unsigned char cNation)
|
||||
{
|
||||
CastleObjectMap::iterator itr = m_CastleObjectMap.begin();
|
||||
CastleObjectMap::iterator end = m_CastleObjectMap.end();
|
||||
|
||||
CSiegeObjectDB* lpCastleObject = NULL;
|
||||
while (itr != end)
|
||||
{
|
||||
lpCastleObject = itr->second;
|
||||
if (lpCastleObject)
|
||||
{
|
||||
lpCastleObject->SetNation(cNation);
|
||||
}
|
||||
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
|
||||
void CCastleDB::DestroyAllCastleArms()
|
||||
{
|
||||
CastleObjectMap::iterator itr = m_CastleObjectMap.begin();
|
||||
CastleObjectMap::iterator end = m_CastleObjectMap.end();
|
||||
|
||||
CSiegeObjectDB* lpCastleObject = NULL;
|
||||
while (itr != end)
|
||||
{
|
||||
lpCastleObject = itr->second;
|
||||
if (lpCastleObject && lpCastleObject->IsCastleArms())
|
||||
{
|
||||
lpCastleObject->Destroy(); // 수성 병기들은 병기 관리 NPC 로 돌려놓는다.
|
||||
|
||||
// 중계서버에서 파괴된 각자의 패킷을 보내지 않고,
|
||||
// 중계서버와 게임서버가 각자 처리하도록 해놓았음..
|
||||
//lpCastleObject->SendCastleCmd(0, PktCastleCmd::CASTLE_DESTROY_ARMS);
|
||||
}
|
||||
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
|
||||
CSiegeObjectDB* CCastleDB::GetCastleEmblem()
|
||||
{
|
||||
CastleObjectMap::iterator itr = m_CastleObjectMap.begin();
|
||||
CSiegeObjectDB* lpCastleObject = NULL;
|
||||
|
||||
while (itr != m_CastleObjectMap.end())
|
||||
{
|
||||
lpCastleObject = itr->second;
|
||||
if (lpCastleObject && lpCastleObject->IsEmblem())
|
||||
{
|
||||
return lpCastleObject;
|
||||
}
|
||||
|
||||
++itr;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CSiegeObjectDB* CCastleDB::GetCastleGate()
|
||||
{
|
||||
CastleObjectMap::iterator itr = m_CastleObjectMap.begin();
|
||||
CSiegeObjectDB* lpCastleObject = NULL;
|
||||
|
||||
while (itr != m_CastleObjectMap.end())
|
||||
{
|
||||
lpCastleObject = itr->second;
|
||||
if (lpCastleObject && lpCastleObject->IsGate())
|
||||
{
|
||||
return lpCastleObject;
|
||||
}
|
||||
|
||||
++itr;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CSiegeObjectDB* CCastleDB::GetCastleObject(unsigned long dwCastleObjectID)
|
||||
{
|
||||
CastleObjectMap::iterator itr = m_CastleObjectMap.find(dwCastleObjectID);
|
||||
if (itr != m_CastleObjectMap.end()) return itr->second;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CCastleDB::CheckEnableSiege(bool bIsSiegeTime)
|
||||
{
|
||||
if (bIsSiegeTime == m_bEnableSiege)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_bEnableSiege = false;
|
||||
if (bIsSiegeTime && 0 == m_cInvincibleCount)
|
||||
{
|
||||
m_bEnableSiege = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CCastleDB::UpdateSiegeCount()
|
||||
{
|
||||
SERVER_ID serverID;
|
||||
serverID.sID.Type = CServerSetup::GameServer;
|
||||
serverID.sID.Group = CServerSetup::GetInstance().GetServerGroup();
|
||||
serverID.sID.Channel = m_cChannel;
|
||||
serverID.sID.ID = m_cZone;
|
||||
|
||||
GET_MULTI_DISPATCH(lpGameDispatch, serverID.dwID,
|
||||
DBAgent::CGameDispatch, DBAgent::CGameDispatch::GetDispatchTable());
|
||||
|
||||
if (m_bEnableSiege)
|
||||
{
|
||||
++m_wTotalSiegeCount;
|
||||
}
|
||||
|
||||
if (m_cInvincibleCount)
|
||||
{
|
||||
--m_cInvincibleCount;
|
||||
}
|
||||
|
||||
++m_cSiegeCount;
|
||||
if (m_cSiegeCount >= Castle::TEMP_TAX_GAIN_COUNT)
|
||||
{
|
||||
m_cSiegeCount = 0;
|
||||
unsigned long dwMoveTempMoney[ Castle::MAX_TAX_TYPE ] = { 0, };
|
||||
|
||||
for (int i=0; i<Castle::MAX_TAX_TYPE; ++i)
|
||||
{
|
||||
dwMoveTempMoney[ i ] = m_CastleTax[ i ].m_dwTempTaxMoney;
|
||||
m_CastleTax[ i ].m_dwTaxMoney += m_CastleTax[ i ].m_dwTempTaxMoney;
|
||||
m_CastleTax[ i ].m_dwTempTaxMoney = 0;
|
||||
|
||||
// DB 업데이트
|
||||
DBComponent::CastleDB::UpdateCastleTaxMoney(m_DBComponent, m_dwCastleID, i, m_CastleTax[ i ].m_dwTempTaxMoney, m_CastleTax[ i ].m_dwTaxMoney);
|
||||
}
|
||||
|
||||
// 누적 세금 정보 전송
|
||||
if (NULL != lpGameDispatch)
|
||||
{
|
||||
CSendStream& SendStream = lpGameDispatch->GetSendStream();
|
||||
|
||||
char* lpBuffer = SendStream.GetBuffer(sizeof(PktCastleTaxMove));
|
||||
if (NULL != lpBuffer)
|
||||
{
|
||||
PktCastleTaxMove* lpPktCastleTaxMove = reinterpret_cast<PktCastleTaxMove*>(lpBuffer);
|
||||
|
||||
lpPktCastleTaxMove->m_dwCastleID = m_dwCastleID;
|
||||
for (int j=0; j<Castle::MAX_TAX_TYPE; ++j)
|
||||
{
|
||||
lpPktCastleTaxMove->m_dwMoveTempMoney[ j ] = dwMoveTempMoney[ j ];
|
||||
lpPktCastleTaxMove->m_dwResultTaxMoney[ j ] = m_CastleTax[ j ].m_dwTaxMoney;
|
||||
}
|
||||
|
||||
SendStream.WrapHeader(sizeof(PktCastleTaxMove), CmdCastleTaxMove, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DB 업데이트
|
||||
DBComponent::CastleDB::UpdateCastleSiegeCount(m_DBComponent, m_dwCastleID, m_cSiegeCount, m_cInvincibleCount, m_wTotalSiegeCount);
|
||||
|
||||
// 공성 횟수 정보 전송
|
||||
if (NULL != lpGameDispatch)
|
||||
{
|
||||
CSendStream& SendStream = lpGameDispatch->GetSendStream();
|
||||
|
||||
char* lpBuffer = SendStream.GetBuffer(sizeof(PktCastleSiegeCount));
|
||||
if (NULL != lpBuffer)
|
||||
{
|
||||
PktCastleSiegeCount* lpPktCastleSiegeCount = reinterpret_cast<PktCastleSiegeCount*>(lpBuffer);
|
||||
|
||||
lpPktCastleSiegeCount->m_dwCastleID = m_dwCastleID;
|
||||
lpPktCastleSiegeCount->m_cSiegeCount = m_cSiegeCount;
|
||||
lpPktCastleSiegeCount->m_cInvincibleCount = m_cInvincibleCount;
|
||||
lpPktCastleSiegeCount->m_wTotalSiegeCount = m_wTotalSiegeCount;
|
||||
|
||||
SendStream.WrapHeader(sizeof(PktCastleSiegeCount), CmdCastleSiegeCount, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// 세율 조정 가능 변수 초기화
|
||||
for (int i=0; i<Castle::MAX_TAX_TYPE; ++i)
|
||||
{
|
||||
m_CastleTax[ i ].m_cTaxChangable = Castle::TAX_ENABLE;
|
||||
|
||||
// DB 업데이트
|
||||
DBComponent::CastleDB::UpdateCastleTaxChangable(m_DBComponent, m_dwCastleID, i, Castle::TAX_ENABLE);
|
||||
}
|
||||
}
|
||||
|
||||
// 거두어 들인 세금을 길드 금고로
|
||||
void CCastleDB::TakeTaxMoney(unsigned char cType, unsigned long dwTakeTaxMoney)
|
||||
{
|
||||
// CASTLE_TODO : 성이 길드 소유가 아니므로 일단 구현부분을 주석 처리 해둔다.
|
||||
/*
|
||||
// edith 세금 부분 추가 (주석처리 뺐음)
|
||||
Guild::CGuildDB* lpGuild = static_cast<Guild::CGuildDB*>(
|
||||
Guild::CGuildDBMgr::GetInstance().GetGuild(m_dwGID));
|
||||
|
||||
if (lpGuild)
|
||||
{
|
||||
if (Castle::CAMP_MINERAL_TAX == cType)
|
||||
{
|
||||
m_dwTotalTaxMoney += dwTakeTaxMoney;
|
||||
|
||||
// DB 업데이트
|
||||
DBComponent::CastleDB::UpdateCastleTotalTaxMoney(m_DBComponent, m_dwCastleID, m_dwTotalTaxMoney);
|
||||
}
|
||||
else
|
||||
{
|
||||
lpGuild->AddGold(dwTakeTaxMoney);
|
||||
m_CastleTax[ cType ].m_dwTaxMoney -= dwTakeTaxMoney;
|
||||
m_dwTotalTaxMoney += dwTakeTaxMoney;
|
||||
|
||||
// DB 업데이트
|
||||
DBComponent::CastleDB::UpdateCastleTaxMoney(m_DBComponent, m_dwCastleID, cType,
|
||||
m_CastleTax[cType].m_dwTempTaxMoney, m_CastleTax[cType].m_dwTaxMoney);
|
||||
|
||||
DBComponent::CastleDB::UpdateCastleTotalTaxMoney(m_DBComponent, m_dwCastleID, m_dwTotalTaxMoney);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
// 광물 세금 회수
|
||||
bool CCastleDB::GainMineral(unsigned short wMineralID, unsigned short wAmount)
|
||||
{
|
||||
MineralInfoMap::iterator itr = m_AccumulatedMineralMap.find(wMineralID);
|
||||
|
||||
if (itr != m_AccumulatedMineralMap.end())
|
||||
{
|
||||
if (itr->second < wAmount)
|
||||
{
|
||||
ERRLOG4(g_Log, "획득할려는 아이템 수보다 현재 누적된 아이템 수가 더 적습니다.( CastleID : 0x%08x, MineralID : %d, CurrentAmount : %d, GainAmount : %d )",
|
||||
m_dwCastleID, wMineralID, itr->second, wAmount);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (itr->second == wAmount)
|
||||
{
|
||||
DBComponent::CastleDB::DeleteCastleMineralInfo(m_DBComponent, m_dwCastleID, Siege::ACCUMULATED_MINERAL, wMineralID);
|
||||
m_AccumulatedMineralMap.erase(itr);
|
||||
}
|
||||
else
|
||||
{
|
||||
itr->second -= wAmount;
|
||||
DBComponent::CastleDB::UpdateCastleMineralInfo(m_DBComponent, m_dwCastleID, Siege::ACCUMULATED_MINERAL, wMineralID, itr->second);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// 게임 서버로부터 임시 세금정보 업데이트
|
||||
bool CCastleDB::SetTempTaxMoney(unsigned long* dwTempTaxMoney, unsigned long* dwTaxMoney)
|
||||
{
|
||||
if (NULL == dwTempTaxMoney || NULL == dwTaxMoney)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i=0; i<Castle::MAX_TAX_TYPE; ++i)
|
||||
{
|
||||
// 누적 세금 정보가 같을 때만 업데이트한다.!!
|
||||
// (GS -> DBA : 임시 세금 정보 패킷전송, DBA -> GS : 임시 세금 -> 누적세금 패킷전송 간의 시간차로 인한 문제가 없게하기 위해)
|
||||
if (m_CastleTax[ i ].m_dwTaxMoney == dwTaxMoney[ i ])
|
||||
{
|
||||
m_CastleTax[ i ].m_dwTempTaxMoney = dwTempTaxMoney[ i ];
|
||||
|
||||
// DB 업데이트
|
||||
DBComponent::CastleDB::UpdateCastleTaxMoney(m_DBComponent, m_dwCastleID, i,
|
||||
m_CastleTax[i].m_dwTempTaxMoney, m_CastleTax[i].m_dwTaxMoney);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// 게임 서버로부터 광물 세금정보 업데이트
|
||||
bool CCastleDB::SetMineralInfo(unsigned char cMineralType, unsigned char cNum, CastleMineral* lpMineralInfo)
|
||||
{
|
||||
switch (cMineralType)
|
||||
{
|
||||
case Siege::TEMPORARY_MINERAL :
|
||||
{
|
||||
DBComponent::CastleDB::DeleteCastleMineralInfo(m_DBComponent, m_dwCastleID, cMineralType);
|
||||
m_TemporaryMineralMap.clear();
|
||||
|
||||
for (int i=0; i<cNum; ++i)
|
||||
{
|
||||
DBComponent::CastleDB::InsertCastleMineralInfo(m_DBComponent, m_dwCastleID, cMineralType,
|
||||
lpMineralInfo->m_wMineralID, lpMineralInfo->m_wAmount);
|
||||
|
||||
InsertMineralInfo(cMineralType, *lpMineralInfo);
|
||||
++lpMineralInfo;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Siege::ACCUMULATED_MINERAL :
|
||||
{
|
||||
DBComponent::CastleDB::DeleteCastleMineralInfo(m_DBComponent, m_dwCastleID, cMineralType);
|
||||
m_AccumulatedMineralMap.clear();
|
||||
|
||||
for (int i=0; i<cNum; ++i)
|
||||
{
|
||||
DBComponent::CastleDB::InsertCastleMineralInfo(m_DBComponent, m_dwCastleID, cMineralType,
|
||||
lpMineralInfo->m_wMineralID, lpMineralInfo->m_wAmount);
|
||||
|
||||
InsertMineralInfo(cMineralType, *lpMineralInfo);
|
||||
++lpMineralInfo;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default: return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void CCastleDB::SetTax(unsigned char cType, unsigned char cTax) // 세율 변경
|
||||
{
|
||||
if (cType < Castle::MAX_TAX_TYPE)
|
||||
{
|
||||
m_CastleTax[ cType ].m_cTax = cTax;
|
||||
m_CastleTax[ cType ].m_cTaxChangable = Castle::TAX_DISABLE;
|
||||
|
||||
DBComponent::CastleDB::UpdateCastleTax(m_DBComponent, m_dwCastleID, cType, cTax);
|
||||
DBComponent::CastleDB::UpdateCastleTaxChangable(m_DBComponent, m_dwCastleID, cType, Castle::TAX_DISABLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool CCastleDB::SetTaxInfo(const CastleTaxInfoDB& taxInfo)
|
||||
{
|
||||
if (taxInfo.m_cTaxType < Castle::MAX_TAX_TYPE)
|
||||
{
|
||||
m_CastleTax[ taxInfo.m_cTaxType ].m_cTaxType = taxInfo.m_cTaxType;
|
||||
m_CastleTax[ taxInfo.m_cTaxType ].m_cTax = taxInfo.m_cTax;
|
||||
m_CastleTax[ taxInfo.m_cTaxType ].m_dwTempTaxMoney = taxInfo.m_dwTempTaxMoney;
|
||||
m_CastleTax[ taxInfo.m_cTaxType ].m_dwTaxMoney = taxInfo.m_dwTaxMoney;
|
||||
m_CastleTax[ taxInfo.m_cTaxType ].m_cTaxChangable = taxInfo.m_cTaxChangable;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO : Log
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CCastleDB::SetMineralInfo(const CastleMineralInfoDB& mineralInfo)
|
||||
{
|
||||
if (mineralInfo.m_wAmount > 0)
|
||||
{
|
||||
switch (mineralInfo.m_cFlag)
|
||||
{
|
||||
case Siege::ACCUMULATED_MINERAL :
|
||||
{
|
||||
m_AccumulatedMineralMap.insert( std::make_pair(mineralInfo.m_wMineralID, mineralInfo.m_wAmount) ).second;
|
||||
}
|
||||
break;
|
||||
|
||||
case Siege::TEMPORARY_MINERAL :
|
||||
{
|
||||
m_TemporaryMineralMap.insert( std::make_pair(mineralInfo.m_wMineralID, mineralInfo.m_wAmount) ).second;
|
||||
}
|
||||
break;
|
||||
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CCastleDB::InsertMineralInfo(unsigned char cMineralType, const CastleMineral& mineralInfo)
|
||||
{
|
||||
if (mineralInfo.m_wAmount > 0)
|
||||
{
|
||||
switch (cMineralType)
|
||||
{
|
||||
case Siege::ACCUMULATED_MINERAL :
|
||||
{
|
||||
m_AccumulatedMineralMap.insert( std::make_pair(mineralInfo.m_wMineralID, mineralInfo.m_wAmount) ).second;
|
||||
}
|
||||
break;
|
||||
|
||||
case Siege::TEMPORARY_MINERAL :
|
||||
{
|
||||
m_TemporaryMineralMap.insert( std::make_pair(mineralInfo.m_wMineralID, mineralInfo.m_wAmount) ).second;
|
||||
}
|
||||
break;
|
||||
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CCastleDB::SetRight(CastleRight castleRight) // 관리 권한 변경
|
||||
{
|
||||
m_CastleRight = castleRight;
|
||||
|
||||
DBComponent::CastleDB::UpdateCastleRight(m_DBComponent, m_dwCastleID, reinterpret_cast<char*>(&m_CastleRight), sizeof(CastleRight));
|
||||
}
|
||||
|
||||
void CCastleDB::SetUpgradeItemInfo(unsigned short wItemID, unsigned char cItemNum)
|
||||
{
|
||||
m_wItemID = wItemID;
|
||||
m_cItemNum = cItemNum;
|
||||
|
||||
DBComponent::CastleDB::UpdateCastleUpgradeItemInfo(m_DBComponent, m_dwCastleID, m_wItemID, m_cItemNum);
|
||||
}
|
||||
108
Server/RylServerProject/RylDBAgentServer/Castle/CastleDB.h
Normal file
108
Server/RylServerProject/RylDBAgentServer/Castle/CastleDB.h
Normal file
@@ -0,0 +1,108 @@
|
||||
#ifndef _RYL_DBAGENT_CASTLE_DB_H_
|
||||
#define _RYL_DBAGENT_CASTLE_DB_H_
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <Castle/CastleConstants.h>
|
||||
#include <Creature/CreatureStructure.h>
|
||||
#include <Network/Packet/PacketStruct/CastlePacket.h>
|
||||
|
||||
// 전방 참조
|
||||
class CSiegeObjectDB;
|
||||
class CDBComponent;
|
||||
|
||||
namespace Castle
|
||||
{
|
||||
class CCastleDB
|
||||
{
|
||||
public:
|
||||
|
||||
~CCastleDB();
|
||||
|
||||
// 타입 정의
|
||||
typedef std::map<unsigned short, unsigned short> MineralInfoMap; // <wMineralID, wAmount>
|
||||
typedef std::map<unsigned long, CSiegeObjectDB*> CastleObjectMap; // <ObjectCID, lpCastleObject>
|
||||
|
||||
bool ChangeCastleMaster(unsigned char cNation); // 성주 변경
|
||||
void LoseOwnership(); // 성 소유를 중립화
|
||||
|
||||
void CloseCastleGate(); // 성문을 닫는다.
|
||||
void OpenCastleGate(); // 성문을 연다. (부셔진 경우 복구)
|
||||
|
||||
void ChangeCastleObjectNation(unsigned char cNation); // 수성 오브젝트들의 국적을 변경
|
||||
void DestroyAllCastleArms(); // 수성 병기들을 병기 관리 NPC 로 만든다.
|
||||
|
||||
bool InsertCastleObject(CSiegeObjectDB* lpCastleObject); // 성 오브젝트 추가
|
||||
bool DeleteCastleObject(unsigned long dwCID); // 공성 병기 삭제
|
||||
bool DeleteCastleObject(CSiegeObjectDB* lpCastleObject); // 공성 병기 삭제
|
||||
|
||||
CSiegeObjectDB* GetCastleEmblem();
|
||||
CSiegeObjectDB* GetCastleGate();
|
||||
CSiegeObjectDB* GetCastleObject(unsigned long dwCastleObjectID);
|
||||
|
||||
void CheckEnableSiege(bool bIsSiegeTime);
|
||||
|
||||
// 공성 시간이 끝난 후 갱신된 성 정보 전송
|
||||
void UpdateSiegeCount();
|
||||
|
||||
void SetTax(unsigned char cType, unsigned char cTax); // 세율 변경
|
||||
void TakeTaxMoney(unsigned char cType, unsigned long dwTakeTaxMoney); // 세금 회수
|
||||
bool GainMineral(unsigned short wMineralID, unsigned short wAmount); // 광물 세금 회수
|
||||
bool SetTempTaxMoney(unsigned long* dwTempTaxMoney, unsigned long* dwTaxMoney); // 게임 서버로부터 임시 세금정보 업데이트
|
||||
bool SetMineralInfo(unsigned char cMineralType, unsigned char cNum, CastleMineral* lpMineralInfo); // 게임 서버로부터 광물 세금정보 업데이트
|
||||
bool InsertMineralInfo(unsigned char cMineralType, const CastleMineral& mineralInfo); // Mineral 추가
|
||||
void SetRight(CastleRight castleRight); // 관리 권한 변경
|
||||
void SetUpgradeItemInfo(unsigned short wItemID, unsigned char cItemNum);
|
||||
|
||||
bool SetTaxInfo(const CastleTaxInfoDB& taxInfo); // DB 에서 읽어들인 Tax 정보 설정
|
||||
bool SetMineralInfo(const CastleMineralInfoDB& mineralInfo); // DB 에서 읽어들인 Mineral 정보 설정
|
||||
|
||||
unsigned long GetCastleID() const { return m_dwCastleID; }
|
||||
unsigned long GetNation() const { return m_cNation; }
|
||||
unsigned char GetZone() const { return m_cZone; }
|
||||
unsigned char GetChannel() const { return m_cChannel; }
|
||||
|
||||
unsigned char GetTax(unsigned char cType) const { return m_CastleTax[cType].m_cTax; }
|
||||
unsigned long GetTaxMoney(unsigned char cType) const { return m_CastleTax[cType].m_dwTaxMoney; }
|
||||
unsigned char GetSiegeCount() const { return m_cSiegeCount; }
|
||||
unsigned char GetInvincibleCount() const { return m_cInvincibleCount; }
|
||||
unsigned short GetTotalSiegeCount() const { return m_wTotalSiegeCount; }
|
||||
unsigned long GetTotalTaxMoney() const { return m_dwTotalTaxMoney; }
|
||||
bool GetEnableSiege() const { return m_bEnableSiege; }
|
||||
|
||||
private:
|
||||
|
||||
CCastleDB(CDBComponent& DBComponent, const CastleInfoDB& CastleInfo);
|
||||
|
||||
CastleObjectMap m_CastleObjectMap; // 성 관련 오브젝트맵
|
||||
|
||||
unsigned long m_dwCastleID; // 성 혹은 마을 ID
|
||||
unsigned char m_cNation; // 성을 차지한 국가
|
||||
unsigned char m_cZone; // 성이 있는 존 번호
|
||||
unsigned char m_cChannel; // 성이 있는 채널 번호
|
||||
unsigned char m_cNameID; // 성의 이름 ID ( 1부터~~ )
|
||||
unsigned char m_cSiegeCount; // 공성 횟수
|
||||
unsigned char m_cInvincibleCount; // 무적 횟수
|
||||
unsigned short m_wTotalSiegeCount; // 누적 공성 횟수
|
||||
unsigned long m_dwTotalTaxMoney; // 누적 세금 회수량
|
||||
unsigned short m_wItemID; // 업그레이드에 사용할 보석 아이템 ID
|
||||
unsigned char m_cItemNum; // 업그레이드에 사용할 보석 아이템 갯수
|
||||
|
||||
CastleRight m_CastleRight; // 성 관리 권한
|
||||
Position m_BackDoorPos[2]; // 뒷문 사용시 안/밖위치
|
||||
|
||||
CastleTaxInfo m_CastleTax[Castle::MAX_TAX_TYPE]; // 세율 및 세금 정보
|
||||
|
||||
MineralInfoMap m_AccumulatedMineralMap; // 누적 광물 세금
|
||||
MineralInfoMap m_TemporaryMineralMap; // 임시 광물 세금
|
||||
|
||||
bool m_bEnableSiege; // 현재 공성이 가능한가?
|
||||
|
||||
CDBComponent& m_DBComponent;
|
||||
|
||||
friend class CCastleDBMgr;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // _RYL_DBAGENT_CASTLE_DB_H_
|
||||
532
Server/RylServerProject/RylDBAgentServer/Castle/CastleDBMgr.cpp
Normal file
532
Server/RylServerProject/RylDBAgentServer/Castle/CastleDBMgr.cpp
Normal file
@@ -0,0 +1,532 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "CastleDB.h"
|
||||
#include "CastleDBMgr.h"
|
||||
|
||||
#include <DB/DBComponent.h>
|
||||
#include <Log/ServerLog.h>
|
||||
|
||||
#include <Utility/Setup/ServerSetup.h>
|
||||
#include <Utility/TokenlizedFile.h>
|
||||
|
||||
#include <Network/Packet/PacketCommand.h>
|
||||
#include <Network/Packet/WrapPacket.h>
|
||||
#include <Network/Packet/PacketStruct/CastlePacket.h>
|
||||
#include <Network/Stream/SendStream.h>
|
||||
#include <Network/Dispatch/GameDispatch.h>
|
||||
|
||||
#include <Creature/Siege/SiegeConstants.h>
|
||||
#include <Creature/Siege/SiegeObjectDB.h>
|
||||
#include <Creature/Siege/SiegeObjectDBMgr.h>
|
||||
|
||||
#include <Castle/CastleConstants.h>
|
||||
#include <Castle/CastleDB.h>
|
||||
#include <Castle/CastleDBComponent.h>
|
||||
|
||||
#include <atltime.h>
|
||||
|
||||
using namespace Castle;
|
||||
using namespace Siege;
|
||||
|
||||
|
||||
CCastleDB* CCastleDBMgr::CreateCastleDB(const CastleInfoDB& CastleInfo)
|
||||
{
|
||||
return 0 != m_lpDBComponent ? new CCastleDB(*m_lpDBComponent, CastleInfo) : 0;
|
||||
}
|
||||
|
||||
void CCastleDBMgr::DeleteCastleDB(CCastleDB* lpCastleDB)
|
||||
{
|
||||
delete lpCastleDB;
|
||||
}
|
||||
|
||||
|
||||
CCastleDBMgr& CCastleDBMgr::GetInstance()
|
||||
{
|
||||
static CCastleDBMgr castleDBMgr;
|
||||
return castleDBMgr;
|
||||
}
|
||||
|
||||
|
||||
CCastleDBMgr::CCastleDBMgr()
|
||||
: m_lpDBComponent(0),
|
||||
m_CastlePool(sizeof(CCastleDB))
|
||||
{
|
||||
}
|
||||
|
||||
CCastleDBMgr::~CCastleDBMgr()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
bool CCastleDBMgr::Initialize(CDBComponent& DBComponent)
|
||||
{
|
||||
m_lpDBComponent = &DBComponent;
|
||||
|
||||
if (true == CServerSetup::GetInstance().UseContents(GameRYL::SIEGE))
|
||||
{
|
||||
if (false == ReadCastleInfoDB()) return false;
|
||||
if (false == ReadCastleTaxInfoDB()) return false;
|
||||
if (false == ReadCastleMineralInfoDB()) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CCastleDBMgr::Destroy()
|
||||
{
|
||||
if (0 == m_CastleMap.size()) return;
|
||||
|
||||
CastleMap::iterator CastleItr = m_CastleMap.begin();
|
||||
CastleMap::iterator CastleEnd = m_CastleMap.end();
|
||||
|
||||
while (CastleItr != CastleEnd)
|
||||
{
|
||||
CCastleDB* lpCastleDB = CastleItr->second;
|
||||
|
||||
if (lpCastleDB)
|
||||
{
|
||||
DeleteCastleDB(lpCastleDB);
|
||||
}
|
||||
|
||||
++CastleItr;
|
||||
}
|
||||
|
||||
m_CastleMap.clear();
|
||||
}
|
||||
|
||||
|
||||
void CCastleDBMgr::CheckEnableSiegeForAllCastle(bool bIsSiegeTime)
|
||||
{
|
||||
CCastleDB* lpCastle;
|
||||
CastleMap::iterator itr = m_CastleMap.begin();
|
||||
while (itr != m_CastleMap.end())
|
||||
{
|
||||
lpCastle = itr->second;
|
||||
if (lpCastle)
|
||||
{
|
||||
lpCastle->CheckEnableSiege(bIsSiegeTime);
|
||||
}
|
||||
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
|
||||
void CCastleDBMgr::UpdateSiegeCount()
|
||||
{
|
||||
CCastleDB* lpCastle;
|
||||
CastleMap::iterator itr = m_CastleMap.begin();
|
||||
while (itr != m_CastleMap.end())
|
||||
{
|
||||
lpCastle = itr->second;
|
||||
if (lpCastle)
|
||||
{
|
||||
lpCastle->UpdateSiegeCount();
|
||||
}
|
||||
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
|
||||
void CCastleDBMgr::DestroyAllCastleArms()
|
||||
{
|
||||
CCastleDB* lpCastle;
|
||||
CastleMap::iterator itr = m_CastleMap.begin();
|
||||
while (itr != m_CastleMap.end())
|
||||
{
|
||||
lpCastle = itr->second;
|
||||
if (lpCastle)
|
||||
{
|
||||
lpCastle->DestroyAllCastleArms();
|
||||
}
|
||||
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
|
||||
void CCastleDBMgr::CloseCastleGate()
|
||||
{
|
||||
CCastleDB* lpCastle;
|
||||
CastleMap::iterator itr = m_CastleMap.begin();
|
||||
while (itr != m_CastleMap.end())
|
||||
{
|
||||
lpCastle = itr->second;
|
||||
|
||||
if (lpCastle)
|
||||
{
|
||||
lpCastle->CloseCastleGate();
|
||||
}
|
||||
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
|
||||
void CCastleDBMgr::OpenCastleGate()
|
||||
{
|
||||
CCastleDB* lpCastle;
|
||||
CastleMap::iterator itr = m_CastleMap.begin();
|
||||
while (itr != m_CastleMap.end())
|
||||
{
|
||||
lpCastle = itr->second;
|
||||
if (lpCastle && !lpCastle->GetEnableSiege())
|
||||
{
|
||||
lpCastle->OpenCastleGate();
|
||||
}
|
||||
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
|
||||
bool CCastleDBMgr::ReadCastleInfoDB()
|
||||
{
|
||||
const int MAX_ROWS = 10;
|
||||
int nGetRows = 0;
|
||||
|
||||
char szBuffer[CDBComponent::QUERY_BUFFER_LEN];
|
||||
_snprintf(szBuffer, CDBComponent::QUERY_BUFFER_LEN - 1,
|
||||
"SELECT "
|
||||
"TblCastleInfo.nCastleID, "
|
||||
"TblCastleInfo.tnNation, "
|
||||
"TblCastleInfo.tnZone, "
|
||||
"TblCastleInfo.tnChannel, "
|
||||
"TblCastleInfo.tnName, "
|
||||
"TblCastleInfo.tnSiegeCount, "
|
||||
"TblCastleInfo.tnInvincibleCount, "
|
||||
"TblCastleInfo.snTotalSiegeCount, "
|
||||
"TblCastleInfo.nTotalTaxMoney, "
|
||||
"TblCastleInfo.bRight, "
|
||||
"TblCastleInfo.fPosInX, "
|
||||
"TblCastleInfo.fPosInY, "
|
||||
"TblCastleInfo.fPosInZ, "
|
||||
"TblCastleInfo.fPosOutX, "
|
||||
"TblCastleInfo.fPosOutY, "
|
||||
"TblCastleInfo.fPosOutZ, "
|
||||
"TblCastleInfo.snItemID, "
|
||||
"TblCastleInfo.tnItemNum "
|
||||
"FROM TblCastleInfo");
|
||||
|
||||
szBuffer[CDBComponent::QUERY_BUFFER_LEN - 1] = 0;
|
||||
|
||||
if (0 == m_lpDBComponent || !m_lpDBComponent->ExecuteQuery(szBuffer))
|
||||
{
|
||||
ERRLOG2(g_Log, "Castle DB 얻어오기 실패 : %s %s",
|
||||
m_lpDBComponent->GetErrorString(), m_lpDBComponent->GetQueryBuffer());
|
||||
return false;
|
||||
}
|
||||
|
||||
CastleInfoDB* castleInfo = new CastleInfoDB[MAX_ROWS];
|
||||
memset(castleInfo, 0, sizeof(CastleInfoDB) * MAX_ROWS);
|
||||
|
||||
while (m_lpDBComponent->GetData((void**)castleInfo, sizeof(CastleInfoDB), MAX_ROWS, &nGetRows))
|
||||
{
|
||||
if (0 == nGetRows) { break; }
|
||||
|
||||
for (CastleInfoDB* lpCastleInfo = castleInfo; nGetRows > 0; --nGetRows, ++lpCastleInfo)
|
||||
{
|
||||
CreateCastle(*lpCastleInfo);
|
||||
}
|
||||
|
||||
memset(castleInfo, 0, sizeof(CastleInfoDB) * MAX_ROWS);
|
||||
}
|
||||
|
||||
delete [] castleInfo;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CCastleDBMgr::ReadCastleTaxInfoDB()
|
||||
{
|
||||
const int MAX_ROWS = 1000;
|
||||
int nGetRows = 0;
|
||||
|
||||
char szBuffer[CDBComponent::QUERY_BUFFER_LEN];
|
||||
_snprintf(szBuffer, CDBComponent::QUERY_BUFFER_LEN - 1,
|
||||
"SELECT "
|
||||
"TblCastleTaxInfo.nCastleID, "
|
||||
"TblCastleTaxInfo.tnType, "
|
||||
"TblCastleTaxInfo.tnTax, "
|
||||
"TblCastleTaxInfo.nTempMoney, "
|
||||
"TblCastleTaxInfo.nTaxMoney, "
|
||||
"TblCastleTaxInfo.tnTaxChangable "
|
||||
"FROM TblCastleInfo, TblCastleTaxInfo WHERE "
|
||||
"TblCastleInfo.nCastleID = TblCastleTaxInfo.nCastleID");
|
||||
|
||||
szBuffer[CDBComponent::QUERY_BUFFER_LEN - 1] = 0;
|
||||
if (0 == m_lpDBComponent || !m_lpDBComponent->ExecuteQuery(szBuffer))
|
||||
{
|
||||
ERRLOG0(g_Log, "Castle Tax DB 얻어오기 실패");
|
||||
return false;
|
||||
}
|
||||
|
||||
CastleTaxInfoDB* castleTaxInfo = new CastleTaxInfoDB[MAX_ROWS];
|
||||
memset(castleTaxInfo, 0, sizeof(CastleTaxInfoDB) * MAX_ROWS);
|
||||
|
||||
while (m_lpDBComponent->GetData((void**)castleTaxInfo, sizeof(CastleTaxInfoDB), MAX_ROWS, &nGetRows))
|
||||
{
|
||||
if (0 == nGetRows) { break; }
|
||||
|
||||
for (CastleTaxInfoDB* lpCastleTaxInfo = castleTaxInfo; nGetRows > 0; --nGetRows, ++lpCastleTaxInfo)
|
||||
{
|
||||
unsigned long dwCastleID = Castle::CASTLE_BIT | lpCastleTaxInfo->m_dwCastleID;
|
||||
CCastleDB* lpCastle = GetCastle(dwCastleID);
|
||||
if (NULL != lpCastle)
|
||||
{
|
||||
lpCastle->SetTaxInfo(*lpCastleTaxInfo);
|
||||
}
|
||||
}
|
||||
|
||||
memset(castleTaxInfo, 0, sizeof(CastleTaxInfoDB) * MAX_ROWS);
|
||||
}
|
||||
|
||||
delete [] castleTaxInfo;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CCastleDBMgr::ReadCastleMineralInfoDB()
|
||||
{
|
||||
const int MAX_ROWS = 10240;
|
||||
int nGetRows = 0;
|
||||
|
||||
char szBuffer[CDBComponent::QUERY_BUFFER_LEN];
|
||||
_snprintf(szBuffer, CDBComponent::QUERY_BUFFER_LEN - 1,
|
||||
"SELECT "
|
||||
"TblCastleMineralInfo.nCastleID, "
|
||||
"TblCastleMineralInfo.snMineralID, "
|
||||
"TblCastleMineralInfo.snAmount, "
|
||||
"TblCastleMineralInfo.tnFlag "
|
||||
"FROM TblCastleInfo, TblCastleMineralInfo WHERE "
|
||||
"TblCastleInfo.nCastleID = TblCastleMineralInfo.nCastleID");
|
||||
|
||||
szBuffer[CDBComponent::QUERY_BUFFER_LEN - 1] = 0;
|
||||
if (0 == m_lpDBComponent || !m_lpDBComponent->ExecuteQuery(szBuffer))
|
||||
{
|
||||
ERRLOG0(g_Log, "Castle Mineral DB 얻어오기 실패");
|
||||
return false;
|
||||
}
|
||||
|
||||
CastleMineralInfoDB* mineralInfo = new CastleMineralInfoDB[MAX_ROWS];
|
||||
memset(mineralInfo, 0, sizeof(CastleMineralInfoDB) * MAX_ROWS);
|
||||
|
||||
while (m_lpDBComponent->GetData((void**)mineralInfo, sizeof(CastleMineralInfoDB), MAX_ROWS, &nGetRows))
|
||||
{
|
||||
if (0 == nGetRows) { break; }
|
||||
|
||||
for (CastleMineralInfoDB* lpMineralInfo = mineralInfo; nGetRows > 0; --nGetRows, ++lpMineralInfo)
|
||||
{
|
||||
unsigned long dwCastleID = Castle::CASTLE_BIT | lpMineralInfo->m_dwCastleID;
|
||||
CCastleDB* lpCastle = GetCastle(dwCastleID);
|
||||
if (NULL != lpCastle)
|
||||
{
|
||||
lpCastle->SetMineralInfo(*lpMineralInfo);
|
||||
}
|
||||
}
|
||||
|
||||
memset(mineralInfo, 0, sizeof(CastleMineralInfoDB) * MAX_ROWS);
|
||||
}
|
||||
|
||||
delete [] mineralInfo;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
CCastleDB* CCastleDBMgr::CreateCastle(const CastleInfoDB& CastleInfo)
|
||||
{
|
||||
CCastleDB* lpCastle = 0;
|
||||
|
||||
if (0 != m_lpDBComponent)
|
||||
{
|
||||
lpCastle = CreateCastleDB(CastleInfo);
|
||||
|
||||
if (0 != lpCastle)
|
||||
{
|
||||
if ( !m_CastleMap.insert(std::make_pair(lpCastle->GetCastleID(), lpCastle)).second )
|
||||
{
|
||||
DeleteCastleDB(lpCastle);
|
||||
lpCastle = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return lpCastle;
|
||||
}
|
||||
|
||||
|
||||
|
||||
CCastleDB* CCastleDBMgr::GetCastle(unsigned long dwCastleID)
|
||||
{
|
||||
CastleMap::iterator itr = m_CastleMap.find(dwCastleID);
|
||||
if (itr != m_CastleMap.end())
|
||||
{
|
||||
return itr->second;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CCastleDBMgr::GetCastleSiegeInfo(CastleSiegeInfo* lpCastleSiegeInfo, unsigned char& cNum, unsigned short& wSize)
|
||||
{
|
||||
if (NULL == lpCastleSiegeInfo)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (CastleMap::iterator itr = m_CastleMap.begin(); itr != m_CastleMap.end(); ++itr)
|
||||
{
|
||||
CCastleDB* lpCastle = itr->second;
|
||||
if (NULL == lpCastle)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
lpCastleSiegeInfo->m_dwCastleID = lpCastle->m_dwCastleID;
|
||||
lpCastleSiegeInfo->m_bEnableSiege = lpCastle->m_bEnableSiege;
|
||||
++lpCastleSiegeInfo;
|
||||
|
||||
++cNum;
|
||||
wSize += sizeof(CastleSiegeInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CCastleDBMgr::SendCastleInfo(CSendStream& SendStream, unsigned char cZone, unsigned char cChannel)
|
||||
{
|
||||
const unsigned short MAX_CASTLE_SEND_BUFFER =
|
||||
sizeof(PktCastleInfo) + sizeof(CastleInfoDB) + sizeof(CastleTaxInfo) * MAX_TAX_TYPE +
|
||||
sizeof(CastleMineralInfo) + sizeof(CastleMineral) * MAX_CASTLE_MINERAL_NUM +
|
||||
sizeof(CastleObjectInfo) * MAX_CASTLE_OBJECT_NUM;
|
||||
|
||||
char szBuffer[MAX_CASTLE_SEND_BUFFER];
|
||||
unsigned short usBufferSize = 0;
|
||||
unsigned char cCastleObjectNum = 0; // 성 관련 오브젝트 수
|
||||
bool bFirst = true;
|
||||
|
||||
for (CastleMap::iterator itr = m_CastleMap.begin(); itr != m_CastleMap.end(); ++itr)
|
||||
{
|
||||
CCastleDB* lpCastle = itr->second;
|
||||
if (NULL == lpCastle)
|
||||
{
|
||||
ERRLOG0(g_Log, "NULL 성이 포함되어 있습니다.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (lpCastle->GetZone() != cZone || lpCastle->GetChannel() != cChannel)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (SerializeOut(lpCastle, szBuffer + sizeof(PktCastleInfo), usBufferSize, cCastleObjectNum))
|
||||
{
|
||||
PktCastleInfo* lpPktCastleInfo = reinterpret_cast<PktCastleInfo*>(szBuffer);
|
||||
|
||||
lpPktCastleInfo->m_cCastleObjectNum = cCastleObjectNum;
|
||||
lpPktCastleInfo->m_wSize = usBufferSize;
|
||||
lpPktCastleInfo->m_bStartFlag = bFirst;
|
||||
|
||||
SendStream.WrapCompress(szBuffer,
|
||||
static_cast<unsigned short>(sizeof(PktCastleInfo) + usBufferSize), CmdCastleInfo, 0, 0);
|
||||
}
|
||||
|
||||
bFirst = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool CCastleDBMgr::SerializeOut(CCastleDB* lpCastle_In, char* lpBuffer_Out, unsigned short& wBufferSize_Out, unsigned char& cDefensiveArmsNum_Out)
|
||||
{
|
||||
if (NULL == lpCastle_In || NULL == lpBuffer_Out) return false;
|
||||
|
||||
wBufferSize_Out = 0;
|
||||
cDefensiveArmsNum_Out = 0;
|
||||
|
||||
// 성 정보
|
||||
CastleInfoDB* lpCastleInfoDB = reinterpret_cast<CastleInfoDB*>(lpBuffer_Out);
|
||||
|
||||
lpCastleInfoDB->m_dwCastleID = lpCastle_In->m_dwCastleID;
|
||||
lpCastleInfoDB->m_cNation = lpCastle_In->m_cNation;
|
||||
lpCastleInfoDB->m_cZone = lpCastle_In->m_cZone;
|
||||
lpCastleInfoDB->m_cChannel = lpCastle_In->m_cChannel;
|
||||
lpCastleInfoDB->m_cNameID = lpCastle_In->m_cNameID;
|
||||
lpCastleInfoDB->m_cSiegeCount = lpCastle_In->m_cSiegeCount;
|
||||
lpCastleInfoDB->m_cInvincibleCount = lpCastle_In->m_cInvincibleCount;
|
||||
lpCastleInfoDB->m_wTotalSiegeCount = lpCastle_In->m_wTotalSiegeCount;
|
||||
lpCastleInfoDB->m_dwTotalTaxMoney = lpCastle_In->m_dwTotalTaxMoney;
|
||||
lpCastleInfoDB->m_InPos.fPointX = lpCastle_In->m_BackDoorPos[0].m_fPointX;
|
||||
lpCastleInfoDB->m_InPos.fPointY = lpCastle_In->m_BackDoorPos[0].m_fPointY;
|
||||
lpCastleInfoDB->m_InPos.fPointZ = lpCastle_In->m_BackDoorPos[0].m_fPointZ;
|
||||
lpCastleInfoDB->m_OutPos.fPointX = lpCastle_In->m_BackDoorPos[1].m_fPointX;
|
||||
lpCastleInfoDB->m_OutPos.fPointY = lpCastle_In->m_BackDoorPos[1].m_fPointY;
|
||||
lpCastleInfoDB->m_OutPos.fPointZ = lpCastle_In->m_BackDoorPos[1].m_fPointZ;
|
||||
lpCastleInfoDB->m_wItemID = lpCastle_In->m_wItemID;
|
||||
lpCastleInfoDB->m_cItemNum = lpCastle_In->m_cItemNum;
|
||||
::memcpy(&lpCastleInfoDB->m_szRight, &lpCastle_In->m_CastleRight, sizeof(CastleRight));
|
||||
|
||||
wBufferSize_Out += sizeof(CastleInfoDB);
|
||||
|
||||
// 성 세율 및 세금 정보
|
||||
CastleTaxInfo* lpCastleTaxInfo = reinterpret_cast<CastleTaxInfo*>( lpCastleInfoDB + 1 );
|
||||
for (int i=0; i<MAX_TAX_TYPE; ++i)
|
||||
{
|
||||
*lpCastleTaxInfo = lpCastle_In->m_CastleTax[ i ];
|
||||
++lpCastleTaxInfo;
|
||||
}
|
||||
|
||||
wBufferSize_Out += sizeof(CastleTaxInfo) * MAX_TAX_TYPE;
|
||||
|
||||
// 성 광물 세금 정보
|
||||
CastleMineralInfo* lpCastleMineralInfo = reinterpret_cast<CastleMineralInfo*>( lpCastleTaxInfo );
|
||||
CastleMineral* lpCastleMineral = reinterpret_cast<CastleMineral*>( lpCastleMineralInfo + 1 );
|
||||
|
||||
lpCastleMineralInfo->m_cAccumulatedNum = static_cast<unsigned char>( lpCastle_In->m_AccumulatedMineralMap.size() );
|
||||
lpCastleMineralInfo->m_cTemporaryNum = static_cast<unsigned char>( lpCastle_In->m_TemporaryMineralMap.size() );
|
||||
unsigned short wSize = sizeof(CastleMineralInfo);
|
||||
|
||||
CCastleDB::MineralInfoMap::iterator MineralItr = lpCastle_In->m_AccumulatedMineralMap.begin();
|
||||
CCastleDB::MineralInfoMap::iterator MineralEnd = lpCastle_In->m_AccumulatedMineralMap.end();
|
||||
while (MineralItr != MineralEnd)
|
||||
{
|
||||
lpCastleMineral->m_wMineralID = MineralItr->first;
|
||||
lpCastleMineral->m_wAmount = MineralItr->second;
|
||||
|
||||
wSize += sizeof(CastleMineral);
|
||||
++lpCastleMineral;
|
||||
++MineralItr;
|
||||
}
|
||||
|
||||
MineralItr = lpCastle_In->m_TemporaryMineralMap.begin();
|
||||
MineralEnd = lpCastle_In->m_TemporaryMineralMap.end();
|
||||
while (MineralItr != MineralEnd)
|
||||
{
|
||||
lpCastleMineral->m_wMineralID = MineralItr->first;
|
||||
lpCastleMineral->m_wAmount = MineralItr->second;
|
||||
|
||||
wSize += sizeof(CastleMineral);
|
||||
++lpCastleMineral;
|
||||
++MineralItr;
|
||||
}
|
||||
|
||||
lpCastleMineralInfo->m_wSize = wSize;
|
||||
wBufferSize_Out += wSize;
|
||||
|
||||
// 성 관련 오브젝트 정보
|
||||
unsigned short wBufferSize;
|
||||
CastleObjectInfo* lpCastleObjectInfo = reinterpret_cast<CastleObjectInfo*>( lpCastleMineral );
|
||||
CCastleDB::CastleObjectMap::iterator ObjectItr = lpCastle_In->m_CastleObjectMap.begin();
|
||||
CCastleDB::CastleObjectMap::iterator ObjectEnd = lpCastle_In->m_CastleObjectMap.end();
|
||||
|
||||
while (ObjectItr != ObjectEnd)
|
||||
{
|
||||
CSiegeObjectDB* lpCastleObject = ObjectItr->second;
|
||||
if (lpCastleObject)
|
||||
{
|
||||
if (true == CSiegeObjectDBMgr::GetInstance().SerializeOutCastleObject(lpCastleObject,
|
||||
reinterpret_cast<char*>(lpCastleObjectInfo), wBufferSize))
|
||||
{
|
||||
++lpCastleObjectInfo;
|
||||
++cDefensiveArmsNum_Out;
|
||||
wBufferSize_Out += wBufferSize;
|
||||
}
|
||||
}
|
||||
|
||||
++ObjectItr;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
#ifndef _RYL_DBAGENT_CASTLE_DB_MANAGER_H_
|
||||
#define _RYL_DBAGENT_CASTLE_DB_MANAGER_H_
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <Network/Packet/PacketStruct/CastlePacket.h>
|
||||
#include <Creature/CreatureStructure.h>
|
||||
|
||||
#include <boost/pool/pool.hpp>
|
||||
#include <boost/pool/pool_alloc.hpp>
|
||||
|
||||
// 전방 참조
|
||||
class CDBComponent;
|
||||
class CSendStream;
|
||||
class CSiegeObjectDB;
|
||||
class CSiegeObjectDBMgr;
|
||||
|
||||
namespace Castle
|
||||
{
|
||||
// 전방 참조
|
||||
class CCastleDB;
|
||||
|
||||
class CCastleDBMgr
|
||||
{
|
||||
public:
|
||||
|
||||
static CCastleDBMgr& GetInstance();
|
||||
|
||||
// <CastleID, lpCastle>
|
||||
typedef std::map<unsigned long, CCastleDB*, std::less<unsigned long>,
|
||||
boost::fast_pool_allocator<std::pair<unsigned long, CCastleDB*> > > CastleMap;
|
||||
|
||||
bool Initialize(CDBComponent& DBComponent);
|
||||
void Destroy();
|
||||
|
||||
void CheckEnableSiegeForAllCastle(bool bIsSiegeTime);
|
||||
void UpdateSiegeCount();
|
||||
void DestroyAllCastleArms();
|
||||
|
||||
void CloseCastleGate();
|
||||
void OpenCastleGate();
|
||||
|
||||
CCastleDB* GetCastle(unsigned long dwCastleID);
|
||||
void GetCastleSiegeInfo(CastleSiegeInfo* lpCastleSiegeInfo, unsigned char& cNum, unsigned short& wSize);
|
||||
|
||||
// GameServer 로의 Send 함수
|
||||
void SendCastleInfo(CSendStream& SendStream, unsigned char cZone, unsigned char cChannel);
|
||||
|
||||
private:
|
||||
|
||||
CCastleDBMgr();
|
||||
~CCastleDBMgr();
|
||||
|
||||
bool ReadCastleInfoDB();
|
||||
bool ReadCastleTaxInfoDB();
|
||||
bool ReadCastleMineralInfoDB();
|
||||
|
||||
CCastleDB* CreateCastle(const CastleInfoDB& CastleInfo); // DB 에서 읽어와서 생성
|
||||
|
||||
bool SerializeOut(CCastleDB* lpCastle_In, char* lpBuffer_Out,
|
||||
unsigned short& wBufferSize_Out, unsigned char& cDefensiveArmsNum_Out);
|
||||
|
||||
CCastleDB* CreateCastleDB(const CastleInfoDB& CastleInfo);
|
||||
void DeleteCastleDB(CCastleDB* lpCastleDB);
|
||||
|
||||
CDBComponent* m_lpDBComponent;
|
||||
|
||||
boost::pool<> m_CastlePool;
|
||||
CastleMap m_CastleMap;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif // _CASTLE_MANAGER_H_
|
||||
Reference in New Issue
Block a user