Example #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());
				}
			}
		}
	}
Example #2
0
//-------------------------------------------------------------------------------------
bool DataTypes::loadTypes(std::string& file)
{
	TiXmlNode* node = NULL;
	SmartPointer<XML> xml(new XML(Resmgr::getSingleton().matchRes(file).c_str()));

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

	node = xml->getRootNode();

	if(node == NULL)
	{
		// root节点下没有子节点了
		return true;
	}

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

		// 不允许前面加_, 因为内部产生的一些临时结构前面使用了_, 避免误判
		if (aliasName[0] == '_')
		{
			ERROR_MSG(fmt::format("DataTypes::loadTypes: Not allowed to use the prefix \"_\"! aliasName={}\n",
				aliasName.c_str()));

			return false;
		}

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

				addDataType(aliasName, dataType);
			}
		}
	}
	XML_FOR_END(node);
	
	return true;
}
//-------------------------------------------------------------------------------------
void ScriptDefModule::autoMatchCompOwn()
{
	/*
		entity存在某部分(cell, base, client)的判定规则

		1: entitydef文件中存在实体某部分的方法或者属性,同时也必须也存在py脚本
		2: 用户在entities.xml明确声明存在某实体部分(为了unity3d或者html5类的前端无法加载py的环境考虑)
			entities.xml, <Spaces hasCell="true" hasClient="false", hasBase="true"></Spaces>
	*/

	std::string entitiesFile = Resmgr::getSingleton().getPyUserScriptsPath() + "entities.xml";

	// 打开这个entities.xml文件
	SmartPointer<XML> xml(new XML());
	if(!xml->openSection(entitiesFile.c_str()) || !xml->isGood())
		return;
	
	// 获得entities.xml根节点, 如果没有定义一个entity那么直接返回true
	TiXmlNode* node = xml->getRootNode();
	if(node == NULL)
		return;

	int assertionHasClient = -1;
	int assertionHasBase = -1;
	int assertionHasCell = -1;

	// 开始遍历所有的entity节点
	XML_FOR_BEGIN(node)
	{
		std::string moduleName = xml.get()->getKey(node);
		if(name_ == moduleName)
		{
			const char* val = node->ToElement()->Attribute("hasClient");
			if(val)
			{
				if(kbe_strnicmp(val, "true", strlen(val)) == 0)
					assertionHasClient = 1;
				else
					assertionHasClient = 0;
			}

			EntityDef::md5().append((void*)&assertionHasClient, sizeof(int));

			val = node->ToElement()->Attribute("hasCell");
			if(val)
			{
				if(kbe_strnicmp(val, "true", strlen(val)) == 0)
					assertionHasCell = 1;
				else
					assertionHasCell = 0;
			}

			EntityDef::md5().append((void*)&assertionHasClient, sizeof(int));

			val = node->ToElement()->Attribute("hasBase");
			if(val)
			{
				if(kbe_strnicmp(val, "true", strlen(val)) == 0)
					assertionHasBase = 1;
				else
					assertionHasBase = 0;
			}

			EntityDef::md5().append((void*)&assertionHasClient, sizeof(int));
			break;
		}
	}
	XML_FOR_END(node);

	std::string fmodule = "scripts/client/" + name_ + ".py";
	std::string fmodule_pyc = "scripts/client/"SCRIPT_BIN_CACHEDIR"/" + name_ + "."SCRIPT_BIN_TAG".pyc";
	if(Resmgr::getSingleton().matchRes(fmodule) != fmodule ||
		Resmgr::getSingleton().matchRes(fmodule_pyc) != fmodule_pyc)
	{
		setClient(true);
	}
	else
	{
		if(assertionHasClient < 0)
		{
			// 如果用户不存在明确声明并设置为没有对应实体部分
			// 这样做的原因是允许用户在def文件定义这部分的内容(因为interface的存在,interface中可能会存在客户端属性或者方法)
			// 但如果脚本不存在仍然认为用户当前不需要该部分
			// http://www.kbengine.org/cn/docs/configuration/entities.html 
			setClient(false);
		}
		else
		{
			// 用户明确声明并进行了设定
			setClient(assertionHasClient == 1);
		}
	}

	if(g_componentType == CLIENT_TYPE)
	{
		setBase(true);
		setCell(true);
		return;
	}

	fmodule = "scripts/base/" + name_ + ".py";
	fmodule_pyc = "scripts/base/"SCRIPT_BIN_CACHEDIR"/" + name_ + "."SCRIPT_BIN_TAG".pyc";
	if(Resmgr::getSingleton().matchRes(fmodule) != fmodule ||
		Resmgr::getSingleton().matchRes(fmodule_pyc) != fmodule_pyc)
	{
		setBase(true);
	}
	else
	{
		if(assertionHasBase < 0)
		{
			// 如果用户不存在明确声明并设置为没有对应实体部分
			// 这样做的原因是允许用户在def文件定义这部分的内容
			// 但如果脚本不存在仍然认为用户当前不需要该部分
			setBase(false);
		}
		else
		{
			// 用户明确声明并进行了设定
			setBase(assertionHasBase == 1);
		}
	}

	fmodule = "scripts/cell/" + name_ + ".py";
	fmodule_pyc = "scripts/cell/"SCRIPT_BIN_CACHEDIR"/" + name_ + "."SCRIPT_BIN_TAG".pyc";
	if(Resmgr::getSingleton().matchRes(fmodule) != fmodule ||
		Resmgr::getSingleton().matchRes(fmodule_pyc) != fmodule_pyc)
	{
		setCell(true);
	}
	else
	{
		if(assertionHasCell < 0)
		{
			// 如果用户不存在明确声明并设置为没有对应实体部分
			// 这样做的原因是允许用户在def文件定义这部分的内容
			// 但如果脚本不存在仍然认为用户当前不需要该部分
			setCell(false);
		}
		else
		{
			// 用户明确声明并进行了设定
			setCell(assertionHasCell == 1);
		}
	}
}
Example #4
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;
}