std::string Settings::get(const std::string &name) const { const SettingsEntry &entry = getEntry(name); if (entry.is_group) throw SettingNotFoundException("Setting [" + name + "] is a group."); return entry.value; }
Settings *Settings::getGroup(const std::string &name) const { const SettingsEntry &entry = getEntry(name); if (!entry.is_group) throw SettingNotFoundException("Setting [" + name + "] is not a group."); return entry.group; }
const SettingsEntry &Settings::getEntry(const std::string &name) const { MutexAutoLock lock(m_mutex); std::map<std::string, SettingsEntry>::const_iterator n; if ((n = m_settings.find(name)) == m_settings.end()) { if ((n = m_defaults.find(name)) == m_defaults.end()) throw SettingNotFoundException("Setting [" + name + "] not found."); } return n->second; }
Database_PostgreSQL::Database_PostgreSQL(const std::string &connect_string) : m_connect_string(connect_string) { if (m_connect_string.empty()) { throw SettingNotFoundException( "Set pgsql_connection string in world.mt to " "use the postgresql backend\n" "Notes:\n" "pgsql_connection has the following form: \n" "\tpgsql_connection = host=127.0.0.1 port=5432 user=mt_user " "password=mt_password dbname=minetest_world\n" "mt_user should have CREATE TABLE, INSERT, SELECT, UPDATE and " "DELETE rights on the database.\n" "Don't create mt_user as a SUPERUSER!"); } }
Database_Redis::Database_Redis(Settings &conf) { std::string tmp; try { tmp = conf.get("redis_address"); hash = conf.get("redis_hash"); } catch (SettingNotFoundException) { throw SettingNotFoundException("Set redis_address and " "redis_hash in world.mt to use the redis backend"); } const char *addr = tmp.c_str(); int port = conf.exists("redis_port") ? conf.getU16("redis_port") : 6379; ctx = redisConnect(addr, port); if (!ctx) { throw FileNotGoodException("Cannot allocate redis context"); } else if (ctx->err) { std::string err = std::string("Connection error: ") + ctx->errstr; redisFree(ctx); throw FileNotGoodException(err); } }
Database_Redis::Database_Redis(ServerMap *map, std::string savedir) { Settings conf; conf.readConfigFile((std::string(savedir) + DIR_DELIM + "world.mt").c_str()); std::string tmp; try { tmp = conf.get("redis_address"); hash = conf.get("redis_hash"); } catch(SettingNotFoundException e) { throw SettingNotFoundException("Set redis_address and redis_hash in world.mt to use the redis backend"); } const char *addr = tmp.c_str(); int port = conf.exists("redis_port") ? conf.getU16("redis_port") : 6379; ctx = redisConnect(addr, port); if(!ctx) throw FileNotGoodException("Cannot allocate redis context"); else if(ctx->err) { std::string err = std::string("Connection error: ") + ctx->errstr; redisFree(ctx); throw FileNotGoodException(err); } srvmap = map; }