Remove blank default values for emergequeue_limit_* settings
authorkwolekr <kwolekr@minetest.net>
Wed, 5 Feb 2014 05:17:53 +0000 (00:17 -0500)
committerkwolekr <kwolekr@minetest.net>
Wed, 5 Feb 2014 05:17:53 +0000 (00:17 -0500)
Add checks for invalid user input for important settings
Rename Settings::tryGet* to Settings::get*NoEx for consistency

src/defaultsettings.cpp
src/emerge.cpp
src/mapgen_indev.cpp
src/mapgen_v6.cpp
src/mapgen_v7.cpp
src/settings.h

index cb7b0ef7a27bdf78a87784188d9e67790ab4b3ef..bac5e0e2d91a1bfddb0723989065d22784f50c1b 100644 (file)
@@ -219,8 +219,6 @@ void set_default_settings(Settings *settings)
        settings->setDefault("remote_media", "");
        settings->setDefault("debug_log_level", "2");
        settings->setDefault("emergequeue_limit_total", "256");
-       settings->setDefault("emergequeue_limit_diskonly", "");
-       settings->setDefault("emergequeue_limit_generate", "");
        settings->setDefault("num_emerge_threads", "1");
        
        // physics stuff
index 42e5337596f9b3dc20974e988e5df823df1e43d9..88bb3a1e65d78fa9fef4cfb3db79e8b23068b17d 100644 (file)
@@ -102,17 +102,25 @@ EmergeManager::EmergeManager(IGameDef *gamedef) {
        // if unspecified, leave a proc for the main thread and one for
        // some other misc thread
        int nthreads = 0;
-       if (!g_settings->tryGetS16("num_emerge_threads", nthreads))
+       if (!g_settings->getS16NoEx("num_emerge_threads", nthreads))
                nthreads = porting::getNumberOfProcessors() - 2;
        if (nthreads < 1)
                nthreads = 1;
 
        qlimit_total = g_settings->getU16("emergequeue_limit_total");
-       if (!g_settings->tryGetU16("emergequeue_limit_diskonly", qlimit_diskonly))
+       if (!g_settings->getU16NoEx("emergequeue_limit_diskonly", qlimit_diskonly))
                qlimit_diskonly = nthreads * 5 + 1;
-       if (!g_settings->tryGetU16("emergequeue_limit_generate", qlimit_generate))
+       if (!g_settings->getU16NoEx("emergequeue_limit_generate", qlimit_generate))
                qlimit_generate = nthreads + 1;
 
+       // don't trust user input for something very important like this
+       if (qlimit_total < 1)
+               qlimit_total = 1;
+       if (qlimit_diskonly < 1)
+               qlimit_diskonly = 1;
+       if (qlimit_generate < 1)
+               qlimit_generate = 1;
+
        for (int i = 0; i != nthreads; i++)
                emergethread.push_back(new EmergeThread((Server *)gamedef, i));
 
@@ -352,13 +360,13 @@ void EmergeManager::loadParamsFromSettings(Settings *settings) {
        std::string seed_str;
        const char *setname = (settings == g_settings) ? "fixed_map_seed" : "seed";
 
-       if (settings->tryGet(setname, seed_str))
+       if (settings->getNoEx(setname, seed_str))
                params.seed = read_seed(seed_str.c_str());
 
-       settings->tryGet("mg_name",         params.mg_name);
-       settings->tryGetS16("water_level",  params.water_level);
-       settings->tryGetS16("chunksize",    params.chunksize);
-       settings->tryGetFlagStr("mg_flags", params.flags, flagdesc_mapgen);
+       settings->getNoEx("mg_name",         params.mg_name);
+       settings->getS16NoEx("water_level",  params.water_level);
+       settings->getS16NoEx("chunksize",    params.chunksize);
+       settings->getFlagStrNoEx("mg_flags", params.flags, flagdesc_mapgen);
 
        delete params.sparams;
        params.sparams = createMapgenParams(params.mg_name);
index 67535b0b464606a1d9d0182ba1351cac25f1423e..ac5b4e811599004bda56b3e592eee8fdc6ef67ae 100644 (file)
@@ -164,7 +164,7 @@ MapgenIndevParams::MapgenIndevParams() {
 void MapgenIndevParams::readParams(Settings *settings) {
        MapgenV6Params::readParams(settings);
 
-       settings->tryGetS16("mgindev_float_islands", float_islands);
+       settings->getS16NoEx("mgindev_float_islands", float_islands);
 
        settings->getNoiseIndevParams("mgindev_np_terrain_base",   npindev_terrain_base);
        settings->getNoiseIndevParams("mgindev_np_terrain_higher", npindev_terrain_higher);
index 526d4af2e52b4bd658130930ebb5a1ecf9271ca3..92ae7dff0cca7a8884a3a812746deb503202d606 100644 (file)
@@ -112,9 +112,9 @@ MapgenV6Params::MapgenV6Params() {
 
 
 void MapgenV6Params::readParams(Settings *settings) {
-       settings->tryGetFlagStr("mgv6_spflags", spflags, flagdesc_mapgen_v6);
-       settings->tryGetFloat("mgv6_freq_desert", freq_desert);
-       settings->tryGetFloat("mgv6_freq_beach",  freq_beach);
+       settings->getFlagStrNoEx("mgv6_spflags", spflags, flagdesc_mapgen_v6);
+       settings->getFloatNoEx("mgv6_freq_desert", freq_desert);
+       settings->getFloatNoEx("mgv6_freq_beach",  freq_beach);
 
        settings->getNoiseParams("mgv6_np_terrain_base",   np_terrain_base);
        settings->getNoiseParams("mgv6_np_terrain_higher", np_terrain_higher);
index 77e25a6723a5ae41cf361bb4625fb1b0806c8ea8..8359151648e2a9332f5a288a88e939c8291950e3 100644 (file)
@@ -126,7 +126,7 @@ MapgenV7Params::MapgenV7Params() {
 
 
 void MapgenV7Params::readParams(Settings *settings) {
-       settings->tryGetFlagStr("mgv7_spflags", spflags, flagdesc_mapgen_v7);
+       settings->getFlagStrNoEx("mgv7_spflags", spflags, flagdesc_mapgen_v7);
 
        settings->getNoiseParams("mgv7_np_terrain_base",    np_terrain_base);
        settings->getNoiseParams("mgv7_np_terrain_alt",     np_terrain_alt);
index f019ce50c8e2c1ca93f0b233c22ef248fc721b2b..cf698b0eb99690d8a366a9259dc19c6bc08d25aa 100644 (file)
@@ -745,7 +745,7 @@ fail:
        }
 
        //////////// Try to get value, no exception thrown
-       bool tryGet(std::string name, std::string &val)
+       bool getNoEx(std::string name, std::string &val)
        {
                try {
                        val = get(name);
@@ -755,7 +755,7 @@ fail:
                }
        }
 
-       bool tryGetFlagStr(std::string name, u32 &val, FlagDesc *flagdesc)
+       bool getFlagStrNoEx(std::string name, u32 &val, FlagDesc *flagdesc)
        {
                try {
                        val = getFlagStr(name, flagdesc);
@@ -765,7 +765,7 @@ fail:
                }
        }
 
-       bool tryGetFloat(std::string name, float &val)
+       bool getFloatNoEx(std::string name, float &val)
        {
                try {
                        val = getFloat(name);
@@ -775,7 +775,7 @@ fail:
                }
        }
 
-       bool tryGetU16(std::string name, int &val)
+       bool getU16NoEx(std::string name, int &val)
        {
                try {
                        val = getU16(name);
@@ -785,7 +785,7 @@ fail:
                }
        }
 
-       bool tryGetU16(std::string name, u16 &val)
+       bool getU16NoEx(std::string name, u16 &val)
        {
                try {
                        val = getU16(name);
@@ -795,7 +795,7 @@ fail:
                }
        }
 
-       bool tryGetS16(std::string name, int &val)
+       bool getS16NoEx(std::string name, int &val)
        {
                try {
                        val = getU16(name);
@@ -805,7 +805,7 @@ fail:
                }
        }
 
-       bool tryGetS16(std::string name, s16 &val)
+       bool getS16NoEx(std::string name, s16 &val)
        {
                try {
                        val = getS16(name);
@@ -815,7 +815,7 @@ fail:
                }
        }
 
-       bool tryGetS32(std::string name, s32 &val)
+       bool getS32NoEx(std::string name, s32 &val)
        {
                try {
                        val = getS32(name);
@@ -825,7 +825,7 @@ fail:
                }
        }
 
-       bool tryGetV3F(std::string name, v3f &val)
+       bool getV3FNoEx(std::string name, v3f &val)
        {
                try {
                        val = getV3F(name);
@@ -835,7 +835,7 @@ fail:
                }
        }
 
-       bool tryGetV2F(std::string name, v2f &val)
+       bool getV2FNoEx(std::string name, v2f &val)
        {
                try {
                        val = getV2F(name);
@@ -845,7 +845,7 @@ fail:
                }
        }
 
-       bool tryGetU64(std::string name, u64 &val)
+       bool getU64NoEx(std::string name, u64 &val)
        {
                try {
                        val = getU64(name);