|
|
@ -5,60 +5,60 @@ creative_regions = {} |
|
|
|
local mod_storage = minetest.get_mod_storage() |
|
|
|
creative_regions.astore = AreaStore() |
|
|
|
|
|
|
|
creative_regions.area_privs = {} |
|
|
|
creative_regions.region_privs = {} |
|
|
|
|
|
|
|
areas_owner_privs = minetest.settings:get("creative_regions.owner_privs") or "+creative, +fast, +fly" |
|
|
|
areas_guest_privs = minetest.settings:get("creative_regions.guest_privs") or "-fly, -fast" |
|
|
|
noarea_privs = minetest.settings:get("creative_regions.noarea_privs") or "-creative, +fast, -fly" |
|
|
|
noregion_privs = minetest.settings:get("creative_regions.noregion_privs") or "-creative, +fast, -fly" |
|
|
|
default_privs = minetest.settings:get("creative_regions.default_privs") or "+creative, +fast, +fly" |
|
|
|
|
|
|
|
function creative_regions:load_areas() |
|
|
|
self.astore:from_file(minetest.get_worldpath().."/creative_regions_areas") |
|
|
|
creative_regions.area_privs = minetest.deserialize(mod_storage:get_string("astore_privs")) or {} |
|
|
|
function creative_regions:load_regions() |
|
|
|
self.astore:from_file(minetest.get_worldpath().."/creative_regions_regions") |
|
|
|
creative_regions.region_privs = minetest.deserialize(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 = "Testarea" |
|
|
|
-- local data = "Testregion" |
|
|
|
-- local astore_id = self.astore:insert_area(edge1, edge2, tostring(data)) |
|
|
|
-- |
|
|
|
-- creative_regions:set_area_privs(astore_id, "+creative, +fast, +fly") |
|
|
|
-- creative_regions:set_region_privs(astore_id, "+creative, +fast, +fly") |
|
|
|
end |
|
|
|
|
|
|
|
function creative_regions:save_areas() |
|
|
|
self.astore:to_file(minetest.get_worldpath().."/creative_regions_areas") |
|
|
|
local datastr = minetest.serialize(creative_regions.area_privs) |
|
|
|
function creative_regions:save_regions() |
|
|
|
self.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 area_privs data!") |
|
|
|
minetest.log("error", "[creative_regions] Failed to serialize region_privs data!") |
|
|
|
return |
|
|
|
end |
|
|
|
mod_storage:set_string("astore_privs", datastr) |
|
|
|
end |
|
|
|
|
|
|
|
function creative_regions:set_area_privs(id, privs_string) |
|
|
|
creative_regions.area_privs[tostring(id)] = privs_string |
|
|
|
function creative_regions:set_region_privs(id, privs_string) |
|
|
|
creative_regions.region_privs[tostring(id)] = privs_string |
|
|
|
end |
|
|
|
|
|
|
|
minetest.register_chatcommand("creative_area", { |
|
|
|
minetest.register_chatcommand("creative_region", { |
|
|
|
params = "<x> <y> <z>, <x> <y> <z>, <text>", |
|
|
|
description = "Set a creative_regions area from a to b", |
|
|
|
description = "Set a creative region from a to b", |
|
|
|
privs = {server = true}, |
|
|
|
func = function(name, param) |
|
|
|
local player = minetest.get_player_by_name(name) |
|
|
|
if not player then |
|
|
|
return false, "Player not found" |
|
|
|
end |
|
|
|
local found, _, x1, y1, z1, x2, y2, z2, area_name = param:find("^([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)%s*,%s*([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)%s*,%s*(.+)$") |
|
|
|
local found, _, x1, y1, z1, x2, y2, z2, region_name = param:find("^([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)%s*,%s*([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)%s*,%s*(.+)$") |
|
|
|
if not found then |
|
|
|
return false, "Syntax error" |
|
|
|
end |
|
|
|
|
|
|
|
local edge1 = { x=tonumber(x1), y=tonumber(y1), z=tonumber(z1) } |
|
|
|
local edge2 = { x=tonumber(x2), y=tonumber(y2), z=tonumber(z2) } |
|
|
|
local data = area_name |
|
|
|
local data = region_name |
|
|
|
local astore_id = creative_regions.astore:insert_area(edge1, edge2, tostring(data)) |
|
|
|
if astore_id then |
|
|
|
creative_regions:set_area_privs(tostring(astore_id), nil) |
|
|
|
minetest.chat_send_player(name, "[creative_area] New area set. ID: " .. astore_id) |
|
|
|
creative_regions:save_areas() |
|
|
|
creative_regions:set_region_privs(tostring(astore_id), nil) |
|
|
|
minetest.chat_send_player(name, "[creative_regions] New region set. ID: " .. astore_id) |
|
|
|
creative_regions:save_regions() |
|
|
|
return true, "Done" |
|
|
|
else |
|
|
|
return false, "Failed" |
|
|
@ -66,23 +66,23 @@ minetest.register_chatcommand("creative_area", { |
|
|
|
end, |
|
|
|
}) |
|
|
|
|
|
|
|
minetest.register_chatcommand("creative_area_privs", { |
|
|
|
minetest.register_chatcommand("creative_region_privs", { |
|
|
|
params = "<id>, <text>", |
|
|
|
description = "Set privstring for creative_regions area", |
|
|
|
description = "Set privstring for creative region", |
|
|
|
privs = {server = true}, |
|
|
|
func = function(name, param) |
|
|
|
local player = minetest.get_player_by_name(name) |
|
|
|
if not player then |
|
|
|
return false, "Player not found" |
|
|
|
end |
|
|
|
local found, _, area_id, privstring = param:find("^([+-]?%a?%d+)%s*,%s*(.+)$") |
|
|
|
local found, _, region_id, privstring = param:find("^([+-]?%a?%d+)%s*,%s*(.+)$") |
|
|
|
if not found then |
|
|
|
return false, "Syntax error" |
|
|
|
end |
|
|
|
if privstring and area_id then |
|
|
|
creative_regions:set_area_privs(tostring(area_id), privstring) |
|
|
|
minetest.chat_send_player(name, "[creative_area] Privstring set for area " .. area_id .. ": " .. privstring) |
|
|
|
creative_regions:save_areas() |
|
|
|
if privstring and region_id then |
|
|
|
creative_regions:set_region_privs(tostring(region_id), privstring) |
|
|
|
minetest.chat_send_player(name, "[creative_regions] Privstring set for region " .. region_id .. ": " .. privstring) |
|
|
|
creative_regions:save_regions() |
|
|
|
return true, "Done" |
|
|
|
else |
|
|
|
return false, "Failed" |
|
|
@ -90,27 +90,27 @@ minetest.register_chatcommand("creative_area_privs", { |
|
|
|
end, |
|
|
|
}) |
|
|
|
|
|
|
|
minetest.register_chatcommand("creative_area_rm", { |
|
|
|
minetest.register_chatcommand("creative_region_rm", { |
|
|
|
params = "<id>", |
|
|
|
description = "Remove a creative_regions area", |
|
|
|
description = "Remove a creative region", |
|
|
|
privs = {server = true}, |
|
|
|
func = function(name, param) |
|
|
|
local player = minetest.get_player_by_name(name) |
|
|
|
if not player then |
|
|
|
return false, "Player not found" |
|
|
|
end |
|
|
|
local found, _, area_id = param:find("^([+-]?%d+)%s*$") |
|
|
|
local found, _, region_id = param:find("^([+-]?%d+)%s*$") |
|
|
|
if not found then |
|
|
|
return false, "Syntax error" |
|
|
|
end |
|
|
|
local success = creative_regions.astore:remove_area(tonumber(area_id)) |
|
|
|
local success = creative_regions.astore:remove_area(tonumber(region_id)) |
|
|
|
if success then |
|
|
|
minetest.chat_send_player(name, "[creative_area] Area " .. area_id .. "removed") |
|
|
|
creative_regions:set_area_privs(tostring(area_id), nil) |
|
|
|
minetest.chat_send_player(name, "[creative_regions] Region " .. region_id .. "removed") |
|
|
|
creative_regions:set_region_privs(tostring(region_id), nil) |
|
|
|
else |
|
|
|
minetest.chat_send_player(name, "[creative_area] Error removing area " .. area_id) |
|
|
|
minetest.chat_send_player(name, "[creative_regions] Error removing region " .. region_id) |
|
|
|
end |
|
|
|
creative_regions:save_areas() |
|
|
|
creative_regions:save_regions() |
|
|
|
return true, "Done." |
|
|
|
end, |
|
|
|
}) |
|
|
@ -147,7 +147,7 @@ function creative_regions:is_areas_mod(area_id) |
|
|
|
return is_areas_id, a_id |
|
|
|
end |
|
|
|
|
|
|
|
function creative_regions:get_area_size(astore_area) |
|
|
|
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 ) |
|
|
@ -220,7 +220,7 @@ function creative_regions:restore_player_inventory(player, listname) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
function creative_regions:player_enter_area(player, privstring) |
|
|
|
function creative_regions:player_enter_region(player, privstring) |
|
|
|
local name = player:get_player_name() |
|
|
|
local has_creative = minetest.check_player_privs(name, {creative=true}) |
|
|
|
|
|
|
@ -256,32 +256,31 @@ function creative_regions:update_player(player) |
|
|
|
local pos = vector.round(player:get_pos()) |
|
|
|
|
|
|
|
local pmeta = player:get_meta() |
|
|
|
-- pmeta:mark_as_private("creative_regions.active_areas") |
|
|
|
local player_last_active_areas = pmeta:get_string("creative_regions.active_areas") or "-1" |
|
|
|
local player_active_areas = "-1" |
|
|
|
-- pmeta:mark_as_private("creative_regions.active_regions") |
|
|
|
local player_last_active_regions = pmeta:get_string("creative_regions.active_regions") or "-1" |
|
|
|
local player_active_regions = "-1" |
|
|
|
local areas_owner = false |
|
|
|
local areas_guest = false |
|
|
|
local areas_open = false |
|
|
|
local new_area = nil |
|
|
|
local smallest_area = {} |
|
|
|
local smallest_region = {} |
|
|
|
local smallest_areas_area = {} |
|
|
|
|
|
|
|
if minetest.check_player_privs(name, { protection_bypass=true }) then |
|
|
|
--minetest.chat_send_player(name, "Changed area. You have protection_bypass priv") |
|
|
|
--minetest.chat_send_player(name, "Changed region. You have protection_bypass priv") |
|
|
|
return |
|
|
|
end |
|
|
|
|
|
|
|
-- enter area |
|
|
|
local current_areas = self.astore:get_areas_for_pos(pos, true, true) |
|
|
|
-- enter region |
|
|
|
local current_regions = self.astore:get_areas_for_pos(pos, true, true) |
|
|
|
for astore_id, astore_area in pairs( current_areas ) do |
|
|
|
local areasize = creative_regions:get_area_size(astore_area) |
|
|
|
if not smallest_area.size or areasize < smallest_area.size then |
|
|
|
smallest_area.id = tostring(astore_id) |
|
|
|
smallest_area.size = areasize |
|
|
|
local regionsize = creative_regions:get_region_size(astore_area) |
|
|
|
if not smallest_region.size or regionsize < smallest_region.size then |
|
|
|
smallest_region.id = tostring(astore_id) |
|
|
|
smallest_region.size = regionsize |
|
|
|
end |
|
|
|
end |
|
|
|
if smallest_area.id then |
|
|
|
player_active_areas = tostring(smallest_area.id) |
|
|
|
if smallest_region.id then |
|
|
|
player_active_regions = tostring(smallest_region.id) |
|
|
|
end |
|
|
|
|
|
|
|
-- enter areas mod area |
|
|
@ -308,10 +307,10 @@ function creative_regions:update_player(player) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
local privstring = noarea_privs |
|
|
|
if smallest_area.id then |
|
|
|
if creative_regions.area_privs[tostring(smallest_area.id)] then |
|
|
|
privstring = creative_regions.area_privs[tostring(smallest_area.id)] |
|
|
|
local privstring = noregion_privs |
|
|
|
if smallest_region.id then |
|
|
|
if creative_regions.region_privs[tostring(smallest_region.id)] then |
|
|
|
privstring = creative_regions.region_privs[tostring(smallest_region.id)] |
|
|
|
else |
|
|
|
privstring = default_privs |
|
|
|
end |
|
|
@ -320,30 +319,30 @@ function creative_regions:update_player(player) |
|
|
|
privstring = privstring .. ", " .. areas_owner_privs |
|
|
|
elseif areas_guest then |
|
|
|
privstring = privstring .. ", " .. areas_guest_privs |
|
|
|
for _, a in pairs(string.split(player_active_areas, ",")) do |
|
|
|
for _, a in pairs(string.split(player_active_regions, ",")) do |
|
|
|
a = a:trim() |
|
|
|
if string.sub(a, 1, 1) == "a" then |
|
|
|
if creative_regions.area_privs[a] then |
|
|
|
privstring = privstring .. ", " .. creative_regions.area_privs[a] |
|
|
|
if creative_regions.region_privs[a] then |
|
|
|
privstring = privstring .. ", " .. creative_regions.region_privs[a] |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
if smallest_areas_area.size and smallest_area.size then |
|
|
|
if smallest_area.size <= smallest_areas_area.size then |
|
|
|
privstring = privstring .. ", " .. creative_regions.area_privs[tostring(smallest_area.id)] |
|
|
|
if smallest_areas_area.size and smallest_region.size then |
|
|
|
if smallest_region.size <= smallest_areas_area.size then |
|
|
|
privstring = privstring .. ", " .. creative_regions.region_privs[tostring(smallest_region.id)] |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
if player_active_areas ~= player_last_active_areas then |
|
|
|
creative_regions:player_enter_area(player, privstring) |
|
|
|
pmeta:set_string("creative_regions.active_areas", player_active_areas) |
|
|
|
if player_active_regions ~= player_last_active_regions then |
|
|
|
creative_regions:player_enter_region(player, privstring) |
|
|
|
pmeta:set_string("creative_regions.active_regions", player_active_regions) |
|
|
|
end |
|
|
|
|
|
|
|
-- print(dump(pmeta:to_table())) |
|
|
|
end |
|
|
|
|
|
|
|
creative_regions:load_areas() |
|
|
|
creative_regions:load_regions() |
|
|
|
|
|
|
|
local timer = 0 |
|
|
|
minetest.register_globalstep(function(dtime) |
|
|
@ -358,8 +357,8 @@ end) |
|
|
|
-- areas mod hud |
|
|
|
if minetest.get_modpath("areas") then |
|
|
|
local function areas_hud_handler(pos, areas) |
|
|
|
local current_areas = creative_regions.astore:get_areas_for_pos(pos, false, true) |
|
|
|
for astore_id, astore_area in pairs( current_areas ) do |
|
|
|
local current_regions = creative_regions.astore:get_areas_for_pos(pos, false, true) |
|
|
|
for astore_id, astore_area in pairs( current_regions ) do |
|
|
|
if astore_id then |
|
|
|
table.insert(areas, { |
|
|
|
id = "mod:"..astore_id, |
|
|
|