⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serversessionfactory.cpp

📁 奇迹世界data 服务器代码,研究游戏的朋友有帮助
💻 CPP
字号:
#include "stdafx.h"
#include ".\serversessionfactory.h"
#include <Macro.h>

#include "GameServerSession.h"
#include "TempServerSession.h"
#include "MasterServerSession.h"
#include "AgentServerSession.h"
#include "WorldServerSession.h"
#include "GuildServerSession.h"

ServerSessionFactory::ServerSessionFactory()
	:	m_pGameServerPool ( NULL ),
		m_pTempServerPool ( NULL ),
		m_pMasterServerPool ( NULL ),
		m_pAgentServerPool ( NULL ),
		m_pWorldServerPool ( NULL ),
		m_pGuildServerPool ( NULL )
{
}

ServerSessionFactory::~ServerSessionFactory()
{
	Release();
}

VOID ServerSessionFactory::Init()
{
	ASSERT( NULL == m_pGameServerPool );
	ASSERT( NULL == m_pTempServerPool );
	ASSERT( NULL == m_pMasterServerPool );
	ASSERT( NULL == m_pAgentServerPool );
	ASSERT( NULL == m_pWorldServerPool );
	ASSERT( NULL == m_pGuildServerPool );

	m_pGameServerPool	= new CMemoryPoolFactory<GameServerSession>;
	m_pTempServerPool	= new CMemoryPoolFactory<TempServerSession>;
	m_pMasterServerPool	= new CMemoryPoolFactory<MasterServerSession>;
	m_pAgentServerPool	= new CMemoryPoolFactory<AgentServerSession>;
	m_pWorldServerPool	= new CMemoryPoolFactory<WorldServerSession>;
	m_pGuildServerPool	= new CMemoryPoolFactory<GuildServerSession>;

	m_pMasterServerPool->Initialize( 10, 2 );
	m_pAgentServerPool->Initialize( 10, 2 );
	m_pWorldServerPool->Initialize( 10, 10 );
	m_pGuildServerPool->Initialize( 10, 10 );
	/// 咯矾俺啊 瞪 荐 乐栏骨肺 俺荐 炼例捞 鞘夸!!!
	m_pGameServerPool->Initialize( 100, 10 );
	m_pTempServerPool->Initialize( 100, 10 );
	
	
}

VOID ServerSessionFactory::Release()
{
	SAFE_DELETE( m_pGameServerPool );
	SAFE_DELETE( m_pTempServerPool );
	SAFE_DELETE( m_pMasterServerPool );
	SAFE_DELETE( m_pAgentServerPool );
	SAFE_DELETE( m_pWorldServerPool );
	SAFE_DELETE( m_pGuildServerPool );
}

ServerSession * ServerSessionFactory::AllocServerSession( eSERVER_TYPE eServerType )
{
	ServerSession * pSession = NULL;
	switch( eServerType )
	{
	case FIELD_SERVER:
	case BATTLE_SERVER:
		{
			pSession = m_pGameServerPool->Alloc();
			pSession->SetServerType( eServerType );
			return pSession;
		}
		break;
	case TEMP_SERVER:
		{
			pSession = m_pTempServerPool->Alloc();
			return pSession;
		}
		break;
	case MASTER_SERVER:
		{
			pSession = m_pMasterServerPool->Alloc();
			return pSession;
		}break;
	case AGENT_SERVER:
		{
			pSession = m_pAgentServerPool->Alloc();
			return pSession;
		}break;
	case WORLD_SERVER:
		{
			pSession = m_pWorldServerPool->Alloc();
			return pSession;
		}break;
	case GUILD_SERVER:
		{
			pSession = m_pGuildServerPool->Alloc();
			return pSession;
		}break;
	}

	SUNLOG(eFULL_LOG,  "[ServerSessionFactory::AllocServerSession] 肋给等 辑滚 鸥涝捞促." );

	return NULL;
}

VOID ServerSessionFactory::FreeServerSession( ServerSession * pServerSession )
{
	switch( pServerSession->GetServerType() )
	{
	case FIELD_SERVER:
	case BATTLE_SERVER:
		return m_pGameServerPool->Free( (GameServerSession *)pServerSession );
	case TEMP_SERVER:
		return m_pTempServerPool->Free( (TempServerSession *)pServerSession );
	case MASTER_SERVER:
		return m_pMasterServerPool->Free( (MasterServerSession *)pServerSession );
	case AGENT_SERVER:
		return m_pAgentServerPool->Free( (AgentServerSession *)pServerSession );
	case WORLD_SERVER:
		return m_pWorldServerPool->Free( (WorldServerSession *)pServerSession );
	case GUILD_SERVER:
		return m_pGuildServerPool->Free( (GuildServerSession *)pServerSession );
	default:
		{
			SUNLOG(eFULL_LOG,  "[ServerSessionFactory::FreeServerSession] 肋给等 鸥涝狼 辑滚技记阑 Free且 荐 绝促" );
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -