]> git.lizzy.rs Git - minetest.git/blobdiff - builtin/mainmenu/common.lua
Fix ContentDB packages timing out by using download_file instead (#7891)
[minetest.git] / builtin / mainmenu / common.lua
index 5e3df086467f64ff4badf375964fab9e7d37f4b7..cc61fe0adfc1e68c40d13f2132d1be015ee3ccfd 100644 (file)
@@ -41,12 +41,12 @@ local function render_client_count(n)
 end
 
 local function configure_selected_world_params(idx)
-       local worldconfig = modmgr.get_worldconfig(menudata.worldlist:get_list()[idx].path)
+       local worldconfig = pkgmgr.get_worldconfig(menudata.worldlist:get_list()[idx].path)
        if worldconfig.creative_mode then
-               core.setting_set("creative_mode", worldconfig.creative_mode)
+               core.settings:set("creative_mode", worldconfig.creative_mode)
        end
        if worldconfig.enable_damage then
-               core.setting_set("enable_damage", worldconfig.enable_damage)
+               core.settings:set("enable_damage", worldconfig.enable_damage)
        end
 end
 
@@ -54,7 +54,12 @@ end
 function image_column(tooltip, flagname)
        return "image,tooltip=" .. core.formspec_escape(tooltip) .. "," ..
                "0=" .. core.formspec_escape(defaulttexturedir .. "blank.png") .. "," ..
-               "1=" .. core.formspec_escape(defaulttexturedir .. "server_flags_" .. flagname .. ".png")
+               "1=" .. core.formspec_escape(defaulttexturedir ..
+                       (flagname and "server_flags_" .. flagname .. ".png" or "blank.png")) .. "," ..
+               "2=" .. core.formspec_escape(defaulttexturedir .. "server_ping_4.png") .. "," ..
+               "3=" .. core.formspec_escape(defaulttexturedir .. "server_ping_3.png") .. "," ..
+               "4=" .. core.formspec_escape(defaulttexturedir .. "server_ping_2.png") .. "," ..
+               "5=" .. core.formspec_escape(defaulttexturedir .. "server_ping_1.png")
 end
 
 --------------------------------------------------------------------------------
@@ -97,6 +102,21 @@ function render_serverlist_row(spec, is_favorite)
                details = "0,"
        end
 
+       if spec.ping then
+               local ping = spec.ping * 1000
+               if ping <= 50 then
+                       details = details .. "2,"
+               elseif ping <= 100 then
+                       details = details .. "3,"
+               elseif ping <= 250 then
+                       details = details .. "4,"
+               else
+                       details = details .. "5,"
+               end
+       else
+               details = details .. "0,"
+       end
+
        if spec.clients and spec.clients_max then
                local clients_color = ''
                local clients_percent = 100 * spec.clients / spec.clients_max
@@ -144,22 +164,34 @@ end
 
 --------------------------------------------------------------------------------
 os.tempfolder = function()
-       if core.setting_get("TMPFolder") then
-               return core.setting_get("TMPFolder") .. DIR_DELIM .. "MT_" .. math.random(0,10000)
+       if core.settings:get("TMPFolder") then
+               return core.settings:get("TMPFolder") .. DIR_DELIM .. "MT_" .. math.random(0,10000)
        end
 
        local filetocheck = os.tmpname()
        os.remove(filetocheck)
 
-       local randname = "MTTempModFolder_" .. math.random(0,10000)
-       if DIR_DELIM == "\\" then
+       -- https://blogs.msdn.microsoft.com/vcblog/2014/06/18/c-runtime-crt-features-fixes-and-breaking-changes-in-visual-studio-14-ctp1/
+       --   The C runtime (CRT) function called by os.tmpname is tmpnam.
+       --   Microsofts tmpnam implementation in older CRT / MSVC releases is defective.
+       --   tmpnam return values starting with a backslash characterize this behavior.
+       -- https://sourceforge.net/p/mingw-w64/bugs/555/
+       --   MinGW tmpnam implementation is forwarded to the CRT directly.
+       -- https://sourceforge.net/p/mingw-w64/discussion/723797/thread/55520785/
+       --   MinGW links to an older CRT release (msvcrt.dll).
+       --   Due to legal concerns MinGW will never use a newer CRT.
+       --
+       --   Make use of TEMP to compose the temporary filename if an old
+       --   style tmpnam return value is detected.
+       if filetocheck:sub(1, 1) == "\\" then
                local tempfolder = os.getenv("TEMP")
                return tempfolder .. filetocheck
-       else
-               local backstring = filetocheck:reverse()
-               return filetocheck:sub(0,filetocheck:len()-backstring:find(DIR_DELIM)+1) ..randname
        end
 
+       local randname = "MTTempModFolder_" .. math.random(0,10000)
+       local backstring = filetocheck:reverse()
+       return filetocheck:sub(0, filetocheck:len() - backstring:find(DIR_DELIM) + 1) ..
+               randname
 end
 
 --------------------------------------------------------------------------------
@@ -186,7 +218,7 @@ function menu_handle_key_up_down(fields, textlist, settingname)
                                oldidx < menudata.worldlist:size() then
                        newidx = oldidx + 1
                end
-               core.setting_set(settingname, menudata.worldlist:get_raw_index(newidx))
+               core.settings:set(settingname, menudata.worldlist:get_raw_index(newidx))
                configure_selected_world_params(newidx)
                return true
        end
@@ -230,7 +262,7 @@ end
 
 --------------------------------------------------------------------------------
 function text2textlist(xpos, ypos, width, height, tl_name, textlen, text, transparency)
-       local textlines = core.splittext(text, textlen)
+       local textlines = core.wrap_text(text, textlen, true)
        local retval = "textlist[" .. xpos .. "," .. ypos .. ";" .. width ..
                        "," .. height .. ";" .. tl_name .. ";"
 
@@ -308,9 +340,9 @@ function menu_worldmt_legacy(selected)
        for _, mode_name in pairs(modes_names) do
                local mode_val = menu_worldmt(selected, mode_name)
                if mode_val then
-                       core.setting_set(mode_name, mode_val)
+                       core.settings:set(mode_name, mode_val)
                else
-                       menu_worldmt(selected, mode_name, core.setting_get(mode_name))
+                       menu_worldmt(selected, mode_name, core.settings:get(mode_name))
                end
        end
 end