aboutsummaryrefslogtreecommitdiff
path: root/builtin/mainmenu
ModeNameSize
-rw-r--r--common.lua10289logplain
-rw-r--r--dlg_config_world.lua8540logplain
-rw-r--r--dlg_create_world.lua4275logplain
-rw-r--r--dlg_delete_mod.lua2328logplain
-rw-r--r--dlg_delete_world.lua1962logplain
-rw-r--r--dlg_rename_modpack.lua2349logplain
-rw-r--r--gamemgr.lua2560logplain
-rw-r--r--init.lua4976logplain
-rw-r--r--init_simple.lua161logplain
-rw-r--r--modmgr.lua12886logplain
-rw-r--r--store.lua18052logplain
-rw-r--r--tab_credits.lua3513logplain
-rw-r--r--tab_mods.lua5359logplain
-rw-r--r--tab_multiplayer.lua8128logplain
-rw-r--r--tab_server.lua6550logplain
-rw-r--r--tab_settings.lua21971logplain
-rw-r--r--tab_simple_main.lua6362logplain
-rw-r--r--tab_singleplayer.lua7478logplain
-rw-r--r--tab_texturepacks.lua4236logplain
-rw-r--r--textures.lua4997logplain
n class="hl opt">] if not is_server_protocol_compat(fav.proto_min, fav.proto_max) then res[#res + 1] = fav end end return res end local public_downloading = false -------------------------------------------------------------------------------- function serverlistmgr.sync() if not serverlistmgr.servers then serverlistmgr.servers = {{ name = fgettext("Loading..."), description = fgettext_ne("Try reenabling public serverlist and check your internet connection.") }} end if public_downloading then return end public_downloading = true core.handle_async( function(param) local http = core.get_http_api() local url = ("%s/list?proto_version_min=%d&proto_version_max=%d"):format( core.settings:get("serverlist_url"), core.get_min_supp_proto(), core.get_max_supp_proto()) local response = http.fetch_sync({ url = url }) if not response.succeeded then return {} end local retval = core.parse_json(response.data) return retval and retval.list or {} end, nil, function(result) public_downloading = nil local favs = order_server_list(result) if favs[1] then serverlistmgr.servers = favs end core.event_handler("Refresh") end ) end -------------------------------------------------------------------------------- local function get_favorites_path() local base = core.get_user_path() .. DIR_DELIM .. "client" .. DIR_DELIM .. "serverlist" .. DIR_DELIM return base .. core.settings:get("serverlist_file") end -------------------------------------------------------------------------------- local function save_favorites(favorites) local filename = core.settings:get("serverlist_file") -- If setting specifies legacy format change the filename to the new one if filename:sub(#filename - 3):lower() == ".txt" then core.settings:set("serverlist_file", filename:sub(1, #filename - 4) .. ".json") end local path = get_favorites_path() core.create_dir(path) core.safe_file_write(path, core.write_json(favorites)) end -------------------------------------------------------------------------------- function serverlistmgr.read_legacy_favorites(path) local file = io.open(path, "r") if not file then return nil end local lines = {} for line in file:lines() do lines[#lines + 1] = line end file:close() local favorites = {} local i = 1 while i < #lines do local function pop() local line = lines[i] i = i + 1 return line and line:trim() end if pop():lower() == "[server]" then local name = pop() local address = pop() local port = tonumber(pop()) local description = pop() if name == "" then name = nil end if description == "" then description = nil end if not address or #address < 3 then core.log("warning", "Malformed favorites file, missing address at line " .. i) elseif not port or port < 1 or port > 65535 then core.log("warning", "Malformed favorites file, missing port at line " .. i) elseif (name and name:upper() == "[SERVER]") or (address and address:upper() == "[SERVER]") or (description and description:upper() == "[SERVER]") then core.log("warning", "Potentially malformed favorites file, overran at line " .. i) else favorites[#favorites + 1] = { name = name, address = address, port = port, description = description } end end end return favorites end -------------------------------------------------------------------------------- local function read_favorites() local path = get_favorites_path() -- If new format configured fall back to reading the legacy file if path:sub(#path - 4):lower() == ".json" then