Esempio n. 1
0
//-------------------------------------------------------------------------------------
std::string MessageHandlers::getDigestStr()
{
	static KBE_MD5 md5;

	if(!md5.isFinal())
	{
		std::map<uint16, std::pair< std::string, std::string> > errsDescrs;

		TiXmlNode *rootNode = NULL;
		XmlPlus* xml = new XmlPlus(Resmgr::getSingleton().matchRes("server/server_errors.xml").c_str());

		if(!xml->isGood())
		{
			ERROR_MSG(fmt::format("MessageHandlers::getDigestStr(): load {} is failed!\n",
				Resmgr::getSingleton().matchRes("server/server_errors.xml")));

			SAFE_RELEASE(xml);
			return "";
		}

		int32 isize = 0;

		rootNode = xml->getRootNode();
		XML_FOR_BEGIN(rootNode)
		{
			TiXmlNode* node = xml->enterNode(rootNode->FirstChild(), "id");
			TiXmlNode* node1 = xml->enterNode(rootNode->FirstChild(), "descr");

			int32 val1 = xml->getValInt(node);
			md5.append((void*)&val1, sizeof(int32));

			std::string val2 = xml->getKey(rootNode);
			md5.append((void*)val2.c_str(), val2.size());

			std::string val3 = xml->getVal(node1);
			md5.append((void*)val3.c_str(), val3.size());
			isize++;
		}
		XML_FOR_END(rootNode);

		SAFE_RELEASE(xml);

		md5.append((void*)&isize, sizeof(int32));

		

		std::vector<MessageHandlers*>& msgHandlers = messageHandlers();
		isize += msgHandlers.size();
		md5.append((void*)&isize, sizeof(int32));

		std::vector<MessageHandlers*>::const_iterator rootiter = msgHandlers.begin();
		for(; rootiter != msgHandlers.end(); rootiter++)
		{
			isize += (*rootiter)->msgHandlers().size();
			md5.append((void*)&isize, sizeof(int32));

			MessageHandlerMap::const_iterator iter = (*rootiter)->msgHandlers().begin();
			for(; iter != (*rootiter)->msgHandlers().end(); iter++)
			{
				MessageHandler* pMessageHandler = iter->second;
			
				md5.append((void*)pMessageHandler->name.c_str(), pMessageHandler->name.size());
				md5.append((void*)&pMessageHandler->msgID, sizeof(MessageID));
				md5.append((void*)&pMessageHandler->msgLen, sizeof(int32));
				md5.append((void*)&pMessageHandler->exposed, sizeof(bool));
	 
				int32 argsize = pMessageHandler->pArgs->strArgsTypes.size();
				md5.append((void*)&argsize, sizeof(int32));

				int32 argsdataSize = pMessageHandler->pArgs->dataSize();
				md5.append((void*)&argsdataSize, sizeof(int32));

				int32 argstype = (int32)pMessageHandler->pArgs->type();
				md5.append((void*)&argstype, sizeof(int32));

				std::vector<std::string>::iterator saiter = pMessageHandler->pArgs->strArgsTypes.begin();
				for(; saiter != pMessageHandler->pArgs->strArgsTypes.end(); saiter++)
				{
					md5.append((void*)(*saiter).c_str(), (*saiter).size());
				}
			}
		}
	}
Esempio n. 2
0
//-------------------------------------------------------------------------------------
bool DataTypes::loadAlias(std::string& file)
{
	TiXmlNode* node = NULL;
	XmlPlus* xml = new XmlPlus(Resmgr::getSingleton().matchRes(file).c_str());

	if(xml == NULL || !xml->isGood())
		return false;

	node = xml->getRootNode();

	if(node == NULL)
	{
		ERROR_MSG("DataTypes::loadAlias: not found node<root->firstChildNode> !\n");
		return false;
	}

	XML_FOR_BEGIN(node)
	{
		std::string type = "";
		std::string aliasName = xml->getKey(node);
		TiXmlNode* childNode = node->FirstChild();

		if(childNode != NULL)
		{
			type = xml->getValStr(childNode);
			if(type == "FIXED_DICT")
			{
				FixedDictType* fixedDict = new FixedDictType;
				
				if(fixedDict->initialize(xml, childNode))
				{
					addDateType(aliasName, fixedDict);
				}
				else
				{
					ERROR_MSG(boost::format("DataTypes::loadAlias:parse FIXED_DICT [%1%] is error!\n") % 
						aliasName.c_str());
					
					delete fixedDict;
					return false;
				}
			}
			else if(type == "ARRAY")
			{
				FixedArrayType* fixedArray = new FixedArrayType;
				
				if(fixedArray->initialize(xml, childNode))
				{
					addDateType(aliasName, fixedArray);
				}
				else
				{
					ERROR_MSG(boost::format("DataTypes::loadAlias:parse ARRAY [%1%] is error!\n") % 
						aliasName.c_str());
					
					delete fixedArray;
					return false;
				}
			}
			else
			{
				DataType* dataType = getDataType(type);
				if(dataType == NULL)
				{
					ERROR_MSG(boost::format("DataTypes::loadAlias:can't fount type %1% by alias[%2%].\n") % 
						type.c_str() % aliasName.c_str());
					
					return false;
				}

				addDateType(aliasName, dataType);
			}
		}
	}
	XML_FOR_END(node);
	
	delete xml;
	return true;
}