Example #1
0
bool Vocations::loadFromXml()
{
	xmlDocPtr doc = xmlParseFile(getFilePath(FILE_TYPE_XML,"vocations.xml").c_str());
	if(!doc)
	{
		std::cout << "[Warning - Vocations::loadFromXml] Cannot load vocations file." << std::endl;
		std::cout << getLastXMLError() << std::endl;
		return false;
	}

	xmlNodePtr p, root = xmlDocGetRootElement(doc);
	if(xmlStrcmp(root->name,(const xmlChar*)"vocations"))
	{
		std::cout << "[Error - Vocations::loadFromXml] Malformed vocations file." << std::endl;
		xmlFreeDoc(doc);
		return false;
	}

	p = root->children;
	while(p)
	{
		parseVocationNode(p);
		p = p->next;
	}

	xmlFreeDoc(doc);
	return true;
}
Example #2
0
bool Chat::parseChannelNode(xmlNodePtr p)
{
	int32_t intValue;
	if(xmlStrcmp(p->name, (const xmlChar*)"channel"))
		return false;

	if(!readXMLInteger(p, "id", intValue) || intValue <= CHANNEL_GUILD)
	{
		std::clog << "[Warning - Chat::loadFromXml] Invalid or not specified channel id." << std::endl;
		return false;
	}

	uint16_t id = intValue;
	std::string strValue;
	if(m_normalChannels.find(id) != m_normalChannels.end() && (!readXMLString(p, "override", strValue) || !booleanString(strValue)))
	{
		std::clog << "[Warning - Chat::loadFromXml] Duplicated channel with id: " << id << "." << std::endl;
		return false;
	}

	if(!readXMLString(p, "name", strValue))
	{
		std::clog << "[Warning - Chat::loadFromXml] Missing name for channel with id: " << id << "." << std::endl;
		return false;
	}

	std::string name = strValue;
	uint16_t flags = ChatChannel::staticFlags;
	if(readXMLString(p, "enabled", strValue) && !booleanString(strValue))
		flags &= ~CHANNELFLAG_ENABLED;

	if(readXMLString(p, "active", strValue) && !booleanString(strValue))
		flags &= ~CHANNELFLAG_ACTIVE;

	if((readXMLString(p, "logged", strValue) || readXMLString(p, "log", strValue)) && booleanString(strValue))
		flags |= CHANNELFLAG_LOGGED;

	uint32_t access = 0;
	if(readXMLInteger(p, "access", intValue))
		access = intValue;

	uint32_t level = 1;
	if(readXMLInteger(p, "level", intValue))
		level = intValue;

	int32_t conditionId = -1;
	std::string conditionMessage = "You are muted.";

	Condition* condition = NULL;
	if(readXMLInteger(p, "muted", intValue))
	{
		conditionId = 2;
		int32_t tmp = intValue * 1000;
		if(readXMLInteger(p, "conditionId", intValue))
		{
			conditionId = intValue;
			if(conditionId < 2)
				std::clog << "[Warning - Chat::parseChannelNode] Using reserved muted condition sub id (" << conditionId << ")" << std::endl;
		}

		if((condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_MUTED, tmp, 0, false, conditionId)))
		{
			if(readXMLString(p, "conditionMessage", strValue))
				conditionMessage = strValue;
		}
		else
			conditionId = -1;
	}

	StringVec vocStringVec;
	VocationMap vocMap;

	std::string error;
	for(xmlNodePtr tmpNode = p->children; tmpNode; tmpNode = tmpNode->next)
	{
		if(!parseVocationNode(tmpNode, vocMap, vocStringVec, error))
			std::clog << "[Warning - Chat::loadFromXml] " << error << std::endl;
	}

	VocationMap* vocationMap = NULL;
	if(!vocMap.empty())
		vocationMap = new VocationMap(vocMap);

	switch(id)
	{
		case CHANNEL_PARTY:
		{
			partyName = name;
			break;
		}

		case CHANNEL_PRIVATE:
		{
			if(ChatChannel* newChannel = new PrivateChatChannel(CHANNEL_PRIVATE, name, flags))
				dummyPrivate = newChannel;

			break;
		}

		default:
		{
			if(ChatChannel* newChannel = new ChatChannel(id, name, flags, access, level,
				condition, conditionId, conditionMessage, vocationMap))
				m_normalChannels[id] = newChannel;

			break;
		}
	}

	return true;
}