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>
760 lines
22 KiB
C++
760 lines
22 KiB
C++
#include "stdafx.h"
|
|
#include "RYL_AgentServerTable.h"
|
|
#include "RYL_AgentServerDispatch.h"
|
|
#include "RYL_AdminMgrDispatch.h"
|
|
|
|
#include <Parser/ServerInfo.h>
|
|
#include <Item/ItemFactory.h>
|
|
#include <Log/ServerLog.h>
|
|
|
|
#include <Network/Packet/WrapPacket.h>
|
|
#include <Network/Packet/PacketCommand.h>
|
|
#include <Network/Packet/PacketStruct/ServerInfo.h>
|
|
#include <Network/Packet/PacketStruct/ServerPacket.h>
|
|
#include <Network/Packet/PacketStruct/GuildPacket.h>
|
|
#include <Network/Winsock/SocketFactory.h>
|
|
#include <Network/Protocol/RYL_AdminMgrProtocol.h>
|
|
#include <Network/Buffer/RYL_CumulateBuffer.h>
|
|
#include <Network/Session/Session.h>
|
|
|
|
#include "ClientDispatchTable.h"
|
|
|
|
|
|
|
|
CMultiDispatch& CRylAgentServerDispatch::GetDispatchTable()
|
|
{
|
|
static CMultiDispatch multiDispatch;
|
|
return multiDispatch;
|
|
}
|
|
|
|
void CRylAgentServerDispatch::SetDispatchInfo(long dwServerGroup, char* ServerName)
|
|
{
|
|
m_dwServerGroup = dwServerGroup;
|
|
strncpy(m_szServerName, ServerName, 256);
|
|
}
|
|
|
|
void CRylAgentServerDispatch::Destroy()
|
|
{
|
|
delete this;
|
|
}
|
|
|
|
bool CRylAgentServerDispatch::DispatchPacket(PktBase* lpPktBase)
|
|
{
|
|
unsigned char cCmd = lpPktBase->GetCmd();
|
|
|
|
switch(cCmd)
|
|
{
|
|
case PktAgentServer::PktCMD::CmdSysServerLogin: return CmdSysServerLogin(lpPktBase);
|
|
case PktAgentServer::PktCMD::CmdAdminToolGetData: return CmdAdminToolGetData(lpPktBase);
|
|
case PktAgentServer::PktCMD::CmdAdminToolSetData: return CmdAdminToolSetData(lpPktBase);
|
|
case CmdItemQtyCheck: return ItemQtyControlAck(lpPktBase);
|
|
case CmdGuildPosition: return GuildPositionAck(lpPktBase);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool CRylAgentServerDispatch::CmdAdminToolGetData(PktBase* lpPktBase)
|
|
{
|
|
PktAgentServer::PktAdminToolGetDataAck* lpGetDataAck =
|
|
static_cast<PktAgentServer::PktAdminToolGetDataAck*>(lpPktBase);
|
|
|
|
char* lpData = reinterpret_cast<char*>(lpGetDataAck + 1);
|
|
|
|
CServerRequestKeeper::RequestInfo RequestInfo;
|
|
|
|
unsigned long dwUID = lpGetDataAck->m_dwUID;
|
|
unsigned long dwCID = lpGetDataAck->m_dwCID;
|
|
unsigned long dwRequestKey = lpGetDataAck->m_dwRequestKey;
|
|
unsigned short cError = lpGetDataAck->GetError();
|
|
bool bResult = false;
|
|
|
|
// 캐릭터 이름 변경 ----------------------------------------------------------------------------------
|
|
if (PktAgentServer::PktAdminToolGetData::CHANGE_CHAR_NAME == lpGetDataAck->m_cType)
|
|
{
|
|
CBuffer* lpBuffer = CREATE_BUFFER(GetBufferFactory(), sizeof(PktAdminMgr::PktChangeName));
|
|
PktAdminMgr::PktChangeName* lpPktChangeName =
|
|
reinterpret_cast<PktAdminMgr::PktChangeName*>(lpBuffer->begin());
|
|
|
|
lpPktChangeName->m_dwCID = dwCID;
|
|
lpPktChangeName->m_dwServerGroup = m_dwServerGroup;
|
|
lpPktChangeName->m_dwRequest = dwRequestKey;
|
|
lpPktChangeName->m_dwUID = (unsigned long)cError;
|
|
|
|
if (false == PacketWrap::WrapHeader(lpBuffer,
|
|
sizeof(PktAdminMgr::PktChangeName), PktAdminMgr::PktCMD::PktChangeNameAck, 0, 0))
|
|
{
|
|
ERRLOG0(g_Log, "패킷 랩핑 실패");
|
|
SAFE_RELEASE_BUFFER(lpBuffer);
|
|
}
|
|
else
|
|
{
|
|
if (false == CClientDispatchTable::GetInstance().SendAll(lpBuffer))
|
|
{
|
|
ERRLOG0(g_Log, "운영 클라이언트로 정보 전송 실패");
|
|
SAFE_RELEASE_BUFFER(lpBuffer);
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
unsigned short ExtraLength =
|
|
(lpGetDataAck->GetLen() - sizeof(PktAgentServer::PktAdminToolGetDataAck));
|
|
|
|
if (!m_AgentRequestKeeper.GetRequest(dwRequestKey, RequestInfo))
|
|
{
|
|
ERRLOG1(g_Log, "검색 요청 실패: 요청키- %d", dwRequestKey);
|
|
return true;
|
|
}
|
|
|
|
CModifyCharacter* lpModifyChar = m_ModifyCharMgr.GetCharacter(dwCID);
|
|
if ((cError != 0) || (NULL == lpModifyChar))
|
|
{
|
|
m_ModifyCharMgr.EraseChar(dwCID);
|
|
m_AgentRequestKeeper.Pop(dwRequestKey);
|
|
|
|
ERRLOG1(g_Log, "캐릭터 정보 받기 실패: err- %d", cError);
|
|
return true;
|
|
}
|
|
|
|
switch(lpGetDataAck->m_cType)
|
|
{
|
|
case PktAgentServer::PktAdminToolGetData::CHAR_BASIC_DATA:
|
|
bResult = m_ParseData.PARSE_CHAR_BASIC_DATA(lpModifyChar, lpData);
|
|
if(bResult)
|
|
{
|
|
SEND_CLIENT_DATA(lpPktBase, RequestInfo, PktAdminMgr::PktGetCharacterAck::CHAR_BASIC_DATA);
|
|
}
|
|
break;
|
|
case PktAgentServer::PktAdminToolGetData::CHAR_EXTRA_DATA:
|
|
bResult = m_ParseData.PARSE_CHAR_EXTRA_DATA(lpModifyChar, lpData);
|
|
if(bResult)
|
|
{
|
|
SEND_CLIENT_DATA(lpPktBase, RequestInfo, PktAdminMgr::PktGetCharacterAck::CHAR_EXTRA_DATA);
|
|
}
|
|
break;
|
|
case PktAgentServer::PktAdminToolGetData::CHAR_FRIEND_DATA:
|
|
bResult = m_ParseData.PARSE_CHAR_FRIEND_DATA(lpModifyChar, lpData, ExtraLength);
|
|
if(bResult)
|
|
{
|
|
SEND_CLIENT_DATA(lpPktBase, RequestInfo, PktAdminMgr::PktGetCharacterAck::CHAR_FRIEND_DATA);
|
|
}
|
|
break;
|
|
case PktAgentServer::PktAdminToolGetData::CHAR_BAN_DATA:
|
|
bResult = m_ParseData.PARSE_CHAR_BAN_DATA(lpModifyChar, lpData, ExtraLength);
|
|
if(bResult)
|
|
{
|
|
SEND_CLIENT_DATA(lpPktBase, RequestInfo, PktAdminMgr::PktGetCharacterAck::CHAR_BAN_DATA);
|
|
}
|
|
break;
|
|
case PktAgentServer::PktAdminToolGetData::STORE_12_DATA:
|
|
bResult = m_ParseData.PARSE_STORE_12_DATA(lpModifyChar, lpData);
|
|
if(bResult)
|
|
{
|
|
SEND_CLIENT_DATA(lpPktBase, RequestInfo, PktAdminMgr::PktGetCharacterAck::STORE_12_DATA);
|
|
}
|
|
break;
|
|
case PktAgentServer::PktAdminToolGetData::STORE_34_DATA:
|
|
bResult = m_ParseData.PARSE_STORE_34_DATA(lpModifyChar, lpData);
|
|
if(bResult)
|
|
{
|
|
SEND_CLIENT_DATA(lpPktBase, RequestInfo, PktAdminMgr::PktGetCharacterAck::STORE_34_DATA);
|
|
}
|
|
break;
|
|
case PktAgentServer::PktAdminToolGetData::FINISH_GET_DATA:
|
|
lpModifyChar->SetUID(dwUID);
|
|
lpModifyChar->SetCID(dwCID);
|
|
lpModifyChar->SetOldServerGroup(lpGetDataAck->m_cOldServerGroupID);
|
|
|
|
bResult = PARSE_FINISH_GET_DATA(dwRequestKey);
|
|
|
|
if(bResult)
|
|
{
|
|
SEND_CLIENT_DATA(lpPktBase, RequestInfo, PktAdminMgr::PktGetCharacterAck::FINISH_GET_DATA);
|
|
SyncDeposit(dwUID, dwCID, RequestInfo);
|
|
}
|
|
break;
|
|
}
|
|
|
|
if (!bResult)
|
|
{
|
|
m_AgentRequestKeeper.Pop(dwRequestKey);
|
|
m_ModifyCharMgr.EraseChar(dwCID);
|
|
ERRLOG4(g_Log, "캐릭터 데이터 초기화 실패: 요청키- %d, UID- %d, CID- %d, cType- %c",
|
|
dwRequestKey, dwUID, dwCID, lpGetDataAck->m_cType );
|
|
return true;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool CRylAgentServerDispatch::UpdateCharacter(CModifyCharacter* lpChar, unsigned __int64 dwSerial,
|
|
unsigned long dwUID, unsigned long dwCID, unsigned long dwRequestKey)
|
|
{
|
|
return m_ParseData.UpdateCharacter(lpChar, dwSerial, dwUID, dwCID, dwRequestKey);
|
|
}
|
|
|
|
bool CRylAgentServerDispatch::PARSE_FINISH_GET_DATA(unsigned long dwRequestKey)
|
|
{
|
|
m_AgentRequestKeeper.Pop(dwRequestKey);
|
|
return true;
|
|
}
|
|
|
|
// TODO : 현재 다른 운영자가 해당 창고를 편집중이면 다른 운영자의 운영 클라이언트에도 동기화 필요;
|
|
bool CRylAgentServerDispatch::SyncDeposit(unsigned long dwUID, unsigned long dwCID,
|
|
CServerRequestKeeper::RequestInfo& Info)
|
|
{
|
|
ItemData::CDepositLock::DepositInfo LockInfo;
|
|
unsigned short DepositBufferSize = sizeof(PktAdminMgr::PktSyncDeposit) + sizeof(STORE);
|
|
|
|
if (m_DepositLock.GetLockInfo(dwUID, LockInfo))
|
|
{
|
|
CModifyCharacter* lpCharacter = m_ModifyCharMgr.GetCharacter(LockInfo.m_dwCID);
|
|
|
|
if ((NULL != lpCharacter) && (LockInfo.m_dwCID != dwCID))
|
|
{
|
|
CModifyCharacter* lpSyncChar = m_ModifyCharMgr.GetCharacter(dwCID);
|
|
|
|
if (NULL != lpSyncChar)
|
|
{
|
|
Item::CDepositContainer& SyncContainer = lpSyncChar->GetDeposit();
|
|
|
|
SyncContainer.GetTab(0)->ClearItems();
|
|
SyncContainer.GetTab(1)->ClearItems();
|
|
SyncContainer.GetTab(2)->ClearItems();
|
|
SyncContainer.GetTab(3)->ClearItems();
|
|
|
|
for (int cnt = 0;cnt < 2; ++cnt)
|
|
{
|
|
CCumulateBuffer cBuffer(DepositBufferSize, &Info.m_lpPacketDispatch->GetSession());
|
|
|
|
unsigned short usBufferSize = DepositBufferSize;
|
|
char* lpBuffer = cBuffer.GetBuffer(sizeof(PktAdminMgr::PktSyncDeposit));
|
|
|
|
PktAdminMgr::PktSyncDeposit* lpSyncDeposit =
|
|
reinterpret_cast<PktAdminMgr::PktSyncDeposit*>(lpBuffer);
|
|
|
|
char* DepositBuffer = reinterpret_cast<char*>(lpSyncDeposit + 1);
|
|
|
|
LPSTORE lpStore = reinterpret_cast<LPSTORE>(DepositBuffer);
|
|
Item::CDepositContainer& DepositContainer = lpCharacter->GetDeposit();
|
|
|
|
const Item::CItemContainer* lpContainer0 = DepositContainer.GetTab((cnt * 2));
|
|
const Item::CItemContainer* lpContainer1 = DepositContainer.GetTab((cnt * 2) + 1);
|
|
|
|
lpSyncDeposit->m_dwUID = dwUID;
|
|
lpSyncDeposit->m_dwRequestID = Info.m_dwClientRequest;
|
|
|
|
if (cnt == 0)
|
|
{
|
|
lpSyncDeposit->m_cType = PktAdminMgr::PktSyncDeposit::Tab12;
|
|
}
|
|
else if(cnt == 1)
|
|
{
|
|
lpSyncDeposit->m_cType = PktAdminMgr::PktSyncDeposit::Tab34;
|
|
}
|
|
|
|
if ((NULL != lpContainer0) && (NULL != lpContainer1))
|
|
{
|
|
lpStore->dwSize = STORE::MAX_STORE_SIZE;
|
|
|
|
if (lpContainer0->SerializeOut(lpStore->Data, lpStore->dwSize))
|
|
{
|
|
unsigned long dwContainer0Size = lpStore->dwSize;
|
|
lpStore->dwSize = STORE::MAX_STORE_SIZE - dwContainer0Size;
|
|
|
|
if (lpContainer1->SerializeOut(lpStore->Data + dwContainer0Size, lpStore->dwSize))
|
|
{
|
|
lpStore->dwSize += dwContainer0Size;
|
|
cBuffer.ResizeLength(usBufferSize);
|
|
m_ParseData.PARSE_STORE_12_DATA(lpSyncChar, DepositBuffer);
|
|
PacketWrap::WrapHeader(lpBuffer,
|
|
usBufferSize, PktAdminMgr::PktCMD::PktDepositSync, 0 , 0);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
cBuffer.ResizeLength(0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
// 클라이언트에게 AgentServer로부터 받은 GetData를 보낸다.
|
|
bool CRylAgentServerDispatch::SEND_CLIENT_DATA(PktBase* lpPktBase, CServerRequestKeeper::RequestInfo& Info,
|
|
unsigned char cType)
|
|
{
|
|
PktAgentServer::PktAdminToolGetDataAck* lpSGetData =
|
|
static_cast<PktAgentServer::PktAdminToolGetDataAck*>(lpPktBase);
|
|
|
|
CSession* lpSession = &Info.m_lpPacketDispatch->GetSession();
|
|
|
|
unsigned short Src_CpySize = lpSGetData->GetLen() - sizeof(PktAgentServer::PktAdminToolGetDataAck);
|
|
char* Src_DataBuffer = reinterpret_cast<char*>(lpSGetData + 1);
|
|
unsigned short PktLength = Src_CpySize + sizeof(PktAdminMgr::PktGetCharacterAck);
|
|
|
|
bool bIsReleased = true;
|
|
|
|
CBuffer* lpBuffer = CREATE_BUFFER(GetBufferFactory(), PktLength);
|
|
if (NULL == lpBuffer)
|
|
{
|
|
ERRLOG0(g_Log, "버퍼 생성 실패");
|
|
return false;
|
|
}
|
|
|
|
PktAdminMgr::PktGetCharacterAck* lpPktGetChar =
|
|
reinterpret_cast<PktAdminMgr::PktGetCharacterAck*>(lpBuffer->begin());
|
|
|
|
char* Des_DataBuffer = reinterpret_cast<char*>(lpPktGetChar + 1);
|
|
|
|
lpPktGetChar->m_dwCID = lpSGetData->m_dwCID;
|
|
lpPktGetChar->m_dwUID = lpSGetData->m_dwUID;
|
|
lpPktGetChar->m_dwServerGroup = m_dwServerGroup;
|
|
lpPktGetChar->m_cOldServerGroupID = lpSGetData->m_cOldServerGroupID;
|
|
lpPktGetChar->m_dwRequestKey = Info.m_dwClientRequest;
|
|
lpPktGetChar->m_cType = cType;
|
|
|
|
CopyMemory(Des_DataBuffer, Src_DataBuffer, Src_CpySize);
|
|
|
|
if (false == PacketWrap::WrapHeader(lpBuffer,
|
|
PktLength, PktAdminMgr::PktCMD::PktGetCharacterAck, 0, 0))
|
|
{
|
|
ERRLOG0(g_Log, "수동으로 패킷을 릴리스합니다.");
|
|
bIsReleased = false;
|
|
}
|
|
else
|
|
{
|
|
if (false == lpSession->SendPending(lpBuffer))
|
|
{
|
|
ERRLOG3(g_Log, "Packet sending to client failed : UID- %d, CID- %d, cType- %d",
|
|
lpSGetData->m_dwUID, lpSGetData->m_dwCID, cType);
|
|
|
|
ERRLOG0(g_Log, "수동으로 패킷을 릴리스합니다.");
|
|
bIsReleased = false;
|
|
}
|
|
}
|
|
|
|
if (false == bIsReleased)
|
|
{
|
|
SAFE_RELEASE_BUFFER(lpBuffer);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool CRylAgentServerDispatch::CmdAdminToolSetData(PktBase* lpPktBase)
|
|
{
|
|
PktAgentServer::PktAdminToolSetDataAck* lpSetDataAck =
|
|
static_cast<PktAgentServer::PktAdminToolSetDataAck*>(lpPktBase);
|
|
|
|
CServerRequestKeeper::RequestInfo RequestInfo;
|
|
CModifyCharacter* lpModifyCharacter = NULL;
|
|
|
|
unsigned long dwUID = lpSetDataAck->m_dwUID;
|
|
unsigned long dwCID = lpSetDataAck->m_dwCID;
|
|
unsigned long dwRequestKey = lpSetDataAck->m_dwRequestKey;
|
|
unsigned long cError = lpSetDataAck->GetError();
|
|
|
|
bool bResult = false;
|
|
|
|
CModifyCharacter* lpModifyChar = m_ModifyCharMgr.GetCharacter(dwCID);
|
|
|
|
if (NULL == lpModifyChar)
|
|
{
|
|
// 로그작성
|
|
m_AgentRequestKeeper.Pop(dwRequestKey);
|
|
return true;
|
|
}
|
|
|
|
if (true != m_AgentRequestKeeper.GetRequest(dwRequestKey, RequestInfo))
|
|
{
|
|
ERRLOG1(g_Log, "Requestkey searching failed : requestkey- %d", dwRequestKey);
|
|
m_ModifyCharMgr.EraseChar(dwCID);
|
|
return true;
|
|
}
|
|
|
|
if (0 != cError)
|
|
{
|
|
CRylAdminMgrDispatch* lpClientDispatch =
|
|
static_cast<CRylAdminMgrDispatch*>(RequestInfo.m_lpPacketDispatch);
|
|
|
|
if (NULL != lpClientDispatch)
|
|
{
|
|
switch(cError)
|
|
{
|
|
case PktAgentServer::PktAdminToolSetData::UNKNOWN_ERROR:
|
|
lpClientDispatch->SendResult(PktAdminMgr::PktResult::UNKNOWN_ERROR);
|
|
break;
|
|
case PktAgentServer::PktAdminToolSetData::INVALID_UID_CID_ERROR:
|
|
lpClientDispatch->SendResult(PktAdminMgr::PktResult::INVALID_UID_CID_ERROR);
|
|
break;
|
|
case PktAgentServer::PktAdminToolSetData::LOGIN_ANOTHER_GAMESERVER:
|
|
lpClientDispatch->SendResult(PktAdminMgr::PktResult::LOGIN_ANOTHER_GAMESERVER);
|
|
break;
|
|
case PktAgentServer::PktAdminToolSetData::SESSION_OPEN_FAILED:
|
|
lpClientDispatch->SendResult(PktAdminMgr::PktResult::SESSION_OPEN_FAILED);
|
|
break;
|
|
case PktAgentServer::PktAdminToolSetData::ALREADY_LOGIN_USER_SESSION_OPEN:
|
|
lpClientDispatch->SendResult(PktAdminMgr::PktResult::ALREADY_LOGIN_USER_SESSION_OPEN);
|
|
break;
|
|
case PktAgentServer::PktAdminToolSetData::ANOTHER_CHAR_LOAD_FAILED:
|
|
lpClientDispatch->SendResult(PktAdminMgr::PktResult::ANOTHER_CHAR_LOAD_FAILED);
|
|
break;
|
|
case PktAgentServer::PktAdminToolSetData::SETTING_DATA_FAILED:
|
|
lpClientDispatch->SendResult(PktAdminMgr::PktResult::SETTING_DATA_FAILED);
|
|
break;
|
|
case PktAgentServer::PktAdminToolSetData::SESSION_START_FAILED:
|
|
lpClientDispatch->SendResult(PktAdminMgr::PktResult::SESSION_START_FAILED);
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ERRLOG0(g_Log, "Client dispatch searching failed");
|
|
}
|
|
|
|
ERRLOG1(g_Log, "Data sending failed : CMD- %d", cError);
|
|
|
|
m_ModifyCharMgr.EraseChar(dwCID);
|
|
|
|
return true;
|
|
}
|
|
|
|
switch(lpSetDataAck->m_cType)
|
|
{
|
|
case PktAgentServer::PktAdminToolSetData::FINISH_UPDATE_DATA:
|
|
m_AgentRequestKeeper.Pop(dwRequestKey); // 리퀘스트 삭제
|
|
lpModifyCharacter = m_ModifyCharMgr.GetCharacter(dwCID); // 캐릭터 정보를 가져온다.
|
|
|
|
if (NULL != lpModifyCharacter)
|
|
{
|
|
ItemData::CDepositLock::DepositInfo Info;
|
|
|
|
if (m_DepositLock.GetLockInfo(dwUID, Info)) // 현재 다른 사용자가 창고를 독점하고 있다.
|
|
{
|
|
if( ( Info.m_lpPacketDispatch == RequestInfo.m_lpPacketDispatch ) && // 독점하고 있는 사람이 나라면..
|
|
( Info.m_dwCID == dwCID ) )
|
|
{
|
|
if( true == lpModifyCharacter->isClose() ) // 작업완료후 캐릭터를 닫을까?
|
|
{
|
|
// 창고데이터 독점 권한 해제
|
|
m_DepositLock.DepositUnLock( dwUID );
|
|
}
|
|
}
|
|
}
|
|
|
|
// 저장후 삭제 대기라면... 편집리스트에서 삭제시켜주자
|
|
if( true == lpModifyCharacter->isClose() )
|
|
{
|
|
m_ModifyCharMgr.EraseChar( lpModifyCharacter->GetCID() );
|
|
}
|
|
else
|
|
{
|
|
// 저장 종료
|
|
lpModifyCharacter->SetSaveState(false);
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void CRylAgentServerDispatch::SetPaseSession()
|
|
{
|
|
m_ParseData.SetSession(&GetSession());
|
|
}
|
|
|
|
bool CRylAgentServerDispatch::Send(CBuffer* lpBuffer)
|
|
{
|
|
return GetSession().SendPending(lpBuffer);
|
|
}
|
|
|
|
void CRylAgentServerDispatch::Connected()
|
|
{
|
|
unsigned long dwServerGroup =
|
|
CAgentServerTable::GetInstance().GetGroupFromDBAgentIP(
|
|
GetSession().GetRemoteAddr().get_addr_in().sin_addr.S_un.S_addr);
|
|
|
|
if (CAgentServerTable::MAX_AGENT_SERVER <= dwServerGroup)
|
|
{
|
|
ERRLOG2(g_Log, "최대 서버그룹(%d)을 넘는 서버그룹으로 접속 시도: 그룹인덱스 - %d",
|
|
CAgentServerTable::MAX_AGENT_SERVER, dwServerGroup);
|
|
}
|
|
else
|
|
{
|
|
ServerLogin(dwServerGroup);
|
|
}
|
|
}
|
|
|
|
void CRylAgentServerDispatch::Disconnected()
|
|
{
|
|
GetDispatchTable().RemoveDispatch(m_dwServerGroup);
|
|
|
|
CAgentServerTable::GetInstance().Disconnected(
|
|
GetSession().GetRemoteAddr().get_addr_in().sin_addr.S_un.S_addr);
|
|
|
|
ConnectedAgentListAck(); // 클라이언트의 중계서버 연결 상태창 갱신
|
|
}
|
|
|
|
// 중계서버에 로그인
|
|
bool CRylAgentServerDispatch::ServerLogin(unsigned long dwServerGroup)
|
|
{
|
|
bool bIsReleased = true;
|
|
|
|
CBuffer* lpBuffer = CREATE_BUFFER(GetBufferFactory(), sizeof(PktAgentServer::PktSL));
|
|
|
|
if (NULL == lpBuffer)
|
|
{
|
|
ERRLOG0(g_Log, "버퍼 생성 실패");
|
|
return false;
|
|
}
|
|
|
|
PktAgentServer::PktSL* lpPktSL = reinterpret_cast<PktAgentServer::PktSL*>(lpBuffer->begin());
|
|
|
|
const int MAX_ADDRESS = 128;
|
|
char szAddress[MAX_ADDRESS];
|
|
|
|
CTCPFactory TcpFactory;
|
|
|
|
TcpFactory.GetNetworkInfo(szAddress, MAX_ADDRESS);
|
|
lpPktSL->m_Address.S_un.S_addr = inet_addr(szAddress);
|
|
|
|
char cChannel = 0;
|
|
CServerInfo& InfoScript = CServerInfo::GetInstance();
|
|
if(InfoScript.Reload())
|
|
{
|
|
const int MAX_BUFFER = 256;
|
|
const char* szCHBuffer = InfoScript.GetValue("SERVER_CH");
|
|
char szCH[MAX_BUFFER];
|
|
|
|
if(NULL != szCHBuffer)
|
|
{
|
|
strncpy(szCH, szCHBuffer, MAX_BUFFER);
|
|
szCH[MAX_BUFFER - 1] = 0;
|
|
|
|
cChannel = (char)atoi(szCH);
|
|
}
|
|
}
|
|
|
|
SERVER_ID serverID;
|
|
|
|
serverID.sID.Channel = cChannel;
|
|
serverID.sID.Group = static_cast<unsigned char>(dwServerGroup);
|
|
serverID.sID.ID = SERVER_ID::ADMIN_TOOL_ZONE;
|
|
serverID.sID.Type = CServerSetup::AdminToolServer;
|
|
|
|
m_dwServerID = lpPktSL->m_dwServerID = serverID.dwID;
|
|
|
|
if (false == PacketWrap::WrapHeader(lpBuffer,
|
|
sizeof(PktAgentServer::PktSL), PktAgentServer::PktCMD::CmdSysServerLogin, 0, 0))
|
|
{
|
|
ERRLOG0(g_Log, "수동으로 패킷을 릴리스합니다.");
|
|
bIsReleased = false;
|
|
}
|
|
else
|
|
{
|
|
if (false == GetSession().SendPending(lpBuffer))
|
|
{
|
|
ERRLOG0(g_Log, "수동으로 패킷을 릴리스합니다.");
|
|
bIsReleased = false;
|
|
}
|
|
}
|
|
|
|
if (false == bIsReleased)
|
|
{
|
|
SAFE_RELEASE_BUFFER(lpBuffer);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
// 중계서버 로그인에 성공했을 경우 Ack
|
|
bool CRylAgentServerDispatch::CmdSysServerLogin(PktBase* lpPktBase)
|
|
{
|
|
SERVER_ID SID;
|
|
PktSLAck* lpPktSLAck = static_cast<PktSLAck*>(lpPktBase);
|
|
|
|
const unsigned char MAX_BUFFER = 255;
|
|
|
|
SID.dwID = m_dwServerID;
|
|
|
|
Item::CItemFactory::GetInstance().SetItemUID(lpPktSLAck->m_dlItemUID);
|
|
|
|
// 로그인 성공시 DispatchTable에 추가
|
|
GetDispatchTable().SetDispatch(SID.GetGroup(), this);
|
|
|
|
CServerInfo& InfoScript = CServerInfo::GetInstance();
|
|
|
|
char szTmp[MAX_BUFFER];
|
|
_snprintf(szTmp, MAX_BUFFER, "SERVERGROUP_NAME_%02d", SID.GetGroup());
|
|
|
|
const char* szGroupName = InfoScript.GetValue(szTmp);
|
|
if(NULL != szGroupName)
|
|
{
|
|
char szServerNameBuffer[MAX_BUFFER];
|
|
strncpy(szServerNameBuffer, szGroupName, MAX_BUFFER); szServerNameBuffer[MAX_BUFFER - 1] = 0;
|
|
|
|
SetDispatchInfo(SID.GetGroup(), szServerNameBuffer);
|
|
|
|
ConnectedAgentListAck(); // 클라이언트 갱신
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool CRylAgentServerDispatch::ItemQtyControlAck(PktBase* lpPktBase)
|
|
{
|
|
bool bIsReleased = true;
|
|
|
|
CBuffer* lpBuffer = CREATE_BUFFER(GetBufferFactory(), sizeof(PktAdminMgr::PktItemQtyControl));
|
|
|
|
if (NULL == lpBuffer)
|
|
{
|
|
ERRLOG0(g_Log, "버퍼 생성 실패");
|
|
return false;
|
|
}
|
|
|
|
PktAdminMgr::PktItemQtyControl* lpPktItemQtyControl =
|
|
reinterpret_cast<PktAdminMgr::PktItemQtyControl*>(lpBuffer->begin());
|
|
|
|
*lpPktItemQtyControl = *reinterpret_cast<PktAdminMgr::PktItemQtyControl*>(lpPktBase);
|
|
|
|
if (false == PacketWrap::WrapHeader(lpBuffer,
|
|
sizeof(PktAdminMgr::PktItemQtyControl), PktAdminMgr::PktCMD::PktItemQtyControl, 0, 0))
|
|
{
|
|
ERRLOG0(g_Log, "수동으로 패킷을 릴리스합니다.");
|
|
bIsReleased = false;
|
|
}
|
|
else
|
|
{
|
|
if (false == CClientDispatchTable::GetInstance().SendAll(lpBuffer))
|
|
{
|
|
ERRLOG0(g_Log, "수동으로 패킷을 릴리스합니다.");
|
|
bIsReleased = false;
|
|
}
|
|
}
|
|
|
|
if (false == bIsReleased)
|
|
{
|
|
SAFE_RELEASE_BUFFER(lpBuffer);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool CRylAgentServerDispatch::GuildPositionAck(PktBase* lpPktBase)
|
|
{
|
|
bool bIsReleased = true;
|
|
|
|
PktGuildPosition* lpPktGuildPosition =
|
|
reinterpret_cast<PktGuildPosition*>(lpPktBase);
|
|
|
|
CBuffer* lpBuffer = CREATE_BUFFER(GetBufferFactory(), sizeof(PktAdminMgr::PktGuildMemberEdit));
|
|
|
|
if (NULL == lpBuffer)
|
|
{
|
|
ERRLOG0(g_Log, "버퍼 생성 실패");
|
|
return false;
|
|
}
|
|
|
|
PktAdminMgr::PktGuildMemberEdit* lpPktGuildMemberEdit =
|
|
reinterpret_cast<PktAdminMgr::PktGuildMemberEdit*>(lpBuffer->begin());
|
|
|
|
lpPktGuildMemberEdit->m_dwGID = lpPktGuildPosition->m_dwGID;
|
|
lpPktGuildMemberEdit->m_dwCID = lpPktGuildPosition->m_dwCID;
|
|
lpPktGuildMemberEdit->m_cPosition = lpPktGuildPosition->m_cPosition;
|
|
lpPktGuildMemberEdit->m_cType = lpPktGuildPosition->m_cType;
|
|
|
|
if (false == PacketWrap::WrapHeader(lpBuffer, sizeof(PktAdminMgr::PktGuildMemberEdit),
|
|
PktAdminMgr::PktCMD::PktGuildMemberEdit, 0, 0))
|
|
{
|
|
ERRLOG0(g_Log, "수동으로 패킷을 릴리스합니다.");
|
|
bIsReleased = false;
|
|
}
|
|
else
|
|
{
|
|
if (false == CClientDispatchTable::GetInstance().SendAll(lpBuffer))
|
|
{
|
|
ERRLOG0(g_Log, "수동으로 패킷을 릴리스합니다.");
|
|
bIsReleased = false;
|
|
}
|
|
}
|
|
|
|
if (false == bIsReleased)
|
|
{
|
|
SAFE_RELEASE_BUFFER(lpBuffer);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
// 중계서버와 접속, 끊김이 일어날때 클라이언트로 정보 보내기
|
|
bool CRylAgentServerDispatch::ConnectedAgentListAck()
|
|
{
|
|
bool bIsReleased = true;
|
|
|
|
CBuffer* lpBuffer = CREATE_BUFFER(GetBufferFactory(), sizeof(PktAdminMgr::PktConnectAllServerz));
|
|
|
|
if (NULL == lpBuffer)
|
|
{
|
|
ERRLOG0(g_Log, "버퍼 생성 실패");
|
|
return false;
|
|
}
|
|
|
|
PktAdminMgr::PktConnectAllServerz* lpConnectAllServerz = new PktAdminMgr::PktConnectAllServerz;
|
|
ZeroMemory(lpConnectAllServerz->m_nConnectedServerIndex, sizeof(lpConnectAllServerz->m_nConnectedServerIndex));
|
|
|
|
int nArrayIndex = 0;
|
|
for(unsigned int nIndex = 0; nIndex < CAgentServerTable::MAX_AGENT_SERVER; ++nIndex)
|
|
{
|
|
if(NULL != CAgentServerTable::GetInstance().GetDispatch(nIndex)) // 중계서버 연결 체크
|
|
{
|
|
// 배열 앞부분부터 차례대로 '연결된 서버 인덱스 + 1' 을 대입
|
|
lpConnectAllServerz->m_nConnectedServerIndex[nArrayIndex] = nIndex + 1;
|
|
++nArrayIndex;
|
|
}
|
|
}
|
|
|
|
*reinterpret_cast<PktAdminMgr::PktConnectAllServerz*>(lpBuffer->wr_ptr()) = *lpConnectAllServerz;
|
|
|
|
if (false == PacketWrap::WrapHeader(lpBuffer,
|
|
sizeof(PktAdminMgr::PktConnectAllServerz), PktAdminMgr::PktCMD::PktRefreshConnectedList, 0, 0))
|
|
{
|
|
ERRLOG0(g_Log, "수동으로 패킷을 릴리스합니다.");
|
|
bIsReleased = false;
|
|
}
|
|
else
|
|
{
|
|
if (NULL != lpConnectAllServerz)
|
|
{
|
|
delete lpConnectAllServerz;
|
|
lpConnectAllServerz = NULL;
|
|
}
|
|
|
|
if (false == CClientDispatchTable::GetInstance().SendAll(lpBuffer))
|
|
{
|
|
ERRLOG0(g_Log, "수동으로 패킷을 릴리스합니다.");
|
|
bIsReleased = false;
|
|
}
|
|
}
|
|
|
|
if (false == bIsReleased)
|
|
{
|
|
SAFE_RELEASE_BUFFER(lpBuffer);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
} |