Skip to content

Commit 7454deb

Browse files
authoredJul 25, 2018
Allow an optional readonly base database (#7544)
* Allow an optional readonly base database * Added basic documentation
1 parent 9537cfd commit 7454deb

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed
 

Diff for: ‎doc/world_format.txt

+9-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,15 @@ See Player File Format below.
9898
world.mt
9999
---------
100100
World metadata.
101-
Example content (added indentation):
102-
gameid = mesetint
101+
Example content (added indentation and - explanations):
102+
gameid = mesetint - name of the game
103+
enable_damage = true - whether damage is enabled or not
104+
creative_mode = false - whether creative mode is enabled or not
105+
backend = sqlite3 - which DB backend to use for blocks (sqlite3, dummy, leveldb, redis, postgresql)
106+
player_backend = sqlite3 - which DB backend to use for player data
107+
readonly_backend = sqlite3 - optionally readonly seed DB (DB file _must_ be located in "readonly" subfolder)
108+
server_announce = false - whether the server is publicly announced or not
109+
load_mod_<mod> = false - whether <mod> is to be loaded in this world
103110

104111
Player File Format
105112
===================

Diff for: ‎src/map.cpp

+13-1
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,10 @@ ServerMap::ServerMap(const std::string &savedir, IGameDef *gamedef,
11591159
}
11601160
std::string backend = conf.get("backend");
11611161
dbase = createDatabase(backend, savedir, conf);
1162-
1162+
if (conf.exists("readonly_backend")) {
1163+
std::string readonly_dir = savedir + DIR_DELIM + "readonly";
1164+
dbase_ro = createDatabase(conf.get("readonly_backend"), readonly_dir, conf);
1165+
}
11631166
if (!conf.updateConfigFile(conf_path.c_str()))
11641167
errorstream << "ServerMap::ServerMap(): Failed to update world.mt!" << std::endl;
11651168

@@ -1230,6 +1233,8 @@ ServerMap::~ServerMap()
12301233
Close database if it was opened
12311234
*/
12321235
delete dbase;
1236+
if (dbase_ro)
1237+
delete dbase_ro;
12331238

12341239
#if 0
12351240
/*
@@ -1869,6 +1874,8 @@ void ServerMap::listAllLoadableBlocks(std::vector<v3s16> &dst)
18691874
<< "all blocks that are stored in flat files." << std::endl;
18701875
}
18711876
dbase->listAllLoadableBlocks(dst);
1877+
if (dbase_ro)
1878+
dbase_ro->listAllLoadableBlocks(dst);
18721879
}
18731880

18741881
void ServerMap::listAllLoadedBlocks(std::vector<v3s16> &dst)
@@ -2107,6 +2114,11 @@ MapBlock* ServerMap::loadBlock(v3s16 blockpos)
21072114
dbase->loadBlock(blockpos, &ret);
21082115
if (!ret.empty()) {
21092116
loadBlock(&ret, blockpos, createSector(p2d), false);
2117+
} else if (dbase_ro) {
2118+
dbase_ro->loadBlock(blockpos, &ret);
2119+
if (!ret.empty()) {
2120+
loadBlock(&ret, blockpos, createSector(p2d), false);
2121+
}
21102122
} else {
21112123
// Not found in database, try the files
21122124

Diff for: ‎src/map.h

+1
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ class ServerMap : public Map
469469
*/
470470
bool m_map_metadata_changed = true;
471471
MapDatabase *dbase = nullptr;
472+
MapDatabase *dbase_ro = nullptr;
472473
};
473474

474475

0 commit comments

Comments
 (0)
Please sign in to comment.