#include "stdafx.h" #include #include "ServerSession.h" #include "ServerFrame.h" #include #include #include ServerSession::ServerSession(void) { Clear(); } ServerSession::~ServerSession(void) { } void ServerSession::Clear() { m_dwSessionIndex = 0; m_wConnectPort = 0; //< 楷搬且 PORT connected_ = false; //< 楷搬登菌绰瘤 咯何 is_connector_ = false; //< 技记狼 漂己篮 楷搬屈牢啊? manual_connect_mode_ = true; m_HeartBeatTimer.SetTimer(KEEP_ALIVE_DEFAULT_TIME); m_HeartBeatTimer.DisableCheckTime(); connecting_ = false; } void ServerSession::Init() { Clear(); } void ServerSession::Release() { Clear(); } void ServerSession::Update() { if( IsConnected() && IsConnector() ) { if( m_HeartBeatTimer.IsExpired() ) { SendHeartbeatPacket(); } } else { } } void ServerSession::OnConnect( BOOL bSuccess, DWORD index ) { NetworkObject::OnConnect( bSuccess, index ); manual_connect_mode_ = false; //< 楷搬 矫档甫 捞固 沁促(Connect()啊 龋免凳)绰 狼固捞骨肺, FALSE connecting_ = false; //< 楷搬 矫档啊 场车促绰 狼固 if( bSuccess ) { OnConnectSuccess( index ); GetFrame()->SendServerType( this ); } else { } } void ServerSession::OnConnectSuccess( DWORD index ) { GetFrame()->RemoveConnectionlessConnector( GetSessionIndex() ); SetConnected(true); //< 楷搬登菌促. SetIsConnector(true); //< 楷搬屈 SetSessionIndex( index ); GetFrame()->AddSession( GetSessionIndex(), this ); m_HeartBeatTimer.Reset(); SUNLOG( eCRITICAL_LOG, "[连接][%u] %s 连接!", index, GetServerType2String(GetServerType()) ); } // CHANGES: f110617.1L, the sub-sessions can control first_contact_msg as the needs void ServerSession::OnRedirect(DWORD session_index, MSG_SERVER_TYPE* const first_contact_msg) { __UNUSED((first_contact_msg)); // default do not control this argument. SetConnected(true); SetIsConnector(false); SetSessionIndex(session_index); assert(session_index == GetSessionIndex()); m_pFrame->AddSession(session_index, this); SUNLOG(eCRITICAL_LOG, _T("[重定向][%u] %s[%s] 重定向!"), session_index, GetServerType2String(GetServerType()), GetIP()); } void ServerSession::OnAccept( DWORD index ) { NetworkObject::OnAccept( index ); SetConnected(true); SetIsConnector(false); SetSessionIndex( index ); GetFrame()->AddSession( GetSessionIndex(), this ); if( GetServerType() != CLIENT_SERVER ) { SUNLOG( eCRITICAL_LOG, "[连接][%u] %s[%s] 新连接接入!", index, GetServerType2String(GetServerType()), GetIP() ); } } void ServerSession::OnDisconnect() { if( GetServerType() != CLIENT_SERVER ) { SUNLOG( eCRITICAL_LOG, "[连接][%u] %s[%s] 连接断开!", GetSessionIndex(), GetServerType2String(GetServerType()), IPOperation::ConvertDWORD2StrIP(GetTempIPAddress()) ); } NetworkObject::OnDisconnect(); m_HeartBeatTimer.DisableCheckTime(); SetConnected(false); GetFrame()->RemoveSession( GetSessionIndex() ); if( IsConnector() ) GetFrame()->AddConnectionlessConnector(this); } void ServerSession::SendHeartbeatPacket() { /* MSG_HEARTBEAT msg; msg.m_byCategory = 0; msg.m_byProtocol = SERVERCOMMON_HEARTBEAT; SendPacket( &msg, sizeof(msg) ); */ } void ServerSession::OnLogString( char *pszLog ) { SUNLOG( eCRITICAL_LOG, "[会话日志] 服务[%s] %s", GetServerType2String(GetServerType()), pszLog ); }