14 #include "nodemetadata.h"
20 #include "util/directiontables.h"
21 #include "rollback_interface.h"
23 #include "database-dummy.h"
25 Database_Dummy::Database_Dummy(ServerMap *map)
30 int Database_Dummy::Initialized(void)
35 void Database_Dummy::beginSave() {}
36 void Database_Dummy::endSave() {}
38 void Database_Dummy::saveBlock(MapBlock *block)
40 DSTACK(__FUNCTION_NAME);
42 Dummy blocks are not written
49 // Format used for writing
50 u8 version = SER_FMT_VER_HIGHEST_WRITE;
52 v3s16 p3d = block->getPos();
55 [0] u8 serialization version
59 std::ostringstream o(std::ios_base::binary);
60 o.write((char*)&version, 1);
62 block->serialize(o, version, true);
63 // Write block to database
64 std::string tmp = o.str();
66 m_database[getBlockAsInteger(p3d)] = tmp;
67 // We just wrote it to the disk so clear modified flag
68 block->resetModified();
71 MapBlock* Database_Dummy::loadBlock(v3s16 blockpos)
73 v2s16 p2d(blockpos.X, blockpos.Z);
75 if(m_database.count(getBlockAsInteger(blockpos))) {
77 Make sure sector is loaded
79 MapSector *sector = srvmap->createSector(p2d);
83 std::string datastr = m_database[getBlockAsInteger(blockpos)];
84 // srvmap->loadBlock(&datastr, blockpos, sector, false);
87 std::istringstream is(datastr, std::ios_base::binary);
88 u8 version = SER_FMT_VER_INVALID;
89 is.read((char*)&version, 1);
92 throw SerializationError("ServerMap::loadBlock(): Failed"
93 " to read MapBlock version");
95 MapBlock *block = NULL;
96 bool created_new = false;
97 block = sector->getBlockNoCreateNoEx(blockpos.Y);
100 block = sector->createBlankBlockNoInsert(blockpos.Y);
104 block->deSerialize(is, version, true);
105 // If it's a new block, insert it to the map
107 sector->insertBlock(block);
109 Save blocks loaded in old format in new format
112 //if(version < SER_FMT_VER_HIGHEST || save_after_load)
113 // Only save if asked to; no need to update version
114 //if(save_after_load)
116 // We just loaded it from, so it's up-to-date.
117 block->resetModified();
120 catch(SerializationError &e)
122 errorstream<<"Invalid block data in database"
123 <<" ("<<blockpos.X<<","<<blockpos.Y<<","<<blockpos.Z<<")"
124 <<" (SerializationError): "<<e.what()<<std::endl;
125 // TODO: Block should be marked as invalid in memory so that it is
126 // not touched but the game can run
128 if(g_settings->getBool("ignore_world_load_errors")){
129 errorstream<<"Ignoring block load error. Duck and cover! "
130 <<"(ignore_world_load_errors)"<<std::endl;
132 throw SerializationError("Invalid block data in database");
137 return srvmap->getBlockNoCreateNoEx(blockpos); // should not be using this here
142 void Database_Dummy::listAllLoadableBlocks(core::list<v3s16> &dst)
144 for(std::map<unsigned long long, std::string>::iterator x = m_database.begin(); x != m_database.end(); ++x)
146 v3s16 p = getIntegerAsBlock(x->first);
147 //dstream<<"block_i="<<block_i<<" p="<<PP(p)<<std::endl;
152 Database_Dummy::~Database_Dummy()