|
|
|
creative_regions.astore = AreaStore()
|
|
|
|
creative_regions.mod_storage = minetest.get_mod_storage()
|
|
|
|
|
|
|
|
creative_regions.region_privs = {}
|
|
|
|
|
|
|
|
function creative_regions.load_regions()
|
|
|
|
creative_regions.astore:from_file(minetest.get_worldpath().."/creative_regions_regions")
|
|
|
|
creative_regions.region_privs = minetest.deserialize(creative_regions.mod_storage:get_string("astore_privs")) or {}
|
|
|
|
-- local edge1 = { x=-10, y=-10, z=-10 }
|
|
|
|
-- local edge2 = { x=10, y=10, z=10 }
|
|
|
|
-- local data = "Testregion"
|
|
|
|
-- local astore_id = creative_regions.astore:insert_area(edge1, edge2, tostring(data))
|
|
|
|
--
|
|
|
|
-- creative_regions.set_region_privs("r"..astore_id, "+creative, +fast, +fly")
|
|
|
|
end
|
|
|
|
|
|
|
|
function creative_regions.save_regions()
|
|
|
|
creative_regions.astore:to_file(minetest.get_worldpath().."/creative_regions_regions")
|
|
|
|
local datastr = minetest.serialize(creative_regions.region_privs)
|
|
|
|
if not datastr then
|
|
|
|
minetest.log("error", "[creative_regions] Failed to serialize region_privs data!")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
creative_regions.mod_storage:set_string("astore_privs", datastr)
|
|
|
|
end
|
|
|
|
|
|
|
|
function creative_regions:get_region_size(astore_area)
|
|
|
|
local pos1 = astore_area.min
|
|
|
|
local pos2 = astore_area.max
|
|
|
|
local x = math.abs( pos2.x - pos1.x )
|
|
|
|
local z = math.abs( pos2.z - pos1.x )
|
|
|
|
return x*z
|
|
|
|
end
|
|
|
|
|
|
|
|
function creative_regions.set_region_privs(id, privs_string)
|
|
|
|
creative_regions.region_privs[tostring(id)] = privs_string
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[function creative_regions.add_region_privs(id, privs_string)
|
|
|
|
local region_privs = creative_regions.region_privs[tostring(id)]
|
|
|
|
if not region_privs or region_privs == '' then
|
|
|
|
creative_regions.region_privs[tostring(id)] = privs_string
|
|
|
|
else
|
|
|
|
creative_regions.region_privs[tostring(id)] = region_privs .. ", " .. privs_string
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function creative_regions.strip_region_privs(id, privs_string)
|
|
|
|
local region_privs = creative_regions.region_privs[tostring(id)]
|
|
|
|
if not privs_string then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
local find = privs_string:gsub("[%(%)%.%%%+%-%*%?%[%]%^%$]", "%%%0")
|
|
|
|
local new_region_privs = region_privs:gsub(find..",%s?", "", 1)
|
|
|
|
if new_region_privs == region_privs then
|
|
|
|
new_region_privs = region_privs:gsub(",%s?"..find, "", 1)
|
|
|
|
end
|
|
|
|
if new_region_privs == region_privs then
|
|
|
|
new_region_privs = region_privs:gsub(find, "", 1)
|
|
|
|
end
|
|
|
|
|
|
|
|
if not new_region_privs or new_region_privs == region_privs then
|
|
|
|
return false
|
|
|
|
elseif new_region_privs == "" then
|
|
|
|
creative_regions.region_privs[tostring(id)] = nil
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
creative_regions.region_privs[tostring(id)] = new_region_privs
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end--]]
|
|
|
|
|
|
|
|
function creative_regions:decode_privs_table(privs_table)
|
|
|
|
local privs_grant = {}
|
|
|
|
local privs_revoke = {}
|
|
|
|
|
|
|
|
--table is sorted ascending with priority
|
|
|
|
for _, priv in ipairs(privs_table) do
|
|
|
|
local toggle = string.sub(priv, 1, 1)
|
|
|
|
priv = string.sub(priv, 2)
|
|
|
|
if toggle == '+' then
|
|
|
|
privs_grant[priv] = true
|
|
|
|
privs_revoke[priv] = nil
|
|
|
|
elseif toggle == '-' then
|
|
|
|
privs_revoke[priv] = true
|
|
|
|
privs_grant[priv] = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return privs_grant, privs_revoke
|
|
|
|
end
|
|
|
|
|
|
|
|
function creative_regions:add_privs_from_string(privs_table, str)
|
|
|
|
-- minetest/builtin/common/misc_helpers.lua:core.string_to_privs()
|
|
|
|
assert(type(str) == "string")
|
|
|
|
local delim = ','
|
|
|
|
local privs = {}
|
|
|
|
for _, priv in pairs(string.split(str, delim)) do
|
|
|
|
priv = priv:trim()
|
|
|
|
table.insert(privs_table, priv)
|
|
|
|
end
|
|
|
|
return privs
|
|
|
|
end
|