From e6e976032019769df988b72a532224ed96b79eee Mon Sep 17 00:00:00 2001 From: AKryukov92 Date: Sat, 17 Nov 2018 01:52:02 +0600 Subject: [PATCH] Add validation to map detection, to fix some issues --- mods/ctf_map/schem_map.lua | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/mods/ctf_map/schem_map.lua b/mods/ctf_map/schem_map.lua index bec445a..bcc0c46 100644 --- a/mods/ctf_map/schem_map.lua +++ b/mods/ctf_map/schem_map.lua @@ -49,9 +49,20 @@ local function search_for_maps() local dirs = minetest.get_dir_list(mapdir, true) table.insert(dirs, ".") for _, dir in pairs(dirs) do - local files = minetest.get_dir_list(mapdir .. dir, false) - for i=1, #files do - files_hash[dir .. "/" .. files[i]:split(".")[1]] = true + if dir ~= ".git" then + local files = minetest.get_dir_list(mapdir .. dir, false) + for i=1, #files do + local parts = files[i]:split(".") + local filename = parts[1] + local extension = parts[2] + if extension == "mts" then + files_hash[dir .. "/" .. filename] = true + else + if extension ~= "conf" and extension ~= "md" then + error("Map extension is not '.mts': " .. files[i]) + end + end + end end end @@ -59,6 +70,9 @@ local function search_for_maps() for key, _ in pairs(files_hash) do table.insert(ctf_map.available_maps, key) end + if next(ctf_map.available_maps) == nil then + error("No maps found in directory " .. mapdir) + end return ctf_map.available_maps end print(dump(search_for_maps())) @@ -112,7 +126,12 @@ end function ctf_match.load_map_meta(idx, name) local offset = vector.new(600 * idx, 0, 0) - local meta = Settings(mapdir .. name .. ".conf") + local conf_path = mapdir .. name .. ".conf" + local meta = Settings(conf_path) + + if meta:get("r") == nil then + error("Map was not properly configured " .. conf_path) + end local initial_stuff = meta:get("initial_stuff") local map = {