149 lines
3.2 KiB
C++
149 lines
3.2 KiB
C++
#include "StdAfx.h"
|
|
#include ".\agentserversession.h"
|
|
#include "PacketHandler.h"
|
|
#include "ServerSessionManager.h"
|
|
|
|
#ifdef _NA_006543_20130318_HEARTBEAT
|
|
|
|
#include "PacketStruct_SA.h"
|
|
#include "AgentServerSession.h"
|
|
#include "WorldManager.h"
|
|
#include "UnitServer.h"
|
|
#include "Channel.h"
|
|
|
|
#define HEARTBEAT_CYCLE 10000
|
|
#define HEARTBEAT_TIMEOUT 3000
|
|
|
|
#endif
|
|
|
|
AgentServerSession::AgentServerSession(void)
|
|
#ifdef _NA_006543_20130318_HEARTBEAT
|
|
: m_byServerStatus(0)
|
|
, m_isRecvHeartbeat(true)
|
|
, m_sendTick(1)
|
|
, m_recvTick(1)
|
|
#endif
|
|
{
|
|
//m_dwAgentKey = 0;
|
|
}
|
|
|
|
AgentServerSession::~AgentServerSession(void)
|
|
{
|
|
}
|
|
|
|
|
|
VOID AgentServerSession::OnRecv( BYTE *pMsg, WORD wSize )
|
|
{
|
|
if( !pMsg ) return;
|
|
|
|
PacketHandler::Instance()->ParserPacket_SA( this, (MSG_BASE*)pMsg, wSize );
|
|
}
|
|
|
|
VOID AgentServerSession::OnConnect( BOOL bSuccess, DWORD dwNetworkIndex )
|
|
{
|
|
ServerSession::OnConnect( bSuccess, dwNetworkIndex );
|
|
if( bSuccess )
|
|
{
|
|
DISPMSG( "AgentServer Connected\n" );
|
|
}
|
|
}
|
|
|
|
VOID AgentServerSession::OnAccept( DWORD dwNetworkIndex )
|
|
{
|
|
ServerSession::OnAccept( dwNetworkIndex );
|
|
DISPMSG( "AgentServer Connectd\n" );
|
|
}
|
|
|
|
VOID AgentServerSession::OnDisconnect()
|
|
{
|
|
ServerSession::OnDisconnect();
|
|
DISPMSG( "AgentServer Disconnect\n" );
|
|
}
|
|
|
|
#ifdef _NA_006543_20130318_HEARTBEAT
|
|
VOID AgentServerSession::SendHeartBeat()
|
|
{
|
|
MSG_SA_CHECK_HEARTBEAT msg;
|
|
|
|
m_isRecvHeartbeat=false;
|
|
SendPacket((BYTE*)&msg, sizeof(msg));
|
|
//DISPMSG("Send HeartBeat to agentkey = %d\n", GetServerKey());
|
|
}
|
|
|
|
VOID AgentServerSession::update()
|
|
{
|
|
DWORD curTick = GetTickCount();
|
|
|
|
_update_Send_Heartbeat(curTick);
|
|
_update_Recv_Heartbeat(curTick);
|
|
}
|
|
|
|
VOID AgentServerSession::_update_Send_Heartbeat( DWORD curTick )
|
|
{
|
|
//Heartbeat 송신
|
|
if(m_sendTick == 1)
|
|
m_sendTick = GetTickCount();
|
|
|
|
if( curTick -m_sendTick > HEARTBEAT_CYCLE )
|
|
{
|
|
SendHeartBeat();
|
|
|
|
m_sendTick = curTick;
|
|
}
|
|
}
|
|
|
|
VOID AgentServerSession::_update_Recv_Heartbeat( DWORD curTick )
|
|
{
|
|
// 지정된 시간 내에 응답이 오는지 체크
|
|
if(m_recvTick == 1)
|
|
m_recvTick = GetTickCount();
|
|
|
|
if(m_isRecvHeartbeat == true)
|
|
{
|
|
m_recvTick = curTick;
|
|
return;
|
|
}
|
|
|
|
//이미 연결이 끊긴 상태
|
|
if(GetServerStatus() == SERVER_STATUS_OFFLINE)
|
|
return;
|
|
|
|
if(curTick - m_recvTick > HEARTBEAT_TIMEOUT)
|
|
{
|
|
//서버의 상태를 바꾼다
|
|
UnitServer* pUnitserver = WorldManager::Instance()->FindFirstUnitServerByAgentKey(GetServerKey());
|
|
|
|
if(pUnitserver == NULL)
|
|
{
|
|
DISPMSG("[AgentServerSession::_update_Recv_Heartbeat()]해당 agent가 서버를 가지고있지않음\n");
|
|
return ;
|
|
}
|
|
|
|
BYTE worldkey = pUnitserver->GetServerInfo().GetServerInfoEx().m_byWorld;
|
|
BYTE channelkey = 0;
|
|
Channel* pChannel=NULL;
|
|
|
|
//월드 내의 채널들을(0번부터) 돌면서 해당 agentkey를 가진 서버가 있는지 확인하고, 있으면 status를 바꾼다.
|
|
while(pChannel = WorldManager::Instance()->FindChannel(worldkey, channelkey))
|
|
{
|
|
UnitServer* unitserver = pChannel->FindFirstUnitServerByAgentKey(GetServerKey());
|
|
|
|
if(unitserver != NULL && unitserver->GetServerStatus() != SERVER_STATUS_UNKNOWN)
|
|
{
|
|
pChannel->SetServerStatus(SERVER_STATUS_UNKNOWN);
|
|
}
|
|
channelkey++;
|
|
}
|
|
//AgentServerSession의 Status도 바꾼다
|
|
SetServerStatus(SERVER_STATUS_OFFLINE);
|
|
|
|
}
|
|
}
|
|
|
|
VOID AgentServerSession::CheckHeatbeatRecv()
|
|
{
|
|
m_isRecvHeartbeat = true;
|
|
SetServerStatus(SERVER_STATUS_ONLINE);
|
|
}
|
|
#endif
|