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
This commit is contained in:
Loïc Blot 2019-01-04 12:55:07 +01:00 committed by GitHub
parent 4a7c97c5f6
commit 022b1eca0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -396,36 +396,62 @@ ServerEnvironment::ServerEnvironment(ServerMap *map,
// Determine which database backend to use // Determine which database backend to use
std::string conf_path = path_world + DIR_DELIM + "world.mt"; std::string conf_path = path_world + DIR_DELIM + "world.mt";
Settings conf; Settings conf;
std::string player_backend_name = "sqlite3";
std::string auth_backend_name = "sqlite3";
bool succeeded = conf.readConfigFile(conf_path.c_str()); bool succeeded = conf.readConfigFile(conf_path.c_str());
if (!succeeded || !conf.exists("player_backend")) {
// fall back to files // If we open world.mt read the backend configurations.
conf.set("player_backend", "files"); if (succeeded) {
// Read those values before setting defaults
bool player_backend_exists = conf.exists("player_backend");
bool auth_backend_exists = conf.exists("auth_backend");
// player backend is not set, assume it's legacy file backend.
if (!player_backend_exists) {
// fall back to files
conf.set("player_backend", "files");
player_backend_name = "files";
if (!conf.updateConfigFile(conf_path.c_str())) {
errorstream << "ServerEnvironment::ServerEnvironment(): "
<< "Failed to update world.mt!" << std::endl;
}
} else {
conf.getNoEx("player_backend", player_backend_name);
}
// auth backend is not set, assume it's legacy file backend.
if (!auth_backend_exists) {
conf.set("auth_backend", "files");
auth_backend_name = "files";
if (!conf.updateConfigFile(conf_path.c_str())) {
errorstream << "ServerEnvironment::ServerEnvironment(): "
<< "Failed to update world.mt!" << std::endl;
}
} else {
conf.getNoEx("auth_backend", auth_backend_name);
}
}
if (player_backend_name == "files") {
warningstream << "/!\\ You are using old player file backend. " warningstream << "/!\\ You are using old player file backend. "
<< "This backend is deprecated and will be removed in next release /!\\" << "This backend is deprecated and will be removed in a future release /!\\"
<< std::endl << "Switching to SQLite3 or PostgreSQL is advised, " << std::endl << "Switching to SQLite3 or PostgreSQL is advised, "
<< "please read http://wiki.minetest.net/Database_backends." << std::endl; << "please read http://wiki.minetest.net/Database_backends." << std::endl;
if (!conf.updateConfigFile(conf_path.c_str())) {
errorstream << "ServerEnvironment::ServerEnvironment(): "
<< "Failed to update world.mt!" << std::endl;
}
} }
std::string name; if (auth_backend_name == "files") {
conf.getNoEx("player_backend", name); warningstream << "/!\\ You are using old auth file backend. "
m_player_database = openPlayerDatabase(name, path_world, conf); << "This backend is deprecated and will be removed in a future release /!\\"
<< std::endl << "Switching to SQLite3 is advised, "
std::string auth_name = "files"; << "please read http://wiki.minetest.net/Database_backends." << std::endl;
if (conf.exists("auth_backend")) {
conf.getNoEx("auth_backend", auth_name);
} else {
conf.set("auth_backend", "files");
if (!conf.updateConfigFile(conf_path.c_str())) {
errorstream << "ServerEnvironment::ServerEnvironment(): "
<< "Failed to update world.mt!" << std::endl;
}
} }
m_auth_database = openAuthDatabase(auth_name, path_world, conf);
m_player_database = openPlayerDatabase(player_backend_name, path_world, conf);
m_auth_database = openAuthDatabase(auth_backend_name, path_world, conf);
} }
ServerEnvironment::~ServerEnvironment() ServerEnvironment::~ServerEnvironment()