Files
2022-10-26 12:25:11 +08:00

126 lines
3.3 KiB
C++

#include "StdAfx.h"
#include ".\tempserversession.h"
#include "ServerSessionFactory.h"
#include "ServerSessionManager.h"
#include <PacketStruct_SA.h>
#include <PacketStruct_SMA.h>
#ifdef _NA_006543_20130318_HEARTBEAT
#include "AgentServerSession.h"
#endif
TempServerSession::TempServerSession(void)
{
}
TempServerSession::~TempServerSession(void)
{
}
VOID TempServerSession::OnRecv( BYTE * pMsg, WORD wSize )
{
// 풀로부터 NetworkObject를 받아 온다.
// Temp일때 2개가 올수 있다..
// Agent 서버는 Auth를 보낸다.
ServerSession* pNewSession = NULL;
MSG_BASE* pBase = (MSG_BASE *)pMsg;
eUPDATE_SERVER_TYPE ServerType;
if( pBase->m_byCategory == SA_SERVER && pBase->m_byProtocol == SA_SERVER_TYPE_SYN )
{
MSG_SERVER_TYPE * pRecvMsg = (MSG_SERVER_TYPE *)pMsg;
if( pRecvMsg->m_byServerType == UPDATE_AGENT )
{
pNewSession = ServerSessionFactory::Instance()->AllocServerSession( UPDATE_AGENT );
ServerType = UPDATE_AGENT;
}
else
{
MSGOUT( "[TempServerSession::OnRecv] Agent로 부터 잘못된 값이 전달되었습니다.\n" );
Disconnect();
return;
}
}
else if( pBase->m_byCategory == SA_CHECK && pBase->m_byProtocol == SA_CHECK_GAMEPROCESS_NTF )
{
// 이 패킷은 Agent가 시작되는 대로, 보내므로.. 여기 올 수 있다. 따라서 이 패킷이 올때는
// 무시한다.
return;
}
else if( pBase->m_byCategory == MO_OPERATION && pBase->m_byProtocol == MO_RTTG_CERTIFY_REQ )
{
MSG_MO_RTTG_CERTIFY_REQ* pRecvMsg = (MSG_MO_RTTG_CERTIFY_REQ *)pMsg;
if( pRecvMsg->dwType == SERVERTYPE_MASTER )
{
pNewSession = ServerSessionFactory::Instance()->AllocServerSession( UPDATE_MASTER );
ServerType = UPDATE_MASTER;
}
else
{
MSGOUT( "[TempServerSession::OnRecv] 마스터로 부터 잘못된 값이 전달되었습니다." );
Disconnect();
return;
}
}
else if( pBase->m_byCategory == MO_OPERATION && pBase->m_byProtocol == MO_RTTG_HEARTBEAT )
{
//Heart Beat다. 그냥 무시하자.
return;
}
else
{
// Master Server HeartBear 테스트 코드..
struct MSG_BASE_EX
{
DWORD m_dwKey;
BYTE m_byCategory; // 카테고리
union
{
BYTE m_byProtocol; // 카테고리 아래의 타입
BYTE m_byEncryptedBuffer[1]; // 암호화된 버퍼
};
};
MSG_BASE_EX* pMsgBase = (MSG_BASE_EX*)pMsg;
if( pMsgBase->m_byCategory == MO_OPERATION && pMsgBase->m_byProtocol == MO_RTTG_HEARTBEAT )
{
//HeartBeat다.. 그냥 리턴하자.
return;
}
MSGOUT( "[TempServerSession::OnRecv] 오지 말아야 할 패킷이 왔습니다.[C:%u, P:%u], IP = %s", pBase->m_byCategory, pBase->m_byProtocol, GetIP() );
Disconnect();
return;
}
if( NULL == pNewSession )
{
MSGOUT( "[TempServerSession::OnRecv] 잘못된 서버가 접속 했습니다." );
Disconnect();
return;
}
// 새로운 NetworkObject으로 교체
Redirect( pNewSession );
pNewSession->Clone( this );
MSGOUT( "[Redirect] ServerName = %s, ServerType = %d", GetUpdateServerType( ServerType ), ServerType );
//Temp 삭제
ServerSessionManager::Instance()->DelSession( GetSessionIndex() );
ServerSessionFactory::Instance()->FreeServerSession( this );
//새로운 서버세션 추가.
ServerSessionManager::Instance()->AddSession( pNewSession );
if( ServerType == UPDATE_AGENT )
{
MSG_SA_SERVER_TYPE_ACK ack;
pNewSession->SendPacket( (BYTE*)&ack, sizeof(ack));
#ifdef _NA_006543_20130318_HEARTBEAT
static_cast<AgentServerSession*>(pNewSession)->SetServerStatus(SERVER_STATUS_ONLINE);
#endif
}
}