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

📄 gameserverinfomanager.cpp

📁 天之炼狱1服务器端源文件游戏服务端不完整
💻 CPP
字号:
//////////////////////////////////////////////////////////////////////////////// Filename    : GameServerInfoManager.cpp// Written By  : Reiot// Description ://////////////////////////////////////////////////////////////////////////////#include "GameServerInfoManager.h"#include "database/DB.h"#include "Properties.h"//////////////////////////////////////////////////////////////////////////////// class GameServerInfoManager member methods//////////////////////////////////////////////////////////////////////////////GameServerInfoManager::GameServerInfoManager () 	throw (){}GameServerInfoManager::~GameServerInfoManager () 	throw (){	// hashmap 救狼 阿 pair 狼 second, 溜 GameServerInfo 按眉父阑 昏力窍绊	// pair 磊眉绰 弊措肺 敌促. (GameServerInfo啊 赛俊 积己登绢 乐促绰 巴俊	// 蜡狼窍扼. 溜 鞘混昏力甫 秦具 茄促. 窍变, GSIM捞 destruct 等促绰 巴篮	// 肺弊牢 辑滚啊 妓促款等促绰 巴阑 狼固窍聪瘪.. - -;)	for (int i=0; i < m_MaxServerGroupID; i++) 	{		HashMapGameServerInfoItor itr = m_pGameServerInfos[i].begin();		for (; itr != m_pGameServerInfos[i].end(); itr++) 		{			SAFE_DELETE(itr->second);		}		// 捞力 秦浆甘救俊 乐绰 葛电 pair 甸阑 昏力茄促.		m_pGameServerInfos[i].clear();	}	if (m_pGameServerInfos != NULL) 	{		SAFE_DELETE_ARRAY(m_pGameServerInfos);	}	}void GameServerInfoManager::init ()	throw (Error){	__BEGIN_TRY	// just load data from GameServerInfo table	load();	// just print to cout	cout << toString() << endl;	__END_CATCH}void GameServerInfoManager::load ()	throw (Error){	__BEGIN_TRY	Statement* pStmt = NULL;	WorldID_t WorldID = g_pConfig->getPropertyInt( "WorldID" );	// 刚历 MAX SERVER GROUP ID甫 佬绢甸咯具 茄促.	BEGIN_DB	{		pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();		Result* pResult = pStmt->executeQuery( "SELECT MAX(GroupID) FROM GameServerInfo WHERE WorldID = %d", WorldID );		if (pResult->getRowCount() == 0)		{			throw Error("GameServerInfo TABLE does not exist!");		}		pResult->next();		m_MaxServerGroupID = pResult->getInt(1) + 1;		SAFE_DELETE(pStmt);	}	END_DB(pStmt)	m_pGameServerInfos = new HashMapGameServerInfo[m_MaxServerGroupID];	cout << "MAX SERVER GROUP = " << m_MaxServerGroupID << endl;	BEGIN_DB	{		pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();		Result* pResult = pStmt->executeQuery(			"SELECT ServerID, Nickname , IP , TCPPort , UDPPort, GroupID, Stat, WorldID FROM GameServerInfo"		);		while (pResult->next()) 		{			int i = 0;			if ( pResult->getInt(8) == WorldID )			{				GameServerInfo* pGameServerInfo = new GameServerInfo();				pGameServerInfo->setServerID(pResult->getInt(++i));				pGameServerInfo->setNickname(pResult->getString(++i));				pGameServerInfo->setIP(pResult->getString(++i));				pGameServerInfo->setTCPPort(pResult->getInt(++i));				pGameServerInfo->setUDPPort(pResult->getInt(++i));				pGameServerInfo->setWorldID(WorldID);				ServerGroupID_t ServerGroupID = pResult->getInt(++i);				pGameServerInfo->setGroupID(ServerGroupID);				pGameServerInfo->setServerStat((ServerStatus)pResult->getInt(++i));				addGameServerInfo(pGameServerInfo, ServerGroupID);			}		}		SAFE_DELETE(pStmt);	}	END_DB(pStmt)	__END_CATCH}void GameServerInfoManager::addGameServerInfo(GameServerInfo * pGameServerInfo, const ServerGroupID_t ServerGroupID) 	throw (DuplicatedException){	__BEGIN_TRY	if (ServerGroupID >= m_MaxServerGroupID)	{		throw DuplicatedException("ServerGroupID over Bounce");	}	HashMapGameServerInfoItor itr = m_pGameServerInfos[ServerGroupID].find(pGameServerInfo->getServerID());		if (itr != m_pGameServerInfos[ServerGroupID].end())	{		throw DuplicatedException("duplicated game-server ServerID");	}	m_pGameServerInfos[ServerGroupID][ pGameServerInfo->getServerID() ] = pGameServerInfo;	__END_CATCH}	void GameServerInfoManager::deleteGameServerInfo (const ServerID_t ServerID, const ServerGroupID_t ServerGroupID) 	throw (NoSuchElementException){	__BEGIN_TRY	if (ServerGroupID >= m_MaxServerGroupID)	{		throw DuplicatedException("ServerGroupID over Bounce");	}	HashMapGameServerInfoItor itr = m_pGameServerInfos[ServerGroupID].find(ServerID);		if (itr != m_pGameServerInfos[ServerGroupID].end()) 	{		// GameServerInfo 甫 昏力茄促.		delete itr->second;		// pair甫 昏力茄促.		m_pGameServerInfos[ServerGroupID].erase(itr);	} 	else 	{		// 弊繁 霸烙辑滚牢器 按眉甫 茫阑 荐 绝阑 锭		throw NoSuchElementException();	}	__END_CATCH}	GameServerInfo * GameServerInfoManager::getGameServerInfo (const ServerID_t ServerID, const ServerGroupID_t ServerGroupID) const	throw (NoSuchElementException){	__BEGIN_TRY			GameServerInfo * pGameServerInfo = NULL;	if( ServerGroupID >= m_MaxServerGroupID )	{		// 弊繁 霸烙辑滚牢器 按眉甫 茫阑 荐 绝菌阑 锭		throw NoSuchElementException();	}	HashMapGameServerInfoItor itr = m_pGameServerInfos[ServerGroupID].find(ServerID);		if (itr != m_pGameServerInfos[ServerGroupID].end()) 	{		pGameServerInfo = itr->second;	} 	else 	{		// 弊繁 霸烙辑滚牢器 按眉甫 茫阑 荐 绝菌阑 锭		throw NoSuchElementException();	}	return pGameServerInfo;	__END_CATCH}string GameServerInfoManager::toString () const	throw (){	__BEGIN_TRY	StringStream msg;	msg << "GameServerInfoManager(\n";	for (int i = 0; i < m_MaxServerGroupID; i++) 	{		if (m_pGameServerInfos[i].empty()) 		{			msg << "EMPTY";		} 		else 		{			HashMapGameServerInfoItor itr = m_pGameServerInfos[i].begin();			for (; itr != m_pGameServerInfos[i].end(); itr++)			{				msg << itr->second->toString() << '\n';			}		}		msg << ")";	}	return msg.toString();	__END_CATCH}// global variable definitionGameServerInfoManager * g_pGameServerInfoManager = NULL;

⌨️ 快捷键说明

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