diff options
author | Chuck Miller <shadowmil@gmail.com> | 2009-07-20 17:46:18 -0400 |
---|---|---|
committer | Chuck Miller <shadowmil@gmail.com> | 2009-07-20 17:46:18 -0400 |
commit | 575282d29ac181c990dc76de48c68d86ebd64efe (patch) | |
tree | 71430be3751dc84dbf5681f668099efec09cbcb6 /src/game-server/mapmanager.cpp | |
parent | 5c3f23831986dda46d1c41b8316dd901f1bf3164 (diff) | |
download | manaserv-575282d29ac181c990dc76de48c68d86ebd64efe.tar.gz manaserv-575282d29ac181c990dc76de48c68d86ebd64efe.tar.xz manaserv-575282d29ac181c990dc76de48c68d86ebd64efe.zip |
Have the game server reconnect with the account-server if account-server is restarted
Diffstat (limited to 'src/game-server/mapmanager.cpp')
-rw-r--r-- | src/game-server/mapmanager.cpp | 56 |
1 files changed, 46 insertions, 10 deletions
diff --git a/src/game-server/mapmanager.cpp b/src/game-server/mapmanager.cpp index 0e682af..390331d 100644 --- a/src/game-server/mapmanager.cpp +++ b/src/game-server/mapmanager.cpp @@ -40,15 +40,18 @@ const MapManager::Maps &MapManager::getMaps() return maps; } -void MapManager::initialize(const std::string &mapReferenceFile) +unsigned int MapManager::initialize(const std::string &mapReferenceFile) { + // Indicates the number of maps loaded successfully + unsigned int loadedMaps = 0; + int size; char *data = ResourceManager::loadFile(mapReferenceFile, size); if (!data) { LOG_ERROR("Map Manager: Could not find " << mapReferenceFile << "!"); free(data); - return; + return loadedMaps; } xmlDocPtr doc = xmlParseMemory(data, size); @@ -58,7 +61,7 @@ void MapManager::initialize(const std::string &mapReferenceFile) { LOG_ERROR("Map Manager: Error while parsing map database (" << mapReferenceFile << ")!"); - return; + return loadedMaps; } xmlNodePtr node = xmlDocGetRootElement(doc); @@ -67,7 +70,7 @@ void MapManager::initialize(const std::string &mapReferenceFile) LOG_ERROR("Map Manager: " << mapReferenceFile << " is not a valid database file!"); xmlFreeDoc(doc); - return; + return loadedMaps; } LOG_INFO("Loading map reference..."); @@ -79,13 +82,38 @@ void MapManager::initialize(const std::string &mapReferenceFile) int id = XML::getProperty(node, "id", 0); std::string name = XML::getProperty(node, "name", std::string()); + std::string file = "maps/"; + bool mapFileExists = false; + // Test id and map name if (id != 0 && !name.empty()) { - maps[id] = new MapComposite(id, name); + // Testing if the file is actually in the maps folder + file += name + ".tmx"; + if (!ResourceManager::exists(file)) + { + file += ".gz"; + if (ResourceManager::exists(file)) + { + mapFileExists = true; + } + } + else + { + mapFileExists = true; + } + + if (mapFileExists) + { + maps[id] = new MapComposite(id, name); + loadedMaps++; + } } } xmlFreeDoc(doc); + if (loadedMaps > 0) + LOG_INFO(loadedMaps << " valid map file references were loaded."); + return loadedMaps; } void MapManager::deinitialize() @@ -114,14 +142,14 @@ MapComposite *MapManager::getMap(const std::string &mapName) return NULL; } -void MapManager::raiseActive(int mapId) +bool MapManager::raiseActive(int mapId) { Maps::iterator i = maps.find(mapId); assert(i != maps.end()); MapComposite *composite = i->second; if (composite->isActive()) { - return; + return true; } std::string file = "maps/" + composite->getName() + ".tmx"; @@ -129,9 +157,17 @@ void MapManager::raiseActive(int mapId) { file += ".gz"; } - MapReader::readMap(file, composite); - - LOG_INFO("Activated map \"" << file << "\" (id " << mapId << ")"); + if (MapReader::readMap(file, composite)) + { + LOG_INFO("Activated map \"" << file << "\" (id " << mapId << ")"); + return true; + } + else + { + LOG_WARN("Couldn't activate invalid map \"" << file << "\" (id " << + mapId << ")"); + return false; + } } |