Example #1
1
void CPlayerManager::_PlayerEventNotify( const unsigned long &ulnID,
			const unsigned long &ulnEventType )
{
	CCriticalSection::Owner locker( m_csUsedClientList );

	switch( ulnEventType )
	{
	case enumClientConnectCreate:

		m_usedClientNode.push_back( ulnID );

		break;

	case enumClientConnectClose:

		PLAYER_MAP::iterator it;

		if ( m_thePlayers.end() != ( it = m_thePlayers.find( ulnID ) ) )
		{
			IPlayer *pPlayer = m_thePlayers[ulnID];

			ASSERT( pPlayer );

			pPlayer->Destroy( NULL );
		}

		m_usedClientNode.remove( ulnID );
		
		break;
	}
}
Example #2
0
void CPlayerManager::CleanNetwork()
{
	if ( m_pDBRoleClient )
	{
		m_pDBRoleClient->Shutdown();

		m_pDBRoleClient->Cleanup();

		SAFE_RELEASE( m_pDBRoleClient );
	}

	if ( m_pPlayerServer )
	{
/*		CCriticalSection::Owner locker( m_csUsedClientList );
		
		LIST::iterator it;
		for ( it = m_usedClientNode.begin(); it != m_usedClientNode.end(); it ++ )
		{
			size_t index = *it;

			m_pPlayerServer->ShutdownClient( index );
		}
*/		
		m_pPlayerServer->CloseService();

		m_pPlayerServer->Cleanup();
		
		SAFE_RELEASE( m_pPlayerServer );
	}

	CCriticalSection::Owner lock( m_csSystemAction );

	/*
     * Repeat until stack is empty
	 */
	while ( !m_freeClientNode.empty() )
	{
		m_freeClientNode.pop();
	}

	CCriticalSection::Owner locker( m_csUsedClientList );

	m_usedClientNode.erase( m_usedClientNode.begin(), m_usedClientNode.end() );

	PLAYER_MAP::iterator it;
	for ( it = m_thePlayers.begin(); it != m_thePlayers.end(); it ++ )
	{
		IPlayer *pPlayer = ( IPlayer * )( ( *it ).second );

		ASSERT( pPlayer );

		pPlayer->Destroy( NULL );

		SAFE_DELETE( pPlayer );
	}

	m_thePlayers.erase( m_thePlayers.begin(), m_thePlayers.end() );
}