bool GameServer::DestroyClientConnection(SOCKET sock, DWORD dwErrorCode){ if( !sock ) return false; bool bRet = true; m_lockConnections.Lock(); // Lock int nIndex = m_arrAcceptedSocks.FindValue((void*)sock); if( nIndex != -1 ){ ClientConnection* pConn = (ClientConnection*)m_arrAcceptedSocks.GetData(nIndex); if( !pConn ) { m_arrAcceptedSocks.Delete(nIndex); // Remove socket from list. m_lockConnections.Unlock(); // Unlock return true; } bool bTableConn = pConn->IsTableConnection(); // Set disconnected state. Session* pSess = pConn->GetSession(true); pConn->SetConnected(false); OnDisconnected(pConn, dwErrorCode); if( pSess ){ // Make session connectionless. if( bTableConn ) pSess->SetTableConnection(pConn->GetTableId(), pConn->GetTournamentId(), NULL, true); else pSess->SetConnection(NULL, true); // Release session pointer. SafePointer::Release(pSess); } // Release pointer. SafePointer::Release(pConn); // Destroy session. if( !bTableConn ) Session::DestroySession(pSess); // Remove conection info. m_arrAcceptedSocks.Delete(nIndex); } else bRet = false; m_lockConnections.Unlock(); // Unlock return bRet; }
void GameServer::OnAcquireTableAccess(AcquireTableAccessPacket* p, void* pParam){ if( p->m_nSessionId != 0 || p->m_nSessionIdAcquire == 0 || p->m_nTableId <= 0 || p->m_nTournamentId < 0 ) return; ClientConnection* pConn = (ClientConnection*)pParam; Session* pSess = Session::GetSessionById(p->m_nSessionIdAcquire, true); bool bSuccess = false; if( pConn->IsTableConnection() ) return; if( pSess && pSess->IsActive() ){ int nUserId = pSess->GetUserId(); pSess->SetTableConnection(p->m_nTableId, p->m_nTournamentId, pConn, true); pConn->SetTableConnection(p->m_nTableId, p->m_nTournamentId); if( nUserId > 0 ) pConn->SetAuthorized(true); p->m_bAvatarIsBlocked = pSess->IsAvatarBlocked(); p->m_bChatIsBlocked = pSess->IsChatBlocked(); p->m_nUserId = nUserId; bSuccess = true; SafePointer::Release(pSess); } // Send reply. if( bSuccess ){ //pConn->SetAuthorized( pConn->SetSession(pSess); p->m_nErrorCode = ES_ERROR_SUCCESS; } else{ p->m_nUserId = 0; p->m_nErrorCode = ES_ERROR_UNKNOWN; } SendPacket(pConn, p, true); }