Original Post
Ok. im working on a code for my game(server for another game). anyhow im working on a new guild system that is more efficient so ive got it to the part where it loads the guild file, and im testing to see if it will read it but thats where i get confused.. its guilds.xml ~~the file im trying to load/read and tell stuff by the file. ~heres my code Guilds.cpp ~~~~~~~~~~~~ ////////////////////////////////////////////////////////////////////// // OpenTibia - an opensource roleplaying game ////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////// // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ////////////////////////////////////////////////////////////////////// #include "definitions.h" #include #include #include #include #include #include #include #include #include "guilds.h" bool Guild::loadGuilds(const std::string &datadir) { std::string name, words; // for(int i=0;i<25;i++){ // std::string member; // } bool enabled = false; int guildrank = 0; this->loaded = false; this->name=true; std::string filename = datadir + "guilds/guilds.xml"; std::transform(filename.begin(), filename.end(), filename.begin(), tolower); xmlDocPtr doc = xmlParseFile(filename.c_str()); if (doc){ this->loaded=true; xmlNodePtr root, p, tmp; root = xmlDocGetRootElement(doc); if (xmlStrcmp(root->name,(const xmlChar*) "guilds")){ //TODO: use exceptions here std::cerr << "Malformed XML" << std::endl; } p = root->children; while (p) { const char* str = (char*)p->name; if (strcmp(str, "guild") == 0){ if ((const char*)xmlGetProp(p, (const xmlChar *)"enabled")) { enabled = (bool)(atoi((const char*)xmlGetProp(p, (const xmlChar *)"enabled")) > 0); } if (enabled==1){ std::cout << "guild enabled"; if ((const char*)xmlGetProp(p, (const xmlChar *)"name")) { name = (const char*)xmlGetProp(p, (const xmlChar *)"name"); // std::transform(name.begin(), name.end(), name.begin(), tolower); } if ((const char*)xmlGetProp(p, (const xmlChar *)"guildrank")) { guildrank = atoi((const char*)xmlGetProp(p, (const xmlChar *)"guildrank")); } // Guild* guild = new PlayerGuild(datadir, name, guildrank, game); }else{ std::cout << "not enabled"; } xmlFreeDoc(doc); } return this->loaded; } } } Guilds.h ~~~~~~~~~~~~~~~~~~~ ////////////////////////////////////////////////////////////////////// // OpenTibia - an opensource roleplaying game ////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////// // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ////////////////////////////////////////////////////////////////////// #ifndef __guilds_h_ #define __guilds_h_ #include "game.h" #include "luascript.h" #include "player.h" extern "C" { #include #include #include } ////////////////////////////////////////////////////////////////////// // Defines a Spell... class Guild { public: bool loadFromXml(const std::string&); bool Guild::loadGuilds(const std::string &datadir); bool loaded; bool name; }; /*class Guilds { public: Guild(std::string name, int guildrank, Game* game); virtual ~Guild(); Game* game; protected: std::string name; int guildrank; Guild* guild; }; class PlayerGuild : public Guild { public: PlayerGuild(const std::string &, std::string name, int guildrank,Game* game); protected: std::string words; }; */ #endif and i have this in my mainfile which loads everything std::cout << ":: Loading guilds guilds.xml... "; if(!guild.loadGuilds(g_config.getGlobalString("datadir"))) { //if(guild.loadGuilds ErrorMessage("Unable to load guilds.xml!"); return -1; } std::cout << "[done]" << std::endl; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`i'll post the whole source too.... its rapidshare soo heres the link... http://rapidshare.de/files/5266636/game_server.zip.html now i got it to load.. im just trying to get it to read it now... thanks for any help apreciated =).