Skip to content

Commit d419e4c

Browse files
committedNov 17, 2013
Do the same for LevelDB interface
1 parent aa172bd commit d419e4c

File tree

2 files changed

+74
-61
lines changed

2 files changed

+74
-61
lines changed
 

‎src/database-leveldb.cpp

+72-59
Original file line numberDiff line numberDiff line change
@@ -92,68 +92,81 @@ MapBlock* Database_LevelDB::loadBlock(v3s16 blockpos)
9292
v2s16 p2d(blockpos.X, blockpos.Z);
9393

9494
std::string datastr;
95-
leveldb::Status s = m_database->Get(leveldb::ReadOptions(), i64tos(getBlockAsInteger(blockpos)), &datastr);
95+
leveldb::Status s = m_database->Get(leveldb::ReadOptions(),
96+
i64tos(getBlockAsInteger(blockpos)), &datastr);
97+
if (datastr.length() == 0) {
98+
errorstream << "Blank block data in database (datastr.length() == 0) ("
99+
<< blockpos.X << "," << blockpos.Y << "," << blockpos.Z << ")" << std::endl;
100+
101+
if (g_settings->getBool("ignore_world_load_errors")) {
102+
errorstream << "Ignoring block load error. Duck and cover! "
103+
<< "(ignore_world_load_errors)" << std::endl;
104+
} else {
105+
throw SerializationError("Blank block data in database");
106+
}
107+
}
96108

97-
if(s.ok()) {
98-
/*
99-
Make sure sector is loaded
100-
*/
101-
MapSector *sector = srvmap->createSector(p2d);
109+
if (s.ok()) {
110+
/*
111+
Make sure sector is loaded
112+
*/
113+
MapSector *sector = srvmap->createSector(p2d);
102114

103115
try {
104-
std::istringstream is(datastr, std::ios_base::binary);
105-
u8 version = SER_FMT_VER_INVALID;
106-
is.read((char*)&version, 1);
107-
108-
if(is.fail())
109-
throw SerializationError("ServerMap::loadBlock(): Failed"
110-
" to read MapBlock version");
111-
112-
MapBlock *block = NULL;
113-
bool created_new = false;
114-
block = sector->getBlockNoCreateNoEx(blockpos.Y);
115-
if(block == NULL)
116-
{
117-
block = sector->createBlankBlockNoInsert(blockpos.Y);
118-
created_new = true;
119-
}
120-
// Read basic data
121-
block->deSerialize(is, version, true);
122-
// If it's a new block, insert it to the map
123-
if(created_new)
124-
sector->insertBlock(block);
125-
/*
126-
Save blocks loaded in old format in new format
127-
*/
128-
129-
//if(version < SER_FMT_VER_HIGHEST || save_after_load)
130-
// Only save if asked to; no need to update version
131-
//if(save_after_load)
132-
// saveBlock(block);
133-
// We just loaded it from, so it's up-to-date.
134-
block->resetModified();
135-
136-
}
137-
catch(SerializationError &e)
138-
{
139-
errorstream<<"Invalid block data in database"
140-
<<" ("<<blockpos.X<<","<<blockpos.Y<<","<<blockpos.Z<<")"
141-
<<" (SerializationError): "<<e.what()<<std::endl;
142-
// TODO: Block should be marked as invalid in memory so that it is
143-
// not touched but the game can run
144-
145-
if(g_settings->getBool("ignore_world_load_errors")){
146-
errorstream<<"Ignoring block load error. Duck and cover! "
147-
<<"(ignore_world_load_errors)"<<std::endl;
148-
} else {
149-
throw SerializationError("Invalid block data in database");
150-
//assert(0);
151-
}
152-
}
153-
154-
return srvmap->getBlockNoCreateNoEx(blockpos); // should not be using this here
155-
}
156-
return(NULL);
116+
std::istringstream is(datastr, std::ios_base::binary);
117+
u8 version = SER_FMT_VER_INVALID;
118+
is.read((char *)&version, 1);
119+
120+
if (is.fail())
121+
throw SerializationError("ServerMap::loadBlock(): Failed"
122+
" to read MapBlock version");
123+
124+
MapBlock *block = NULL;
125+
bool created_new = false;
126+
block = sector->getBlockNoCreateNoEx(blockpos.Y);
127+
if (block == NULL)
128+
{
129+
block = sector->createBlankBlockNoInsert(blockpos.Y);
130+
created_new = true;
131+
}
132+
133+
// Read basic data
134+
block->deSerialize(is, version, true);
135+
136+
// If it's a new block, insert it to the map
137+
if (created_new)
138+
sector->insertBlock(block);
139+
140+
/*
141+
Save blocks loaded in old format in new format
142+
*/
143+
//if(version < SER_FMT_VER_HIGHEST || save_after_load)
144+
// Only save if asked to; no need to update version
145+
//if(save_after_load)
146+
// saveBlock(block);
147+
// We just loaded it from, so it's up-to-date.
148+
block->resetModified();
149+
}
150+
catch (SerializationError &e)
151+
{
152+
errorstream << "Invalid block data in database"
153+
<< " (" << blockpos.X << "," << blockpos.Y << "," << blockpos.Z
154+
<< ") (SerializationError): " << e.what() << std::endl;
155+
// TODO: Block should be marked as invalid in memory so that it is
156+
// not touched but the game can run
157+
158+
if (g_settings->getBool("ignore_world_load_errors")) {
159+
errorstream << "Ignoring block load error. Duck and cover! "
160+
<< "(ignore_world_load_errors)" << std::endl;
161+
} else {
162+
throw SerializationError("Invalid block data in database");
163+
//assert(0);
164+
}
165+
}
166+
167+
return srvmap->getBlockNoCreateNoEx(blockpos); // should not be using this here
168+
}
169+
return NULL;
157170
}
158171

159172
void Database_LevelDB::listAllLoadableBlocks(std::list<v3s16> &dst)

‎src/database-sqlite3.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ MapBlock* Database_SQLite3::loadBlock(v3s16 blockpos)
247247
std::istringstream is(datastr, std::ios_base::binary);
248248

249249
u8 version = SER_FMT_VER_INVALID;
250-
is.read((char*)&version, 1);
250+
is.read((char *)&version, 1);
251251

252252
if (is.fail())
253253
throw SerializationError("ServerMap::loadBlock(): Failed"
@@ -280,7 +280,7 @@ MapBlock* Database_SQLite3::loadBlock(v3s16 blockpos)
280280
// We just loaded it from, so it's up-to-date.
281281
block->resetModified();
282282
}
283-
catch(SerializationError &e)
283+
catch (SerializationError &e)
284284
{
285285
errorstream << "Invalid block data in database"
286286
<< " (" << blockpos.X << "," << blockpos.Y << "," << blockpos.Z << ")"

0 commit comments

Comments
 (0)
Please sign in to comment.