Add validation to map detection, to fix some issues

This commit is contained in:
AKryukov92 2018-11-17 01:52:02 +06:00 committed by rubenwardy
parent 696a44d3d9
commit e6e9760320

View file

@ -49,9 +49,20 @@ local function search_for_maps()
local dirs = minetest.get_dir_list(mapdir, true) local dirs = minetest.get_dir_list(mapdir, true)
table.insert(dirs, ".") table.insert(dirs, ".")
for _, dir in pairs(dirs) do for _, dir in pairs(dirs) do
if dir ~= ".git" then
local files = minetest.get_dir_list(mapdir .. dir, false) local files = minetest.get_dir_list(mapdir .. dir, false)
for i=1, #files do for i=1, #files do
files_hash[dir .. "/" .. files[i]:split(".")[1]] = true 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
end end
@ -59,6 +70,9 @@ local function search_for_maps()
for key, _ in pairs(files_hash) do for key, _ in pairs(files_hash) do
table.insert(ctf_map.available_maps, key) table.insert(ctf_map.available_maps, key)
end end
if next(ctf_map.available_maps) == nil then
error("No maps found in directory " .. mapdir)
end
return ctf_map.available_maps return ctf_map.available_maps
end end
print(dump(search_for_maps())) print(dump(search_for_maps()))
@ -112,7 +126,12 @@ end
function ctf_match.load_map_meta(idx, name) function ctf_match.load_map_meta(idx, name)
local offset = vector.new(600 * idx, 0, 0) 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 initial_stuff = meta:get("initial_stuff")
local map = { local map = {