Exemple #1
0
//	Produces a formatted string of the AIML
string AimlWriter::prettyAiml(PElement element) {
	if (element == NULL) {
		return "";
	}
	string s = "<aiml>\n\n";
	if (element->getTagname() != "aiml") {
		cerr << "Error: Document root is not 'aiml'" << endl;
		return "";
	}
	velement array;
	velement_it ix;
	//	Process <topic> first
	element->getChildren("topic", &array);
	//	All the <topic> nodes...
	for (ix = array.begin(); ix != array.end(); ++ix) {
		velement categories;
		(*ix)->getChildren("category", &categories);
		//	All of the <category> nodes per <topic>
		string topic = (*ix)->getAttribute("name");
		s += "<topic name=\"" + topic + "\">\n\n";
		for (velement_it iy = categories.begin(); iy != categories.end(); ++iy) {
			//	Get the <that> <pattern> and <template>
			string Pattern = recurse((*iy)->getChild("pattern"));
			string That = recurse((*iy)->getChild("that"));
			string Template = recurse((*iy)->getChild("template"));
			
			s += "<category>\n";
			if (!That.empty()) {
				s += "<that>" + That + "</that>\n";
			}
			s += "<pattern>" + Pattern + "</pattern>\n";
			s += "<template>\n" + Template + "\n</template>\n";
			s += "</category>\n\n";
		}
		s += "</topic>\n\n";
	}
	array.clear();
	
	element->getChildren("category", &array);
	//	All the <category> nodes without a <topic>
	for (ix = array.begin(); ix != array.end(); ++ix) {
		//	Get the <that> <pattern> and <template>
		string Pattern = recurse((*ix)->getChild("pattern"));
		string That = recurse((*ix)->getChild("that"));
		string Template = recurse((*ix)->getChild("template"));
		
		s += "<category>\n";
		if (!That.empty()) {
			s += "<that>" + That + "</that>\n";
		}
		s += "<pattern>" + Pattern + "</pattern>\n";
		s += "<template>\n" + Template + "\n</template>\n";
		s += "</category>\n\n";
	}
	
	s += "</aiml>\n";
	
	return s;
}
Exemple #2
0
void Kernel::loadSubstitutions() {
	char installPath[1024];
	unsigned long installPathLen=1023;
	installPath[0]='\0';
	HKEY hkey=NULL;
	if (!RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\Tibia Auto\\",0,KEY_ALL_ACCESS,&hkey))
	{
		RegQueryValueEx(hkey,TEXT("Install_Dir"),NULL,NULL,(unsigned char *)installPath,&installPathLen );
		RegCloseKey(hkey);
	}
	if (!strlen(installPath))
	{
		AfxMessageBox("ERROR! Unable to read TA install directory! Please reinstall!");
		exit(1);
	}
	
	char pathBuf[2048];
	sprintf(pathBuf,"%s\\mods\\substitutions.xml",installPath);
	ifstream fin;
	PElement root;
	fin.open(pathBuf, ios::in | ios::binary);
	
	if (fin.is_open()) {
		SaxParser *p = new SaxParser(new Parser());
		p->parse(fin);
		root = ((Parser *)p->getListener())->getRoot();
		delete p;
		fin.close();
		
		if (root == NULL) {
			return;
		}
	} else {
		return;
	}
	
	velement array;
	velement_it ix;
	root->getChildren("substitute", &array);
	for (ix = array.begin(); ix != array.end(); ++ix) {
		string name = (*ix)->getAttribute("name");
		string find = (*ix)->getAttribute("find");
		string replace = (*ix)->getAttribute("replace");
		Substituter::addSubstitute(name, find, replace);
	}
}