示例#1
0
	bool loadLand (const string &filename)
	{
		try
		{
			CIFile fileIn;
			if (fileIn.open (filename))
			{
				CIXml xml (true);
				xml.init (fileIn);
				ZoneRegion = new CZoneRegion;
				ZoneRegion->serial (xml);
			}
			else
			{
				string sTmp = string("Can't open file : ") + filename;
				outString (sTmp);
				return false;
			}
		}
		catch (Exception& e)
		{
			string sTmp = string("Error in land file : ") + e.what();
			outString (sTmp);
			return false;
		}
		return true;
	}
示例#2
0
/*
 *		readFile()
 */
void	CPrimChecker::readFile(const string &filename)
{
	string	fullpath = CPath::lookup(filename, false);

	if (fullpath.empty())
		return;

	// lookup for primitive file
	CIFile		f(fullpath);
	CIXml		xml;

	CPrimitives	prims;

	// load xml file
	xml.init(f);
	if (Verbose)
		nlinfo("Loaded prim file '%s'", filename.c_str());

	// read nodes
	if (!prims.read(xml.getRootNode(), filename.c_str(), LigoConfig))
	{
		nlwarning("Can't use primitive file '%s', xml parse error",  filename.c_str());
		return;
	}

	// get CPrimNode
	CPrimNode	*primRootNode = prims.RootNode;

	// read recursive node
	readPrimitive(primRootNode);
}
示例#3
0
void CSoundAnimation::load()
{
	CIFile file;

	// Open the file
	if (!file.open(_Filename.c_str()))
	{
		throw NLMISC::Exception("Can't open the file for reading");
	}

	// Create the XML stream
	CIXml input;

	// Init
	if (input.init (file))
	{
		xmlNodePtr animNode = input.getRootNode ();
		xmlNodePtr markerNode = input.getFirstChildNode(animNode, "MARKER");

		while (markerNode != 0)
		{
			CSoundAnimMarker* marker = new CSoundAnimMarker();

			const char *time = (const char*) xmlGetProp(markerNode, (xmlChar*) "time");
			if (time == 0)
			{
				throw NLMISC::Exception("Invalid sound animation marker");
			}

			marker->setTime((float) atof(time));
			xmlFree ((void*)time);


			xmlNodePtr soundNode = input.getFirstChildNode(markerNode, "SOUND");

			while (soundNode != 0)
			{
				char *name = (char*) xmlGetProp(soundNode, (xmlChar*) "name");
				if (name == 0)
				{
					throw NLMISC::Exception("Invalid sound animation marker");
				}

				marker->addSound(NLMISC::CSheetId(string(name), "sound"));

				xmlFree ((void*)name);

				soundNode = input.getNextChildNode(soundNode, "SOUND");
			}

			addMarker(marker);

			markerNode = input.getNextChildNode(markerNode, "MARKER");
		}
	}

	// Close the file
	file.close ();
	_Dirty = false;
}
示例#4
0
文件: main.cpp 项目: sythaeryn/pndrpg
// ---------------------------------------------------------------------------
CZoneRegion *loadLand (const string &filename)
{
	CZoneRegion *ZoneRegion = NULL;
	try
	{
		CIFile fileIn;
		if (fileIn.open (filename))
		{
			// Xml
			CIXml xml (true);
			nlverify (xml.init (fileIn));

			ZoneRegion = new CZoneRegion;
			ZoneRegion->serial (xml);
		}
		else
		{
			string sTmp = string("Can't open the land file : ") + filename;
			outString (sTmp);
		}
	}
	catch (const Exception& e)
	{
		string sTmp = string("Error in land file : ") + e.what();
		outString (sTmp);
	}
	return ZoneRegion;
}
示例#5
0
/*
 * Load State
 */
bool	CDatabaseState::load(const std::string& rootpath, bool usePrevious)
{
	CIFile		f;
	CIXml		ixml;

	string		filename = CPath::standardizePath(rootpath);
	if (usePrevious)
		filename += "previous_state";
	else
		filename += "state";

	if (!f.open(filename) || !ixml.init(f))
		return false;

	try
	{
		serial(ixml);
	}
	catch (const Exception&)
	{
		return false;
	}

	return true;
}
// ***************************************************************************
bool CInputHandlerManager::readInputConfigFile(const std::string & fileName)
{
	// parse the XML input config file to build the events to actions map
	CIXml read;
	CIFile file;
	xmlNodePtr root;
	if (!file.open(fileName))
	{
		nlinfo(" could not open file %s",fileName.c_str());
	}
	try
	{
		read.init (file);
		root = read.getRootNode();

	}
	catch (Exception &e)
	{
		// Output error
		root = NULL;
		nlwarning ("CFormLoader: Error while loading the xml input file : %s", e.what());
	}
	if (!root)
	{
		nlinfo ("no root element in xml file %s",fileName.c_str());
		return false;
	}
	//the root node name should be input_config
	if (strcmp( (char*)root->name,"input_config") )
	{
		nlinfo("in a xml input config, the root node must be <input_config>");
		return false;
	}

	//get all system nodes
	xmlNodePtr cur = root->xmlChildrenNode;
	while (cur)
	{
		// Read all combo_key_chat setup.
		if ( !strcmp((char*)cur->name,"combo_key_chat") )
			parseComboKeyChat(cur);

		cur= cur->next;
	}

	return true;
}
示例#7
0
// init
void	CGenericXmlMsgHeaderManager::init(const string &filename)
{
	// open xml file
	CIFile file;
	if (!file.open (filename))
	{
		nlwarning("Cannot open xml file '%s', unable to initialize generic messages", filename.c_str());
		return;
	}

	// Init an xml stream
	CIXml read;
	read.init (file);

	// create root node from root xml node
	_Root = new CNode(read.getRootNode(), 0);
}
示例#8
0
/*
 * Load a Reference index file
 */
bool	CRefIndex::load(const string& filename)
{
	CIFile		reffile;
	CIXml		ixml;

	if (!reffile.open(filename) || !ixml.init(reffile))
		return false;

	try
	{
		serial(ixml);
	}
	catch (const Exception&)
	{
		return false;
	}

	return true;
}
示例#9
0
/*
 * Load the ranges from a data file
 */
void				CRangeMirrorManager::loadRanges()
{
	try
	{
		CIFile file;
		if ( file.open( RANGE_MANAGER_BACKUP_FILE ) )
		{
			CIXml input;
			if ( input.init( file ) )
			{
				input.serialCont( _RangeListByDataSet );
			}
			file.close();
		}
		else
			throw EFileNotOpened( RANGE_MANAGER_BACKUP_FILE );
		nlinfo( "RangeMirrorManager: successfully loaded ranges" );
	}
	catch ( Exception& e )
	{
		nlinfo( "Can't load ranges: %s", e.what() ); // Info because not a problem
	}
}
//-----------------------------------------------
//	init
//
//-----------------------------------------------
void CCDBSynchronised::init( const string &fileName, NLMISC::IProgressCallback &progressCallBack )
{
	try
	{
		CIFile file;
		if (file.open (fileName))
		{
			// Init an xml stream
			CIXml read;
			read.init (file);

			//Parse the parser output!!!
			CCDBNodeBranch::resetNodeBankMapping(); // in case the game is restarted from start
			_Database = new CCDBNodeBranch("SERVER");
			_Database->init( read.getRootNode (), progressCallBack, true );
		}
	}
	catch (Exception &e)
	{
		// Output error
		nlwarning ("CFormLoader: Error while loading the form %s: %s", fileName.c_str(), e.what());
	}
}
void CRingAccess::init()
{



	if (_Initialised ) { return; } // no double initialisation
	_CustomNpcSheetId.clear();
	//CSheetId::init() must be called first
	_CustomNpcSheetId.insert(CSheetId("basic_matis_male.creature"));
	_CustomNpcSheetId.insert(CSheetId("basic_fyros_male.creature"));
	_CustomNpcSheetId.insert(CSheetId("basic_tryker_male.creature"));
	_CustomNpcSheetId.insert(CSheetId("basic_zorai_male.creature"));

	_CustomNpcSheetId.insert(CSheetId("basic_matis_female.creature"));
	_CustomNpcSheetId.insert(CSheetId("basic_fyros_female.creature"));
	_CustomNpcSheetId.insert(CSheetId("basic_tryker_female.creature"));
	_CustomNpcSheetId.insert(CSheetId("basic_zorai_female.creature"));


	for (uint32 i = 0 ; i <= 184 ; ++i)
	{
		_R2PlotItemSheetId.insert( CSheetId( NLMISC::toString("r2_plot_item_%d.sitem", i)));
	}

	_SheetIdToAccess.clear();//only usefull when manualy re init file
	// File stream
	CIFile file;


	std::string pathFileName = CPath::lookup(RingAccessFilename, false, false, false);
	// Open the file
	if (pathFileName.empty() || !file.open(pathFileName.c_str()))
	{
		nlinfo("Can't open the file for reading : %s", RingAccessFilename.c_str());
		return;
	}



	// Create the XML stream
	CIXml input;

	// Init
	if(input.init(file))
	{
		xmlNodePtr entitiesAccess = input.getRootNode();
		xmlNodePtr entityAccess = input.getFirstChildNode(entitiesAccess, "entityAccess");

		while (entityAccess != 0)
		{

			// island name
			CXMLAutoPtr namePtr( (const char*) xmlGetProp(entityAccess, (xmlChar*) "name") );
			CXMLAutoPtr packagePtr( (const char*) xmlGetProp(entityAccess, (xmlChar*) "package") );
			CXMLAutoPtr sheetClientPtr( (const char*) xmlGetProp(entityAccess, (xmlChar*) "sheetClient") );
			CXMLAutoPtr sheetPtr( (const char*) xmlGetProp(entityAccess, (xmlChar*) "sheetServer") );

			if (!namePtr.getDatas()|| !packagePtr.getDatas() || !sheetPtr.getDatas() || !sheetPtr.getDatas())
			{
				nlerror( "Syntax error in %s", pathFileName.c_str());
				return;
			}

			std::string sheet( sheetPtr.getDatas() );
			std::string package( packagePtr.getDatas() );
			std::string sheetClient(sheetClientPtr.getDatas());


			CSheetId sheetClientId(sheetClient);
			CSheetId sheetId; // no sheet server

			if (sheet.empty())
			{
				bool ok = _SheetIdToAccess.insert( std::make_pair(std::make_pair(sheetClientId, sheetId), package)).second;
				if (!ok)
				{
					std::string previousPackage = _SheetIdToAccess[std::make_pair(sheetClientId, sheetId)];
					// only display warning if one key has multiple package
					if ( previousPackage != package )
					{
						nlwarning("%s: Entity %s sheet(%s) is defined more than once with different package definition. Previous definition is '%s', current definition is '%s'", RingAccessFilename.c_str(), namePtr.getDatas(), sheetClientPtr.getDatas(), previousPackage.c_str(), package.c_str());
					}

				}
			}
			else
			{


				sheetId = CSheetId(sheet);
				if (_CustomNpcSheetId.find(sheetClientId) != _CustomNpcSheetId.end())
				{

					bool ok = _SheetIdToAccess.insert( std::make_pair(std::make_pair(sheetClientId, sheetId), package)).second;
					if (!ok)
					{
						std::string previousPackage = _SheetIdToAccess[std::make_pair(sheetClientId, sheetId)];
						// only display warning if one key has multiple package
						if ( previousPackage != package )
						{
							nlwarning("%s: Entity %s sheet(%s) is defined more than once. Previous definition is '%s', current definition is '%s'", RingAccessFilename.c_str(), namePtr.getDatas(), sheetPtr.getDatas(), previousPackage.c_str(), package.c_str());
						}
					}
				}
				else
				{
					nlwarning("%s: Entity %s has invalid sheets %s %s", RingAccessFilename.c_str(), namePtr.getDatas(), sheetClientPtr.getDatas(), sheetPtr.getDatas());
				}
			}


			entityAccess = input.getNextChildNode(entityAccess, "entityAccess");
		}
	}

	// Close the file
	file.close ();

	_Initialised = true;

}