-void ServerMap::saveSectorMeta(ServerMapSector *sector)
-{
- DSTACK(FUNCTION_NAME);
- // Format used for writing
- u8 version = SER_FMT_VER_HIGHEST_WRITE;
- // Get destination
- v2s16 pos = sector->getPos();
- std::string dir = getSectorDir(pos);
- createDirs(dir);
-
- std::string fullpath = dir + DIR_DELIM + "meta";
- std::ostringstream ss(std::ios_base::binary);
-
- sector->serialize(ss, version);
-
- if(!fs::safeWriteToFile(fullpath, ss.str()))
- throw FileNotGoodException("Cannot write sector metafile");
-
- sector->differs_from_disk = false;
-}
-
-MapSector* ServerMap::loadSectorMeta(std::string sectordir, bool save_after_load)
-{
- DSTACK(FUNCTION_NAME);
- // Get destination
- v2s16 p2d = getSectorPos(sectordir);
-
- ServerMapSector *sector = NULL;
-
- std::string fullpath = sectordir + DIR_DELIM + "meta";
- std::ifstream is(fullpath.c_str(), std::ios_base::binary);
- if(is.good() == false)
- {
- // If the directory exists anyway, it probably is in some old
- // format. Just go ahead and create the sector.
- if(fs::PathExists(sectordir))
- {
- /*infostream<<"ServerMap::loadSectorMeta(): Sector metafile "
- <<fullpath<<" doesn't exist but directory does."
- <<" Continuing with a sector with no metadata."
- <<std::endl;*/
- sector = new ServerMapSector(this, p2d, m_gamedef);
- m_sectors[p2d] = sector;
- }
- else
- {
- throw FileNotGoodException("Cannot open sector metafile");
- }
- }
- else
- {
- sector = ServerMapSector::deSerialize
- (is, this, p2d, m_sectors, m_gamedef);
- if(save_after_load)
- saveSectorMeta(sector);
- }
-
- sector->differs_from_disk = false;
-
- return sector;
-}
-
-bool ServerMap::loadSectorMeta(v2s16 p2d)
-{
- DSTACK(FUNCTION_NAME);
-
- // The directory layout we're going to load from.
- // 1 - original sectors/xxxxzzzz/
- // 2 - new sectors2/xxx/zzz/
- // If we load from anything but the latest structure, we will
- // immediately save to the new one, and remove the old.
- int loadlayout = 1;
- std::string sectordir1 = getSectorDir(p2d, 1);
- std::string sectordir;
- if(fs::PathExists(sectordir1))
- {
- sectordir = sectordir1;
- }
- else
- {
- loadlayout = 2;
- sectordir = getSectorDir(p2d, 2);
- }
-
- try{
- loadSectorMeta(sectordir, loadlayout != 2);
- }
- catch(InvalidFilenameException &e)
- {
- return false;
- }
- catch(FileNotGoodException &e)
- {
- return false;
- }
- catch(std::exception &e)
- {
- return false;
- }
-
- return true;
-}
-
-#if 0
-bool ServerMap::loadSectorFull(v2s16 p2d)
-{
- DSTACK(FUNCTION_NAME);
-
- MapSector *sector = NULL;
-
- // The directory layout we're going to load from.
- // 1 - original sectors/xxxxzzzz/
- // 2 - new sectors2/xxx/zzz/
- // If we load from anything but the latest structure, we will
- // immediately save to the new one, and remove the old.
- int loadlayout = 1;
- std::string sectordir1 = getSectorDir(p2d, 1);
- std::string sectordir;
- if(fs::PathExists(sectordir1))
- {
- sectordir = sectordir1;
- }
- else
- {
- loadlayout = 2;
- sectordir = getSectorDir(p2d, 2);
- }
-
- try{
- sector = loadSectorMeta(sectordir, loadlayout != 2);
- }
- catch(InvalidFilenameException &e)
- {
- return false;
- }
- catch(FileNotGoodException &e)
- {
- return false;
- }
- catch(std::exception &e)
- {
- return false;
- }
-
- /*
- Load blocks
- */
- std::vector<fs::DirListNode> list2 = fs::GetDirListing
- (sectordir);
- std::vector<fs::DirListNode>::iterator i2;
- for(i2=list2.begin(); i2!=list2.end(); i2++)
- {
- // We want files
- if(i2->dir)
- continue;
- try{
- loadBlock(sectordir, i2->name, sector, loadlayout != 2);
- }
- catch(InvalidFilenameException &e)
- {
- // This catches unknown crap in directory
- }
- }
-
- if(loadlayout != 2)
- {
- infostream<<"Sector converted to new layout - deleting "<<
- sectordir1<<std::endl;
- fs::RecursiveDelete(sectordir1);
- }
-
- return true;
-}
-#endif
-
-Database *ServerMap::createDatabase(