void SFMulitiCasualGameDispatcher::Dispatch(BasePacket* pPacket) { ISession* pSession = pPacket->GetSessionDesc().pSession; switch (pPacket->GetPacketType()) { case SFPACKET_CONNECT: { #ifdef _DEBUG pSession->SetLoginState(SESSION_STATE_AUTENTICATE); pSession->m_channelNum = 1; SFPacket* pkt = PacketPoolSingleton::instance()->Alloc(); pkt->SetPacketType(SFPACKET_DATA); pkt->SetSerial(pPacket->GetSerial()); pkt->SetPacketID(12345); pkt->SetSessionDesc(pPacket->GetSessionDesc()); DistributePacket(pkt); #else pSession->SetLoginState(SESSION_STATE_CONNECT); #endif ReleasePacket(pPacket); } return; case SFPACKET_DISCONNECT: { if (pSession->GetLoginState() == SESSION_STATE_AUTENTICATE) { DistributePacket(pPacket); } return; } case SFPACKET_DATA: if (pSession->GetLoginState() == SESSION_STATE_AUTENTICATE) DistributePacket(pPacket); else if (pSession->GetLoginState() == SESSION_STATE_CONNECT) { if (true == OnAuthenticate(pPacket)) { pSession->m_channelNum = 1; pSession->SetLoginState(SESSION_STATE_AUTENTICATE); } else { pSession->SetLoginState(SESSION_STATE_NULL); SFEngine::GetInstance()->Disconnect(pPacket->GetSerial()); } ReleasePacket(pPacket); } else { pSession->SetLoginState(SESSION_STATE_NULL); SFEngine::GetInstance()->Disconnect(pPacket->GetSerial()); ReleasePacket(pPacket); } } }
long CNetMgr::OnNetMsg(WPARAM wParam, LPARAM lParam, const GUID *pGuid) {_STT(); CNetCom *pNc = (CNetCom*)lParam; if ( pNc == NULL ) return E_FAIL; // Authenticate the connection if ( !OnAuthenticate( pNc ) ) return E_FAIL; // Hook NetCmd messages if ( pGuid != NULL && IsEqualGUID( NetCmd::IID, *pGuid ) ) { // Save network error if any if ( pNc->GetNetError() ) SetNetError( pNc->GetNetError() ); // Cleanup if node is disconnecting // +++ This doesn't work because it causes the calling // class to delete itself. For now, Cleanup() must be // called from the outside. This is just to remind me // to come up with something. // if ( wParam == NetCmd::efDisconnect ) Cleanup(); } // end if // Check for update request if ( ( wParam & CNetMsg::fWantUpdate ) != 0 ) { AddUpdateNotification( pNc->Tx()->GetConnectionId(), pGuid, wParam & CNetMsg::fMask ); } // end if // Check for remove notification command if ( ( wParam & CNetMsg::fCancelUpdate ) != 0 ) { RemoveUpdateNotification( pNc->Tx()->GetConnectionId(), pGuid, wParam & CNetMsg::fMask ); // Don't process this message return S_OK; } // end if // Turn off internal flags wParam &= CNetMsg::fCmdMask; pNc->SMsg().dwFunction &= CNetMsg::fCmdMask; // Pass on the message return MMessage( wParam, lParam, pGuid ); }