|
|
@ -9,9 +9,9 @@ toggle_areas.area_privs = {} |
|
|
|
toggle_areas.registered_on_enter = {} |
|
|
|
toggle_areas.registered_on_leave = {} |
|
|
|
|
|
|
|
areas_owner_privs = minetest.settings:get("toggle_areas.owner_privs") or "+creative, +fly, +fast" |
|
|
|
areas_owner_privs = minetest.settings:get("toggle_areas.owner_privs") or "+creative, +fast, +fly" |
|
|
|
areas_guest_privs = minetest.settings:get("toggle_areas.guest_privs") or "-fly, -fast" |
|
|
|
default_privs = minetest.settings:get("toggle_areas.default_privs") or "+fast, -creative" |
|
|
|
default_privs = minetest.settings:get("toggle_areas.default_privs") or "-creative, +fast, -fly" |
|
|
|
|
|
|
|
function toggle_areas:load_areas() |
|
|
|
local test = minetest.deserialize(mod_storage:get_string("astore")) |
|
|
@ -20,7 +20,7 @@ function toggle_areas:load_areas() |
|
|
|
local data = "Testarea" |
|
|
|
local astore_id = self.astore:insert_area(edge1, edge2, tostring(data)) |
|
|
|
|
|
|
|
self.set_area_privs(astore_id, "+fly, +fast, +creative") |
|
|
|
toggle_areas:set_area_privs(astore_id, "+creative, +fast, +fly") |
|
|
|
|
|
|
|
self.register_on_enter(astore_id, function(player) |
|
|
|
local name = player:get_player_name() |
|
|
@ -61,8 +61,10 @@ function toggle_areas:decode_privs_string(str) |
|
|
|
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 |
|
|
@ -149,8 +151,8 @@ function toggle_areas:update_player(player) |
|
|
|
|
|
|
|
local pmeta = player:get_meta() |
|
|
|
-- pmeta:mark_as_private("toggle_areas") |
|
|
|
local player_last_active_area = pmeta:get_string("toggle_areas.active_area") or "-1" |
|
|
|
local player_active_area = "-1" |
|
|
|
local player_last_active_areas = pmeta:get_string("toggle_areas.active_areas") or "-1" |
|
|
|
local player_active_areas = "-1" |
|
|
|
local areas_owner = false |
|
|
|
local areas_guest = false |
|
|
|
local areas_open = false |
|
|
@ -162,38 +164,36 @@ function toggle_areas:update_player(player) |
|
|
|
return |
|
|
|
end |
|
|
|
|
|
|
|
-- enter area |
|
|
|
local current_areas = self.astore:get_areas_for_pos(pos, true, true) |
|
|
|
for astore_id, astore_area in pairs( current_areas ) do |
|
|
|
local areasize = toggle_areas:get_area_size(astore_area) |
|
|
|
if not smallest_area.size or areasize < smallest_area.size then |
|
|
|
smallest_area.id = astore_id |
|
|
|
smallest_area.size = areasize |
|
|
|
end |
|
|
|
end |
|
|
|
if smallest_area.id then |
|
|
|
player_active_areas = tostring(smallest_area.id) |
|
|
|
end |
|
|
|
|
|
|
|
-- enter areas mod area |
|
|
|
local a_current_areas = {} |
|
|
|
if minetest.get_modpath("areas") then |
|
|
|
a_current_areas = areas:getAreasAtPos(pos) |
|
|
|
for a_id, a_area in pairs( a_current_areas ) do |
|
|
|
player_active_areas = player_active_areas .. ", a"..a_id |
|
|
|
if a_area.owner == name then |
|
|
|
areas_owner = true |
|
|
|
player_active_area = "a"..a_id |
|
|
|
break |
|
|
|
elseif a_area.open then |
|
|
|
areas_open = true |
|
|
|
player_active_area = "a"..a_id |
|
|
|
break |
|
|
|
else |
|
|
|
areas_guest = true |
|
|
|
player_active_area = "a"..a_id |
|
|
|
break |
|
|
|
end |
|
|
|
--continue |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
-- enter area |
|
|
|
local current_areas = self.astore:get_areas_for_pos(pos, true, true) |
|
|
|
for astore_id, astore_area in pairs( current_areas ) do |
|
|
|
local areasize = toggle_areas:get_area_size(astore_area) |
|
|
|
if not smallest_area.size or areasize < smallest_area.size then |
|
|
|
smallest_area.id = astore_id |
|
|
|
smallest_area.size = areasize |
|
|
|
end |
|
|
|
end |
|
|
|
if player_active_area == "-1" and smallest_area.id then |
|
|
|
player_active_area = smallest_area.id |
|
|
|
end |
|
|
|
|
|
|
|
local privstring = default_privs |
|
|
@ -203,17 +203,21 @@ function toggle_areas:update_player(player) |
|
|
|
if areas_owner or areas_open then |
|
|
|
privstring = privstring .. ", " .. areas_owner_privs |
|
|
|
elseif areas_guest then |
|
|
|
if toggle_areas.area_privs[player_active_area] then |
|
|
|
privstring = privstring .. ", " .. toggle_areas.area_privs[player_active_area] |
|
|
|
else |
|
|
|
privstring = privstring .. ", " .. areas_guest_privs |
|
|
|
for _, a in pairs(string.split(player_active_areas, ",")) do |
|
|
|
a = a:trim() |
|
|
|
if string.sub(a, 1, 1) == "a" then |
|
|
|
if toggle_areas.area_privs[a] then |
|
|
|
privstring = privstring .. ", " .. toggle_areas.area_privs[a] |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
if player_active_area ~= player_last_active_area then |
|
|
|
minetest.log("warning", "[toggle_areas] player entering new area "..player_last_active_area.."->"..player_active_area) |
|
|
|
if player_active_areas ~= player_last_active_areas then |
|
|
|
minetest.log("warning", "[toggle_areas] player entering new area "..player_last_active_areas.."->"..player_active_areas) |
|
|
|
toggle_areas:player_enter_area(player, privstring) |
|
|
|
pmeta:set_string("toggle_areas.active_area", player_active_area) |
|
|
|
pmeta:set_string("toggle_areas.active_areas", player_active_areas) |
|
|
|
end |
|
|
|
|
|
|
|
-- print(dump(pmeta:to_table())) |
|
|
|