diff options
-rw-r--r-- | ChangeLog | 29 | ||||
-rw-r--r-- | src/game-server/mapreader.cpp | 36 | ||||
-rw-r--r-- | src/game-server/mapreader.hpp | 10 |
3 files changed, 48 insertions, 27 deletions
@@ -1,19 +1,24 @@ +2008-08-04 Bjørn Lindeijer <bjorn@lindeijer.nl> + + * src/game-server/mapreader.cpp, src/game-server/mapreader.hpp: Fixed + another crash when reading inlined object properties. + 2008-07-28 Roderic Morris <roderic@ccs.neu.edu> - * src/game-server/character.cpp: avoid a crash caused by the last commit. - * src/game-server/being.cpp: calculate magic damage according to wiki spec. - * src/account-server/dalstorage.cpp: read guild permissions from the db. - * src/chat-server/guild.hpp, src/chat-server/guild.cpp: use const strings. - + * src/game-server/character.cpp: Avoid a crash caused by the last commit. + * src/game-server/being.cpp: Calculate magic damage according to wiki spec. + * src/account-server/dalstorage.cpp: Read guild permissions from the db. + * src/chat-server/guild.hpp, src/chat-server/guild.cpp: Use const strings. + 2008-07-27 Roderic Morris <roderic@ccs.neu.edu> - * src/game-server/character.cpp: take into account weapon skills - in damage calculation. - + * src/game-server/character.cpp: Take into account weapon skills in + damage calculation. + 2008-07-24 David Athay <ko2fan@gmail.com> - * src/defines.h, src/game-server/movingobject.cpp, - src/game-server/gamehandler.cpp, src/game-server/gamehandler.hpp, + * src/defines.h, src/game-server/movingobject.cpp, + src/game-server/gamehandler.cpp, src/game-server/gamehandler.hpp, gameserver.cbp: Added error message when NPC is too far away. 2008-07-22 David Athay <ko2fan@gmail.com> @@ -56,10 +61,10 @@ 2008-07-03 David Athay <ko2fan@gmail.com> - * src/defines.h, src/game-server/character.cpp, + * src/defines.h, src/game-server/character.cpp, src/game-server/character.hpp, src/game-server/gamehandler.cpp, src/game-server/accountconnection.cpp, src/game-server/gamehandler.hpp, - src/game-server/accountconnection.hpp: Removed guild stuff from game + src/game-server/accountconnection.hpp: Removed guild stuff from game server. Added some party stuff to game server. 2008-07-03 Roderic Morris <roderic@ccs.neu.edu> diff --git a/src/game-server/mapreader.cpp b/src/game-server/mapreader.cpp index c24c99dd..46baaa43 100644 --- a/src/game-server/mapreader.cpp +++ b/src/game-server/mapreader.cpp @@ -276,7 +276,7 @@ Map* MapReader::readMap(xmlNodePtr node, std::string const &path, } int npcId = -1; - char const *scriptText = NULL; + std::string scriptText; for_each_xml_child_node(propertiesNode, objectNode) { @@ -296,15 +296,15 @@ Map* MapReader::readMap(xmlNodePtr node, std::string const &path, } else if (value == "SCRIPT") { - scriptText = (const char *)propertyNode->xmlChildrenNode->content; + scriptText = getObjectProperty(propertyNode, ""); } } } } - if (npcId != -1 && scriptText != NULL) + if (npcId != -1 && !scriptText.empty()) { - s->loadNPC(objName, npcId, objX, objY, scriptText); + s->loadNPC(objName, npcId, objX, objY, scriptText.c_str()); } else { @@ -322,7 +322,7 @@ Map* MapReader::readMap(xmlNodePtr node, std::string const &path, } std::string scriptFilename; - char const *scriptText = NULL; + std::string scriptText; for_each_xml_child_node(propertiesNode, objectNode) { @@ -338,12 +338,12 @@ Map* MapReader::readMap(xmlNodePtr node, std::string const &path, std::string value = XML::getProperty(propertyNode, "name", std::string()); if (value == "FILENAME") { - scriptFilename = (const char *)propertyNode->xmlChildrenNode->content; + scriptFilename = getObjectProperty(propertyNode, ""); trim(scriptFilename); } else if (value == "TEXT") { - scriptText = (const char *)propertyNode->xmlChildrenNode->content; + scriptText = getObjectProperty(propertyNode, ""); } } } @@ -353,9 +353,9 @@ Map* MapReader::readMap(xmlNodePtr node, std::string const &path, { s->loadFile(scriptFilename); } - else if (scriptText != NULL) + else if (!scriptText.empty()) { - s->load(scriptText); + s->load(scriptText.c_str()); } else { @@ -490,14 +490,28 @@ void MapReader::readLayer(xmlNodePtr node, Map *map) } } +std::string MapReader::getObjectProperty(xmlNodePtr node, + const std::string &def) +{ + if (xmlHasProp(node, BAD_CAST "value")) + { + return XML::getProperty(node, "value", def); + } + else if (const char *prop = (const char *)node->xmlChildrenNode->content) + { + return std::string(prop); + } + return std::string(); +} + int MapReader::getObjectProperty(xmlNodePtr node, int def) { int val = def; - if(xmlHasProp(node, BAD_CAST "value")) + if (xmlHasProp(node, BAD_CAST "value")) { val = XML::getProperty(node, "value", def); } - else if(const char * prop = (const char *)node->xmlChildrenNode->content) + else if (const char *prop = (const char *)node->xmlChildrenNode->content) { val = atoi(prop); } diff --git a/src/game-server/mapreader.hpp b/src/game-server/mapreader.hpp index cb3e70ac..a809cdd9 100644 --- a/src/game-server/mapreader.hpp +++ b/src/game-server/mapreader.hpp @@ -45,27 +45,29 @@ class MapReader static void readMap(const std::string &filename, MapComposite *composite); private: - /** * Read an XML map from a parsed XML tree, and populate things with objects * in that map. */ static Map* readMap(xmlNodePtr node, std::string const &path, MapComposite *composite, std::vector<Thing *> &things); - + /** * Reads a map layer and adds it to the given map. */ static void readLayer(xmlNodePtr node, Map *map); /** + * Get the string value from the given object property node. + */ + static std::string getObjectProperty(xmlNodePtr node, const std::string &def); + + /** * Get the integer value from the given object property node. */ static int getObjectProperty(xmlNodePtr node, int def); static void setTileWithGid(Map *map, int x, int y, int gid); - - }; #endif |