Files
Sun1602/Tools/SunUpdateManager/SunUpdateServer/ServerSession.cpp
T
2022-10-26 12:25:11 +08:00

85 lines
1.7 KiB
C++

#include "StdAfx.h"
#include ".\serversession.h"
#include "ServerSessionManager.h"
ServerSession::ServerSession(void)
{
m_dwServerKey = 0;
}
ServerSession::~ServerSession(void)
{
}
BOOL ServerSession::SendPacket( BYTE* pMsg, WORD wSize )
{
return Send( (BYTE*)pMsg, wSize );
}
VOID ServerSession::OnConnect( BOOL bSuccess, DWORD dwNetworkIndex )
{
if( bSuccess )
{
SetConnected( TRUE );
SetIsConnector( TRUE );
m_dwSessionIndex = dwNetworkIndex;
}
}
VOID ServerSession::OnDisconnect()
{
ServerSessionManager::Instance()->DelSession( GetSessionIndex() );
SetConnected( FALSE );
SetIsConnector( FALSE );
}
VOID ServerSession::OnAccept( DWORD dwNetworkIndex )
{
SetConnected( TRUE );
SetIsConnector( FALSE );
m_dwSessionIndex = dwNetworkIndex;
DISPMSG( "Server Accept : index = %d, type = %s\n", GetSessionIndex(), GetServerTypeStr().c_str() );
}
std::string ServerSession::GetServerTypeStr()
{
std::string strMsg;
switch( GetServerType() )
{
case UPDATE_AGENT:
strMsg = "UpdateAgent";
break;
case UPDATE_MANAGER:
strMsg = "UpdateManager";
break;
case UPDATE_SERVER:
strMsg = "UpdateServer";
break;
case UPDATE_MASTER:
strMsg = "MasterServer";
break;
case UPDATE_TEMP:
strMsg = "TempServer";
break;
default:
strMsg = "UnknownServer";
break;
}
return strMsg;
}
VOID ServerSession::Clone( ServerSession* pServerSession )
{
if( !pServerSession ) return;
m_dwSessionIndex = pServerSession->m_dwSessionIndex;
m_dwServerKey = pServerSession->m_dwServerKey;
m_bIsConnector = pServerSession->m_bIsConnector;
m_strConnectIP = pServerSession->m_strConnectIP;
m_wConnectPort = pServerSession->m_wConnectPort;
m_bIsConnected = pServerSession->m_bIsConnected;
}