summaryrefslogtreecommitdiff
path: root/src/game-server/mapreader.cpp
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2011-03-23 21:11:18 +0100
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2011-03-23 23:08:23 +0100
commit7967b82c19bfa5bd2249abcb807a7a55af031abe (patch)
tree751fdbd7c49466aa2f4a47e237ca489895078018 /src/game-server/mapreader.cpp
parent0391a2203100d1c6c45e8eb92f10ab625d66906b (diff)
downloadmanaserv-7967b82c19bfa5bd2249abcb807a7a55af031abe.tar.gz
manaserv-7967b82c19bfa5bd2249abcb807a7a55af031abe.tar.bz2
manaserv-7967b82c19bfa5bd2249abcb807a7a55af031abe.tar.xz
manaserv-7967b82c19bfa5bd2249abcb807a7a55af031abe.zip
Fixed problems with loading XML files containing Windows newlines
By using xmlParseFile instead of xmlParseMemory, the system-dependent newlines should be handled automatically. The .tmx.gz files should still be supported, but instead of manually decompressing them the xmlParseFile function should take care of that. It also fixes the leaking of XML documents in both the SkillManager as well as the PermissionManager, since they now rely on XML::Document, which cleans up automatically. Reviewed-by: Stefan Dombrowski
Diffstat (limited to 'src/game-server/mapreader.cpp')
-rw-r--r--src/game-server/mapreader.cpp53
1 files changed, 6 insertions, 47 deletions
diff --git a/src/game-server/mapreader.cpp b/src/game-server/mapreader.cpp
index 80d0a107..462105f2 100644
--- a/src/game-server/mapreader.cpp
+++ b/src/game-server/mapreader.cpp
@@ -20,7 +20,6 @@
#include "game-server/mapreader.h"
-#include "common/resourcemanager.h"
#include "game-server/map.h"
#include "game-server/mapcomposite.h"
#include "game-server/mapmanager.h"
@@ -40,58 +39,18 @@ static std::vector< int > tilesetFirstGids;
bool MapReader::readMap(const std::string &filename, MapComposite *composite)
{
- int fileSize;
- char *buffer = ResourceManager::loadFile(filename, fileSize);
-
- if (buffer == NULL)
- {
- LOG_ERROR("Error: Map file not found (" << filename.c_str() << ")");
- return false;
- }
-
- xmlDocPtr doc = NULL;
-
- int l = filename.length();
- if (l > 3 && filename.substr(l - 3) == ".gz")
- {
- // Inflate the gzipped map data.
- char *inflated;
- unsigned inflatedSize = 0;
- bool ret = inflateMemory(buffer, fileSize, inflated, inflatedSize);
- free(buffer);
- buffer = ret ? inflated : NULL;
- fileSize = inflatedSize;
- }
-
- if (buffer)
- {
- // Parse the XML document.
- doc = xmlParseMemory(buffer, fileSize);
- free(buffer);
- }
-
- if (!doc)
- {
- LOG_ERROR("Error while parsing map file '" << filename << "'!");
- return false;
- }
-
- Map *map = NULL;
- xmlNodePtr node = xmlDocGetRootElement(doc);
-
- std::vector<Thing *> things;
+ XML::Document doc(filename);
+ xmlNodePtr rootNode = doc.rootNode();
// Parse the inflated map data.
- if (node && xmlStrEqual(node->name, BAD_CAST "map"))
- {
- map = MapReader::readMap(node, filename, composite, things);
- }
- else
+ if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "map"))
{
LOG_ERROR("Error: Not a map file (" << filename << ")!");
+ return false;
}
- xmlFreeDoc(doc);
+ std::vector<Thing *> things;
+ Map *map = readMap(rootNode, filename, composite, things);
if (map)
{