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

📄 gameworldinfomanager.cpp

📁 天之炼狱1服务器端源文件游戏服务端不完整
💻 CPP
字号:
//----------------------------------------------------------------------//// Filename    : GameWorldInfoManager.cpp// Written By  : Reiot// Description :////----------------------------------------------------------------------// include files#include "GameWorldInfoManager.h"#include "database/DatabaseManager.h"#include "database/Connection.h"#include "database/Statement.h"#include "database/Result.h"//----------------------------------------------------------------------// constructor//----------------------------------------------------------------------GameWorldInfoManager::GameWorldInfoManager () 	throw (){}	//----------------------------------------------------------------------// destructor//----------------------------------------------------------------------GameWorldInfoManager::~GameWorldInfoManager () 	throw (){	// hashmap 救狼 阿 pair 狼 second, 溜 GameWorldInfo 按眉父阑 昏力窍绊	// pair 磊眉绰 弊措肺 敌促. (GameWorldInfo啊 赛俊 积己登绢 乐促绰 巴俊	// 蜡狼窍扼. 溜 鞘混昏力甫 秦具 茄促. 窍变, GSIM捞 destruct 等促绰 巴篮	// 肺弊牢 辑滚啊 妓促款等促绰 巴阑 狼固窍聪瘪.. - -; )	for ( HashMapGameWorldInfo::iterator itr = m_GameWorldInfos.begin() ; 		  itr != m_GameWorldInfos.end() ; 		  itr ++ ) {		delete itr->second;		itr->second = NULL;	}	// 捞力 秦浆甘救俊 乐绰 葛电 pair 甸阑 昏力茄促.	m_GameWorldInfos.clear();}	//----------------------------------------------------------------------// initialize GSIM//----------------------------------------------------------------------void GameWorldInfoManager::init ()	throw ( Error ){	__BEGIN_TRY	// just load data from GameWorldInfo table	load();	// just print to cout	cout << toString() << endl;	__END_CATCH}//----------------------------------------------------------------------// load data from database//----------------------------------------------------------------------void GameWorldInfoManager::load ()	throw ( Error ){	__BEGIN_TRY	// clear GameWorldInfos	clear();	Statement * pStmt = NULL;	try {		pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();		Result * pResult = pStmt->executeQuery( "SELECT ID, Name, Stat FROM WorldInfo" );		cout << "Loading GameWorldInfoManager...." << endl;		while ( pResult->next() ) {			//cout << "TICK" << endl;			GameWorldInfo * pGameWorldInfo = new GameWorldInfo();			pGameWorldInfo->setID( pResult->getInt(1) );			pGameWorldInfo->setName( pResult->getString(2) );			pGameWorldInfo->setStatus( (WorldStatus)pResult->getInt(3) );			addGameWorldInfo( pGameWorldInfo );		}		cout << "End GameWorldInfoManager Load"<< endl;		// 鞘混 昏力!		SAFE_DELETE( pStmt );	} catch ( SQLQueryException & sqe ) {		// 鞘混 昏力!		SAFE_DELETE( pStmt );		throw Error(sqe.toString());	} catch ( Throwable & t ) {		SAFE_DELETE( pStmt );		cout << t.toString() << endl;	}	__END_CATCH}//----------------------------------------------------------------------// clear info //----------------------------------------------------------------------void GameWorldInfoManager::clear()	throw( Error ){	__BEGIN_TRY	HashMapGameWorldInfo::iterator itr = m_GameWorldInfos.begin();	for ( ; itr != m_GameWorldInfos.end(); itr++ )	{		GameWorldInfo* pGameWorldInfo = itr->second;		SAFE_DELETE( pGameWorldInfo );	}	m_GameWorldInfos.clear();	__END_CATCH}//----------------------------------------------------------------------// add info //----------------------------------------------------------------------void GameWorldInfoManager::addGameWorldInfo ( GameWorldInfo * pGameWorldInfo ) 	throw ( DuplicatedException ){	__BEGIN_TRY	cout << pGameWorldInfo->toString() << endl;	cout << "Size : " << m_GameWorldInfos.size() << endl;	HashMapGameWorldInfo::iterator itr = m_GameWorldInfos.find( pGameWorldInfo->getID() );		if ( itr != m_GameWorldInfos.end() )		throw DuplicatedException("duplicated game-server nickname");	m_GameWorldInfos[ pGameWorldInfo->getID() ] = pGameWorldInfo;	__END_CATCH}	//----------------------------------------------------------------------// delete info//----------------------------------------------------------------------void GameWorldInfoManager::deleteGameWorldInfo ( const WorldID_t ID ) 	throw ( NoSuchElementException ){	__BEGIN_TRY			HashMapGameWorldInfo::iterator itr = m_GameWorldInfos.find( ID );		if ( itr != m_GameWorldInfos.end() ) {		// GameWorldInfo 甫 昏力茄促.		delete itr->second;		// pair甫 昏力茄促.		m_GameWorldInfos.erase( itr );	} else {		// 弊繁 霸烙辑滚牢器 按眉甫 茫阑 荐 绝阑 锭		throw NoSuchElementException();	}	__END_CATCH}	//----------------------------------------------------------------------// get Worldinfo by WorldID//----------------------------------------------------------------------GameWorldInfo * GameWorldInfoManager::getGameWorldInfo ( const WorldID_t ID ) const	throw ( NoSuchElementException ){	__BEGIN_TRY			GameWorldInfo * pGameWorldInfo = NULL;	HashMapGameWorldInfo::const_iterator itr = m_GameWorldInfos.find( ID );		if ( itr != m_GameWorldInfos.end() ) {		pGameWorldInfo = itr->second;	} else {		// 弊繁 霸烙辑滚牢器 按眉甫 茫阑 荐 绝菌阑 锭		throw NoSuchElementException();	}	return pGameWorldInfo;	__END_CATCH}//----------------------------------------------------------------------// get debug string//----------------------------------------------------------------------string GameWorldInfoManager::toString () const	throw (){	__BEGIN_TRY	StringStream msg;	msg << "GameWorldInfoManager(\n";	if ( m_GameWorldInfos.empty() ) {		msg << "EMPTY";	} else {		//--------------------------------------------------		// *OPTIMIZATION*		//		// for_each()甫 荤侩且 巴		//--------------------------------------------------		for ( HashMapGameWorldInfo::const_iterator itr = m_GameWorldInfos.begin() ; 			  itr != m_GameWorldInfos.end() ; 			  itr ++ )			msg << itr->second->toString() << '\n';	}	msg << ")";	return msg.toString();	__END_CATCH}// global variable definitionGameWorldInfoManager * g_pGameWorldInfoManager = NULL;

⌨️ 快捷键说明

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