Skip to content

Commit 022b1ec

Browse files
authoredJan 4, 2019
Make sqlite3 default auth & player backends for new worlds (#8043)
* Make sqlite3 default auth & player backends for new worlds Also notify about auth backend depreciation
1 parent 4a7c97c commit 022b1ec

File tree

1 file changed

+49
-23
lines changed

1 file changed

+49
-23
lines changed
 

‎src/serverenvironment.cpp

+49-23
Original file line numberDiff line numberDiff line change
@@ -396,36 +396,62 @@ ServerEnvironment::ServerEnvironment(ServerMap *map,
396396
// Determine which database backend to use
397397
std::string conf_path = path_world + DIR_DELIM + "world.mt";
398398
Settings conf;
399+
400+
std::string player_backend_name = "sqlite3";
401+
std::string auth_backend_name = "sqlite3";
402+
399403
bool succeeded = conf.readConfigFile(conf_path.c_str());
400-
if (!succeeded || !conf.exists("player_backend")) {
401-
// fall back to files
402-
conf.set("player_backend", "files");
403-
warningstream << "/!\\ You are using old player file backend. "
404-
<< "This backend is deprecated and will be removed in next release /!\\"
405-
<< std::endl << "Switching to SQLite3 or PostgreSQL is advised, "
406-
<< "please read http://wiki.minetest.net/Database_backends." << std::endl;
407404

408-
if (!conf.updateConfigFile(conf_path.c_str())) {
409-
errorstream << "ServerEnvironment::ServerEnvironment(): "
410-
<< "Failed to update world.mt!" << std::endl;
405+
// If we open world.mt read the backend configurations.
406+
if (succeeded) {
407+
// Read those values before setting defaults
408+
bool player_backend_exists = conf.exists("player_backend");
409+
bool auth_backend_exists = conf.exists("auth_backend");
410+
411+
// player backend is not set, assume it's legacy file backend.
412+
if (!player_backend_exists) {
413+
// fall back to files
414+
conf.set("player_backend", "files");
415+
player_backend_name = "files";
416+
417+
if (!conf.updateConfigFile(conf_path.c_str())) {
418+
errorstream << "ServerEnvironment::ServerEnvironment(): "
419+
<< "Failed to update world.mt!" << std::endl;
420+
}
421+
} else {
422+
conf.getNoEx("player_backend", player_backend_name);
411423
}
412-
}
413424

414-
std::string name;
415-
conf.getNoEx("player_backend", name);
416-
m_player_database = openPlayerDatabase(name, path_world, conf);
425+
// auth backend is not set, assume it's legacy file backend.
426+
if (!auth_backend_exists) {
427+
conf.set("auth_backend", "files");
428+
auth_backend_name = "files";
417429

418-
std::string auth_name = "files";
419-
if (conf.exists("auth_backend")) {
420-
conf.getNoEx("auth_backend", auth_name);
421-
} else {
422-
conf.set("auth_backend", "files");
423-
if (!conf.updateConfigFile(conf_path.c_str())) {
424-
errorstream << "ServerEnvironment::ServerEnvironment(): "
425-
<< "Failed to update world.mt!" << std::endl;
430+
if (!conf.updateConfigFile(conf_path.c_str())) {
431+
errorstream << "ServerEnvironment::ServerEnvironment(): "
432+
<< "Failed to update world.mt!" << std::endl;
433+
}
434+
} else {
435+
conf.getNoEx("auth_backend", auth_backend_name);
426436
}
427437
}
428-
m_auth_database = openAuthDatabase(auth_name, path_world, conf);
438+
439+
if (player_backend_name == "files") {
440+
warningstream << "/!\\ You are using old player file backend. "
441+
<< "This backend is deprecated and will be removed in a future release /!\\"
442+
<< std::endl << "Switching to SQLite3 or PostgreSQL is advised, "
443+
<< "please read http://wiki.minetest.net/Database_backends." << std::endl;
444+
}
445+
446+
if (auth_backend_name == "files") {
447+
warningstream << "/!\\ You are using old auth file backend. "
448+
<< "This backend is deprecated and will be removed in a future release /!\\"
449+
<< std::endl << "Switching to SQLite3 is advised, "
450+
<< "please read http://wiki.minetest.net/Database_backends." << std::endl;
451+
}
452+
453+
m_player_database = openPlayerDatabase(player_backend_name, path_world, conf);
454+
m_auth_database = openAuthDatabase(auth_backend_name, path_world, conf);
429455
}
430456

431457
ServerEnvironment::~ServerEnvironment()

0 commit comments

Comments
 (0)
Please sign in to comment.