#include "StdAfx.h" #include "UpdateServerSession.h" #include "SunUpdateAgent.h" #include "PacketHandler.h" #include UpdateServerSession::UpdateServerSession(void) { m_wConnectPort = 0; m_bConnected = FALSE; m_bConnector = FALSE; m_bLogin = FALSE; m_dwSessionIndex = 0; } UpdateServerSession::~UpdateServerSession(void) { } VOID UpdateServerSession::SetAddr( const TCHAR* pszIP, WORD wPort ) { if( !pszIP ) return; m_strConnectIP = pszIP; m_wConnectPort = wPort; } BOOL UpdateServerSession::TryToConnect() { if( IsConnected() ) return TRUE; if( m_strConnectIP.empty() ) return FALSE; DWORD dwIndex = SunUpdateAgent::Instance()->ConnectToServer( this, m_strConnectIP.c_str(), m_wConnectPort ); if( dwIndex != 0 ) { m_dwSessionIndex = dwIndex; return TRUE; } return FALSE; } VOID UpdateServerSession::OnRecv( BYTE *pMsg, WORD wSize ) { PacketHandler::Instance()->ParserPacket_SA( this, (MSG_BASE*)pMsg, wSize ); } VOID UpdateServerSession::OnConnect( BOOL bSuccess, DWORD dwNetworkIndex ) { if( bSuccess ) { SetConnected( TRUE ); SetIsConnector( TRUE ); MSGOUT( "[OnConnect] ¾÷µ¥ÀÌÆ® ¼­¹ö Á¢¼Ó ¼º°ø" ); SendServerType(); } else { TryToConnect(); } } VOID UpdateServerSession::OnDisconnect() { SetConnected( FALSE ); MSGOUT( "[OnDisconnect] ¼­¹ö ¿¬°á ÇØÁ¦" ); if( IsConnector() ) { TryToConnect(); } } BOOL UpdateServerSession::SendPacket( MSG_BASE * pMsg, WORD wSize ) { return Send( (BYTE*)pMsg, wSize ); } VOID UpdateServerSession::SendServerType() { MSG_SERVER_TYPE msg; msg.m_byCategory = SA_SERVER; msg.m_byProtocol = SA_SERVER_TYPE_SYN; msg.m_byServerType = UPDATE_AGENT; SendPacket( &msg, sizeof(msg) ); }