]> git.lizzy.rs Git - minetest.git/commitdiff
Enforce limits of settings that could cause buggy behaviour (#12450)
authorSmallJoker <SmallJoker@users.noreply.github.com>
Sat, 9 Jul 2022 20:32:08 +0000 (22:32 +0200)
committerGitHub <noreply@github.com>
Sat, 9 Jul 2022 20:32:08 +0000 (22:32 +0200)
Enforces the setting value bounds that are currently only limited by the GUI (settingtypes.txt).

28 files changed:
builtin/mainmenu/dlg_contentstore.lua
builtin/settingtypes.txt
src/client/camera.cpp
src/client/client.cpp
src/client/client.h
src/client/clouds.cpp
src/client/fontengine.cpp
src/client/game.cpp
src/client/gameui.cpp
src/client/hud.cpp
src/client/joystick_controller.cpp
src/client/render/stereo.cpp
src/client/renderingengine.cpp
src/client/tile.cpp
src/emerge.cpp
src/gui/guiChatConsole.cpp
src/gui/guiFormSpecMenu.cpp
src/gui/guiTable.cpp
src/gui/modalMenu.cpp
src/gui/touchscreengui.cpp
src/map.cpp
src/map.h
src/mapgen/mapgen.cpp
src/mapgen/mapgen_fractal.cpp
src/nodedef.cpp
src/server.cpp
src/settings.cpp
src/settings.h

index 11eaceac3fdb1e8814596873ac9a52585894ef11..2152b8a3947a45dff240efad0cd41f6b58d17639 100644 (file)
@@ -191,7 +191,7 @@ end
 
 local function queue_download(package, reason)
        local max_concurrent_downloads = tonumber(core.settings:get("contentdb_max_concurrent_downloads"))
-       if number_downloading < max_concurrent_downloads then
+       if number_downloading < math.max(max_concurrent_downloads, 1) then
                start_install(package, reason)
        else
                table.insert(download_queue, { package = package, reason = reason })
index 10438fe218ec91dfa6b5258d229f9d32df7c1d6e..caa6e4db3c1800d1c27ab287a0423e7d88c0f259 100644 (file)
@@ -95,7 +95,7 @@ always_fly_fast (Always fly fast) bool true
 
 #    The time in seconds it takes between repeated node placements when holding
 #    the place button.
-repeat_place_time (Place repetition interval) float 0.25 0.001
+repeat_place_time (Place repetition interval) float 0.25 0.25 2
 
 #    Automatically jump up single-node obstacles.
 autojump (Automatic jumping) bool false
@@ -223,7 +223,7 @@ view_bobbing_amount (View bobbing factor) float 1.0 0.0 7.9
 
 #    Multiplier for fall bobbing.
 #    For example: 0 for no view bobbing; 1.0 for normal; 2.0 for double.
-fall_bobbing_amount (Fall bobbing factor) float 0.03 0.0
+fall_bobbing_amount (Fall bobbing factor) float 0.03 0.0 100.0
 
 [**Camera]
 
@@ -1877,7 +1877,7 @@ server_side_occlusion_culling (Server side occlusion culling) bool true
 #    Reducing this value increases cave and dungeon density.
 #    Altering this value is for special usage, leaving it unchanged is
 #    recommended.
-chunksize (Chunk size) int 5 1 5
+chunksize (Chunk size) int 5 1 10
 
 #    Dump the mapgen debug information.
 enable_mapgen_debug_info (Mapgen debug) bool false
@@ -1926,7 +1926,7 @@ curl_file_download_timeout (cURL file download timeout) int 300000 100 214748364
 screen_dpi (DPI) int 72 1
 
 #    Adjust the detected display density, used for scaling UI elements.
-display_density_factor (Display Density Scaling Factor) float 1
+display_density_factor (Display Density Scaling Factor) float 1 0.5 5.0
 
 #    Windows systems only: Start Minetest with the command line window in the background.
 #    Contains the same information as the file debug.txt (default name).
index 7cc9cb6e8cdc31ae19fecdc2ce92fb5f227a8bec..df75c52d63488a47780958862797c890b7067e93 100644 (file)
@@ -75,11 +75,11 @@ Camera::Camera(MapDrawControl &draw_control, Client *client, RenderingEngine *re
         *       (as opposed to the this local caching). This can be addressed in
         *       a later release.
         */
-       m_cache_fall_bobbing_amount = g_settings->getFloat("fall_bobbing_amount");
-       m_cache_view_bobbing_amount = g_settings->getFloat("view_bobbing_amount");
+       m_cache_fall_bobbing_amount = g_settings->getFloat("fall_bobbing_amount", 0.0f, 100.0f);
+       m_cache_view_bobbing_amount = g_settings->getFloat("view_bobbing_amount", 0.0f, 7.9f);
        // 45 degrees is the lowest FOV that doesn't cause the server to treat this
        // as a zoom FOV and load world beyond the set server limits.
-       m_cache_fov                 = std::fmax(g_settings->getFloat("fov"), 45.0f);
+       m_cache_fov                 = g_settings->getFloat("fov", 45.0f, 160.0f);
        m_arm_inertia               = g_settings->getBool("arm_inertia");
        m_nametags.clear();
        m_show_nametag_backgrounds  = g_settings->getBool("show_nametag_backgrounds");
index 37d4bd816b82284d03c932bd6527aa1646c482e1..0f82970809dd8138b62283e66df1721a18aaee9b 100644 (file)
@@ -118,6 +118,7 @@ Client::Client(
        m_particle_manager(&m_env),
        m_con(new con::Connection(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, ipv6, this)),
        m_address_name(address_name),
+       m_allow_login_or_register(allow_login_or_register),
        m_server_ser_ver(SER_FMT_VER_INVALID),
        m_last_chat_message_sent(time(NULL)),
        m_password(password),
@@ -125,8 +126,7 @@ Client::Client(
        m_media_downloader(new ClientMediaDownloader()),
        m_state(LC_Created),
        m_game_ui(game_ui),
-       m_modchannel_mgr(new ModChannelMgr()),
-       m_allow_login_or_register(allow_login_or_register)
+       m_modchannel_mgr(new ModChannelMgr())
 {
        // Add local player
        m_env.setLocalPlayer(new LocalPlayer(this, playername));
@@ -424,7 +424,7 @@ void Client::step(float dtime)
        if(m_map_timer_and_unload_interval.step(dtime, map_timer_and_unload_dtime)) {
                std::vector<v3s16> deleted_blocks;
                m_env.getMap().timerUpdate(map_timer_and_unload_dtime,
-                       g_settings->getFloat("client_unload_unused_data_timeout"),
+                       std::max(g_settings->getFloat("client_unload_unused_data_timeout"), 0.0f),
                        g_settings->getS32("client_mapblock_limit"),
                        &deleted_blocks);
 
@@ -1254,7 +1254,7 @@ void Client::sendChatMessage(const std::wstring &message)
                pkt << message;
 
                Send(&pkt);
-       } else if (m_out_chat_queue.size() < (u16) max_queue_size || max_queue_size == -1) {
+       } else if (m_out_chat_queue.size() < (u16) max_queue_size || max_queue_size < 0) {
                m_out_chat_queue.push(message);
        } else {
                infostream << "Could not queue chat message because maximum out chat queue size ("
index f01510ddb8f185f1bee2dcaaf2652b05737def84..bdcc2a3dda0bce9a80b837344250ca4c30243509 100644 (file)
@@ -349,7 +349,6 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
        u16 getProtoVersion()
        { return m_proto_ver; }
 
-       ELoginRegister m_allow_login_or_register = ELoginRegister::Any;
        bool m_simple_singleplayer_mode;
 
        float mediaReceiveProgress();
@@ -492,6 +491,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
        ParticleManager m_particle_manager;
        std::unique_ptr<con::Connection> m_con;
        std::string m_address_name;
+       ELoginRegister m_allow_login_or_register = ELoginRegister::Any;
        Camera *m_camera = nullptr;
        Minimap *m_minimap = nullptr;
        bool m_minimap_disabled_by_server = false;
index 383a1d799e963f2afec9396f059bc11617bf9144..c84c03034e12fd2cd737521b31bd4f1d96be6d66 100644 (file)
@@ -366,7 +366,8 @@ void Clouds::update(const v3f &camera_p, const video::SColorf &color_diffuse)
 
 void Clouds::readSettings()
 {
-       m_cloud_radius_i = g_settings->getU16("cloud_radius");
+       // Upper limit was chosen due to posible render bugs
+       m_cloud_radius_i = rangelim(g_settings->getU16("cloud_radius"), 1, 62);
        m_enable_3d = g_settings->getBool("enable_3d_clouds");
 }
 
index ad8305b4583e9d7a39c1649f8103bec08b4bd4be..0ae50dfe2f1d4924eefa371146ea1172f499c4fc 100644 (file)
@@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "filesys.h"
 #include "gettext.h"
 #include "irrlicht_changes/CGUITTFont.h"
+#include "util/numeric.h" // rangelim
 
 /** maximum size distance for getting a "similar" font size */
 #define MAX_FONT_SIZE_OFFSET 10
@@ -172,9 +173,9 @@ unsigned int FontEngine::getFontSize(FontMode mode)
 /******************************************************************************/
 void FontEngine::readSettings()
 {
-       m_default_size[FM_Standard]  = g_settings->getU16("font_size");
-       m_default_size[_FM_Fallback] = g_settings->getU16("font_size");
-       m_default_size[FM_Mono]      = g_settings->getU16("mono_font_size");
+       m_default_size[FM_Standard]  = rangelim(g_settings->getU16("font_size"), 5, 72);
+       m_default_size[_FM_Fallback] = m_default_size[FM_Standard];
+       m_default_size[FM_Mono]      = rangelim(g_settings->getU16("mono_font_size"), 5, 72);
 
        m_default_bold = g_settings->getBool("font_bold");
        m_default_italic = g_settings->getBool("font_italic");
@@ -217,8 +218,9 @@ gui::IGUIFont *FontEngine::initFont(const FontSpec &spec)
        if (spec.italic)
                setting_suffix.append("_italic");
 
-       u32 size = std::max<u32>(spec.size * RenderingEngine::getDisplayDensity() *
-                       g_settings->getFloat("gui_scaling"), 1);
+       // Font size in pixels for FreeType
+       u32 size = rangelim(spec.size * RenderingEngine::getDisplayDensity() *
+                       g_settings->getFloat("gui_scaling"), 1U, 500U);
 
        // Constrain the font size to a certain multiple, if necessary
        u16 divisible_by = g_settings->getU16(setting_prefix + "font_size_divisible_by");
index e6308c3b63399ce3f45fc09ce36436e481c6aa5f..e838b337ac50b91ba9f83b84aa6a74ccb651c1ac 100644 (file)
@@ -1932,7 +1932,7 @@ void Game::processKeyInput()
                }
        } else if (wasKeyDown(KeyType::INC_VOLUME)) {
                if (g_settings->getBool("enable_sound")) {
-                       float new_volume = rangelim(g_settings->getFloat("sound_volume") + 0.1f, 0.0f, 1.0f);
+                       float new_volume = g_settings->getFloat("sound_volume", 0.0f, 0.9f) + 0.1f;
                        g_settings->setFloat("sound_volume", new_volume);
                        std::wstring msg = fwgettext("Volume changed to %d%%", myround(new_volume * 100));
                        m_game_ui->showStatusText(msg);
@@ -1941,7 +1941,7 @@ void Game::processKeyInput()
                }
        } else if (wasKeyDown(KeyType::DEC_VOLUME)) {
                if (g_settings->getBool("enable_sound")) {
-                       float new_volume = rangelim(g_settings->getFloat("sound_volume") - 0.1f, 0.0f, 1.0f);
+                       float new_volume = g_settings->getFloat("sound_volume", 0.1f, 1.0f) - 0.1f;
                        g_settings->setFloat("sound_volume", new_volume);
                        std::wstring msg = fwgettext("Volume changed to %d%%", myround(new_volume * 100));
                        m_game_ui->showStatusText(msg);
@@ -4082,10 +4082,10 @@ void FpsControl::reset()
  */
 void FpsControl::limit(IrrlichtDevice *device, f32 *dtime)
 {
-       const u64 frametime_min = 1000000.0f / (
-               device->isWindowFocused() && !g_menumgr.pausesGame()
+       const float fps_limit = (device->isWindowFocused() && !g_menumgr.pausesGame())
                        ? g_settings->getFloat("fps_max")
-                       : g_settings->getFloat("fps_max_unfocused"));
+                       : g_settings->getFloat("fps_max_unfocused");
+       const u64 frametime_min = 1000000.0f / std::max(fps_limit, 1.0f);
 
        u64 time = porting::getTimeUs();
 
@@ -4134,9 +4134,9 @@ void Game::readSettings()
        m_cache_enable_joysticks             = g_settings->getBool("enable_joysticks");
        m_cache_enable_particles             = g_settings->getBool("enable_particles");
        m_cache_enable_fog                   = g_settings->getBool("enable_fog");
-       m_cache_mouse_sensitivity            = g_settings->getFloat("mouse_sensitivity");
-       m_cache_joystick_frustum_sensitivity = g_settings->getFloat("joystick_frustum_sensitivity");
-       m_repeat_place_time                  = g_settings->getFloat("repeat_place_time");
+       m_cache_mouse_sensitivity            = g_settings->getFloat("mouse_sensitivity", 0.001f, 10.0f);
+       m_cache_joystick_frustum_sensitivity = std::max(g_settings->getFloat("joystick_frustum_sensitivity"), 0.001f);
+       m_repeat_place_time                  = g_settings->getFloat("repeat_place_time", 0.25f, 2.0);
 
        m_cache_enable_noclip                = g_settings->getBool("noclip");
        m_cache_enable_free_move             = g_settings->getBool("free_move");
index 01c733b4f412f678f4aa70153c984d44d5c42a35..909719bbe3a2682068a9232c94ac19f9d37f0cfa 100644 (file)
@@ -68,7 +68,7 @@ void GameUI::init()
        u16 chat_font_size = g_settings->getU16("chat_font_size");
        if (chat_font_size != 0) {
                m_guitext_chat->setOverrideFont(g_fontengine->getFont(
-                       chat_font_size, FM_Unspecified));
+                       rangelim(chat_font_size, 5, 72), FM_Unspecified));
        }
 
 
index 01f4d6ff3bfdb1b832406fabbae2d7939be88b49..c05ce76e86ff33adc8604b8e4c70c512c4e78a4a 100644 (file)
@@ -55,7 +55,7 @@ Hud::Hud(Client *client, LocalPlayer *player,
        this->player      = player;
        this->inventory   = inventory;
 
-       m_hud_scaling      = g_settings->getFloat("hud_scaling");
+       m_hud_scaling      = g_settings->getFloat("hud_scaling", 1.0f, 20.0f);
        m_scale_factor     = m_hud_scaling * RenderingEngine::getDisplayDensity();
        m_hotbar_imagesize = std::floor(HOTBAR_IMAGE_SIZE *
                RenderingEngine::getDisplayDensity() + 0.5f);
index aae73c62d205c783c5e4d038709e331bf2eefdb0..9e58b9f624a273a3f5eabc53f1f87ca0d619ab31 100644 (file)
@@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "gettime.h"
 #include "porting.h"
 #include "util/string.h"
+#include "util/numeric.h"
 
 bool JoystickButtonCmb::isTriggered(const irr::SEvent::SJoystickEvent &ev) const
 {
@@ -202,9 +203,9 @@ JoystickLayout create_dragonrise_gamecube_layout()
 }
 
 
-JoystickController::JoystickController() :
-               doubling_dtime(g_settings->getFloat("repeat_joystick_button_time"))
+JoystickController::JoystickController()
 {
+       doubling_dtime = std::max(g_settings->getFloat("repeat_joystick_button_time"), 0.001f);
        for (float &i : m_past_pressed_time) {
                i = 0;
        }
@@ -217,19 +218,20 @@ void JoystickController::onJoystickConnect(const std::vector<irr::SJoystickInfo>
        s32         id     = g_settings->getS32("joystick_id");
        std::string layout = g_settings->get("joystick_type");
 
-       if (id < 0 || (u16)id >= joystick_infos.size()) {
+       if (id < 0 || id >= (s32)joystick_infos.size()) {
                // TODO: auto detection
                id = 0;
        }
 
-       if (id >= 0 && (u16)id < joystick_infos.size()) {
+       if (id >= 0 && id < (s32)joystick_infos.size()) {
                if (layout.empty() || layout == "auto")
                        setLayoutFromControllerName(joystick_infos[id].Name.c_str());
                else
                        setLayoutFromControllerName(layout);
        }
 
-       m_joystick_id = id;
+       // Irrlicht restriction.
+       m_joystick_id = rangelim(id, 0, UINT8_MAX);
 }
 
 void JoystickController::setLayoutFromControllerName(const std::string &name)
index 967b5a78f57132ee969589c361b943cbcd0f54f0..0f54e166e941879a7b8b973110cd0a587f4d9a8b 100644 (file)
@@ -27,7 +27,7 @@ RenderingCoreStereo::RenderingCoreStereo(
        IrrlichtDevice *_device, Client *_client, Hud *_hud)
        : RenderingCore(_device, _client, _hud)
 {
-       eye_offset = BS * g_settings->getFloat("3d_paralax_strength");
+       eye_offset = BS * g_settings->getFloat("3d_paralax_strength", -0.087f, 0.087f);
 }
 
 void RenderingCoreStereo::beforeDraw()
index 7afca45004882363b86e7404c334760dc154c67d..ea2dbfa80bf307912e9408b28b3efa0d4f3e0bdd 100644 (file)
@@ -86,8 +86,8 @@ RenderingEngine::RenderingEngine(IEventReceiver *receiver)
 
        // Resolution selection
        bool fullscreen = g_settings->getBool("fullscreen");
-       u16 screen_w = g_settings->getU16("screen_w");
-       u16 screen_h = g_settings->getU16("screen_h");
+       u16 screen_w = std::max<u16>(g_settings->getU16("screen_w"), 1);
+       u16 screen_h = std::max<u16>(g_settings->getU16("screen_h"), 1);
 
        // bpp, fsaa, vsync
        bool vsync = g_settings->getBool("vsync");
@@ -598,7 +598,7 @@ static float calcDisplayDensity()
 float RenderingEngine::getDisplayDensity()
 {
        static float cached_display_density = calcDisplayDensity();
-       return cached_display_density * g_settings->getFloat("display_density_factor");
+       return std::max(cached_display_density * g_settings->getFloat("display_density_factor"), 0.5f);
 }
 
 #elif defined(_WIN32)
@@ -626,14 +626,15 @@ float RenderingEngine::getDisplayDensity()
                display_density = calcDisplayDensity(get_video_driver());
                cached = true;
        }
-       return display_density * g_settings->getFloat("display_density_factor");
+       return std::max(display_density * g_settings->getFloat("display_density_factor"), 0.5f);
 }
 
 #else
 
 float RenderingEngine::getDisplayDensity()
 {
-       return (g_settings->getFloat("screen_dpi") / 96.0) * g_settings->getFloat("display_density_factor");
+       return std::max(g_settings->getFloat("screen_dpi") / 96.0f *
+               g_settings->getFloat("display_density_factor"), 0.5f);
 }
 
 #endif
index aa78c50f01d412cadb8007acd76a5322a78355e0..87d2818b41836ca203619558de1fcbac11e4854e 100644 (file)
@@ -1619,7 +1619,7 @@ bool TextureSource::generateImagePart(std::string part_of_name,
                         * textures that don't have the resources to offer high-res alternatives.
                         */
                        const bool filter = m_setting_trilinear_filter || m_setting_bilinear_filter;
-                       const s32 scaleto = filter ? g_settings->getS32("texture_min_size") : 1;
+                       const s32 scaleto = filter ? g_settings->getU16("texture_min_size") : 1;
                        if (scaleto > 1) {
                                const core::dimension2d<u32> dim = baseimg->getDimension();
 
index 5c1569f047814a16990e9e6a98ea496c6ae8db23..e36d364480ba531cfce58ccc6ae4b9e5465c7c20 100644 (file)
@@ -173,7 +173,7 @@ EmergeManager::EmergeManager(Server *server, MetricsBackend *mb)
        g_settings->getS16NoEx("num_emerge_threads", nthreads);
        // If automatic, leave a proc for the main thread and one for
        // some other misc thread
-       if (nthreads == 0)
+       if (nthreads <= 0)
                nthreads = Thread::getNumberOfProcessors() - 2;
        if (nthreads < 1)
                nthreads = 1;
index 01e10ea2ea213df4236730b1f2c6da1792d5e9e4..280f7e45b668e6c0f72b3bef63e1edb14118fd97 100644 (file)
@@ -76,9 +76,9 @@ GUIChatConsole::GUIChatConsole(
                m_background_color.setBlue(clamp_u8(myround(console_color.Z)));
        }
 
-       u16 chat_font_size = g_settings->getU16("chat_font_size");
+       const u16 chat_font_size = g_settings->getU16("chat_font_size");
        m_font = g_fontengine->getFont(chat_font_size != 0 ?
-               chat_font_size : FONT_SIZE_UNSPECIFIED, FM_Mono);
+               rangelim(chat_font_size, 5, 72) : FONT_SIZE_UNSPECIFIED, FM_Mono);
 
        if (!m_font) {
                errorstream << "GUIChatConsole: Unable to load mono font" << std::endl;
index e01a5347afc34af2ee0bc66b143d09efee71f0b2..e4ea9ff58c37fd4d34d212118336cd531db62812 100644 (file)
@@ -3212,8 +3212,8 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
                        offset = v2s32(0,0);
                }
 
-               double gui_scaling = g_settings->getFloat("gui_scaling");
-               double screen_dpi = RenderingEngine::getDisplayDensity() * 96;
+               const double gui_scaling = g_settings->getFloat("gui_scaling", 0.5f, 42.0f);
+               const double screen_dpi = RenderingEngine::getDisplayDensity() * 96;
 
                double use_imgsize;
                if (m_lock) {
index 79ae1aea31525f9af2b3a08a35e0db4da0e947cf..3929d678b35da8c0439079bd495bbed9969d3168 100644 (file)
@@ -84,7 +84,7 @@ GUITable::GUITable(gui::IGUIEnvironment *env,
 #endif
        core::rect<s32> relative_rect = m_scrollbar->getRelativePosition();
        s32 width = (relative_rect.getWidth() / (2.0 / 3.0)) * density *
-                       g_settings->getFloat("gui_scaling");
+                       g_settings->getFloat("gui_scaling", 0.5f, 20.0f);
        m_scrollbar->setRelativePosition(core::rect<s32>(
                        relative_rect.LowerRightCorner.X-width,relative_rect.UpperLeftCorner.Y,
                        relative_rect.LowerRightCorner.X,relative_rect.LowerRightCorner.Y
index 172eb11e6d18ddc07964953e59588f8e9538a690..cfc4d5c5a18ade8792b5fcb12eff57467038215d 100644 (file)
@@ -40,7 +40,7 @@ GUIModalMenu::GUIModalMenu(gui::IGUIEnvironment* env, gui::IGUIElement* parent,
                m_menumgr(menumgr),
                m_remap_dbl_click(remap_dbl_click)
 {
-       m_gui_scale = g_settings->getFloat("gui_scaling");
+       m_gui_scale = std::max(g_settings->getFloat("gui_scaling"), 0.5f);
 #ifdef HAVE_TOUCHSCREENGUI
        float d = RenderingEngine::getDisplayDensity();
        m_gui_scale *= 1.1 - 0.3 * d + 0.2 * d * d;
index ebe1a632520ab6b6edf5cf4f9cb3762f0eb36230..d483c136e56a11e80827f2ed3b4739da34125750 100644 (file)
@@ -843,7 +843,7 @@ void TouchScreenGUI::translateEvent(const SEvent &event)
                                        s32 dy = Y - m_pointerpos[event.TouchInput.ID].Y;
 
                                        // adapt to similar behaviour as pc screen
-                                       double d = g_settings->getFloat("mouse_sensitivity") * 3.0f;
+                                       const double d = g_settings->getFloat("mouse_sensitivity", 0.001f, 10.0f) * 3.0f;
 
                                        m_camera_yaw_change -= dx * d;
                                        m_camera_pitch = MYMIN(MYMAX(m_camera_pitch + (dy * d), -180), 180);
index 213844d5759e3a4e731553ad0ffe411bd8247ef7..a53680065d0557d86a476a1122d983a0949a8cd6 100644 (file)
@@ -323,7 +323,7 @@ struct TimeOrderedMapBlock {
 /*
        Updates usage timers
 */
-void Map::timerUpdate(float dtime, float unload_timeout, u32 max_loaded_blocks,
+void Map::timerUpdate(float dtime, float unload_timeout, s32 max_loaded_blocks,
                std::vector<v3s16> *unloaded_blocks)
 {
        bool save_before_unloading = maySaveBlocks();
@@ -340,7 +340,7 @@ void Map::timerUpdate(float dtime, float unload_timeout, u32 max_loaded_blocks,
        beginSave();
 
        // If there is no practical limit, we spare creation of mapblock_queue
-       if (max_loaded_blocks == U32_MAX) {
+       if (max_loaded_blocks < 0) {
                for (auto &sector_it : m_sectors) {
                        MapSector *sector = sector_it.second;
 
@@ -399,7 +399,7 @@ void Map::timerUpdate(float dtime, float unload_timeout, u32 max_loaded_blocks,
                block_count_all = mapblock_queue.size();
 
                // Delete old blocks, and blocks over the limit from the memory
-               while (!mapblock_queue.empty() && (mapblock_queue.size() > max_loaded_blocks
+               while (!mapblock_queue.empty() && ((s32)mapblock_queue.size() > max_loaded_blocks
                                || mapblock_queue.top().block->getUsageTimer() > unload_timeout)) {
                        TimeOrderedMapBlock b = mapblock_queue.top();
                        mapblock_queue.pop();
index 9317642150e2fcf3c0a712baf2569ef821e21b8d..6bc2aaaee9527bb068b6de762a0cac8716aa09c0 100644 (file)
--- a/src/map.h
+++ b/src/map.h
@@ -205,7 +205,7 @@ class Map /*: public NodeContainer*/
                Updates usage timers and unloads unused blocks and sectors.
                Saves modified blocks before unloading if possible.
        */
-       void timerUpdate(float dtime, float unload_timeout, u32 max_loaded_blocks,
+       void timerUpdate(float dtime, float unload_timeout, s32 max_loaded_blocks,
                        std::vector<v3s16> *unloaded_blocks=NULL);
 
        /*
index cca036b7bd6ce8bd7369e78848bc9263dc13e730..99db5042638905c6a5dd274676ed94b82201eaac 100644 (file)
@@ -1038,6 +1038,8 @@ void MapgenParams::readParams(const Settings *settings)
        settings->getS16NoEx("chunksize", chunksize);
        settings->getFlagStrNoEx("mg_flags", flags, flagdesc_mapgen);
 
+       chunksize = rangelim(chunksize, 1, 10);
+
        delete bparams;
        bparams = BiomeManager::createBiomeParams(BIOMEGEN_ORIGINAL);
        if (bparams) {
index fabb1b2b197d7eb37b3022014fc7ecb6c21c247a..c9071cecf0628c59a71fdbcafac8704aa6f7a788 100644 (file)
@@ -131,6 +131,7 @@ void MapgenFractalParams::readParams(const Settings *settings)
        settings->getNoiseParams("mgfractal_np_cave1",        np_cave1);
        settings->getNoiseParams("mgfractal_np_cave2",        np_cave2);
        settings->getNoiseParams("mgfractal_np_dungeons",     np_dungeons);
+       iterations = std::max<u16>(iterations, 1);
 }
 
 
index a2af7e0569866bd37d630f6dad978cd3b18d7098..4022ac8350760032658a88d250d05eb48166c2fb 100644 (file)
@@ -279,7 +279,7 @@ void TextureSettings::readSettings()
        bool smooth_lighting           = g_settings->getBool("smooth_lighting");
        enable_mesh_cache              = g_settings->getBool("enable_mesh_cache");
        enable_minimap                 = g_settings->getBool("enable_minimap");
-       node_texture_size              = g_settings->getU16("texture_min_size");
+       node_texture_size              = std::min<u16>(g_settings->getU16("texture_min_size"), 1);
        std::string leaves_style_str   = g_settings->get("leaves_style");
        std::string world_aligned_mode_str = g_settings->get("world_aligned_mode");
        std::string autoscale_mode_str = g_settings->get("autoscale_mode");
index d94271143546119a02645dbc2f5c154f1b9dc603..24e3526584bf3f810323ac5aa5cea57e3420778a 100644 (file)
@@ -646,8 +646,8 @@ void Server::AsyncRunStep(bool initial_step)
                // Run Map's timers and unload unused data
                ScopeProfiler sp(g_profiler, "Server: map timer and unload");
                m_env->getMap().timerUpdate(map_timer_and_unload_dtime,
-                       g_settings->getFloat("server_unload_unused_data_timeout"),
-                       U32_MAX);
+                       std::max(g_settings->getFloat("server_unload_unused_data_timeout"), 0.0f),
+                       -1);
        }
 
        /*
index 0e44ee0bcb6c9adbc7915d228843a8c5fd85298d..a0225bc2cc835de3379bc7dfc22ee3b1645e0c76 100644 (file)
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "irrlichttypes_bloated.h"
 #include "exceptions.h"
 #include "threading/mutex_auto_lock.h"
+#include "util/numeric.h" // rangelim
 #include "util/strfnd.h"
 #include <iostream>
 #include <fstream>
@@ -534,6 +535,13 @@ float Settings::getFloat(const std::string &name) const
 }
 
 
+float Settings::getFloat(const std::string &name, float min, float max) const
+{
+       float val = stof(get(name));
+       return rangelim(val, min, max);
+}
+
+
 u64 Settings::getU64(const std::string &name) const
 {
        std::string s = get(name);
index 767d057f9c1b77eb4b11e7fe4095121a32eb0aa3..4b0787343a60446a6750d74d55c40db5f5bd6512 100644 (file)
@@ -164,6 +164,7 @@ class Settings {
        s32 getS32(const std::string &name) const;
        u64 getU64(const std::string &name) const;
        float getFloat(const std::string &name) const;
+       float getFloat(const std::string &name, float min, float max) const;
        v2f getV2F(const std::string &name) const;
        v3f getV3F(const std::string &name) const;
        u32 getFlagStr(const std::string &name, const FlagDesc *flagdesc,