|
|
@ -12,28 +12,102 @@ areas_guest_privs = minetest.settings:get("switch_creative.guest_privs") or "-fl |
|
|
|
default_privs = minetest.settings:get("switch_creative.default_privs") or "-creative, +fast, -fly" |
|
|
|
|
|
|
|
function switch_creative:load_areas() |
|
|
|
local test = minetest.deserialize(mod_storage:get_string("astore")) |
|
|
|
local edge1 = { x=-10, y=-10, z=-10 } |
|
|
|
local edge2 = { x=10, y=10, z=10 } |
|
|
|
local data = "Testarea" |
|
|
|
local astore_id = self.astore:insert_area(edge1, edge2, tostring(data)) |
|
|
|
|
|
|
|
switch_creative:set_area_privs(astore_id, "+creative, +fast, +fly") |
|
|
|
self.astore:from_file(minetest.get_worldpath().."/switch_creative_areas") |
|
|
|
-- local test = minetest.deserialize(mod_storage:get_string("astore")) |
|
|
|
-- local edge1 = { x=-10, y=-10, z=-10 } |
|
|
|
-- local edge2 = { x=10, y=10, z=10 } |
|
|
|
-- local data = "Testarea" |
|
|
|
-- local astore_id = self.astore:insert_area(edge1, edge2, tostring(data)) |
|
|
|
-- |
|
|
|
-- switch_creative:set_area_privs(astore_id, "+creative, +fast, +fly") |
|
|
|
end |
|
|
|
|
|
|
|
function switch_creative:save_areas() |
|
|
|
local datastr = minetest.serialize(self.astore) |
|
|
|
if not datastr then |
|
|
|
minetest.log("error", "[switch_creative] Failed to serialize area data!") |
|
|
|
return |
|
|
|
end |
|
|
|
mod_storage:set_string("astore", datastr) |
|
|
|
self.astore:to_file(minetest.get_worldpath().."/switch_creative_areas") |
|
|
|
-- local datastr = minetest.serialize(self.astore) |
|
|
|
-- if not datastr then |
|
|
|
-- minetest.log("error", "[switch_creative] Failed to serialize area data!") |
|
|
|
-- return |
|
|
|
-- end |
|
|
|
-- mod_storage:set_string("astore", datastr) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
function switch_creative:set_area_privs(id, privs_string) |
|
|
|
switch_creative.area_privs[id] = privs_string |
|
|
|
end |
|
|
|
|
|
|
|
minetest.register_chatcommand("creative_area", { |
|
|
|
params = "<x> <y> <z>, <x> <y> <z>, <text>", |
|
|
|
description = "Set a switch_creative area 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*(.+)$") |
|
|
|
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 astore_id = switch_creative.astore:insert_area(edge1, edge2, tostring(data)) |
|
|
|
switch_creative:set_area_privs(astore_id, "+creative, +fast, +fly") |
|
|
|
minetest.chat_send_player(name, "[creative_area] New area set. ID: " .. astore_id) |
|
|
|
switch_creative:save_areas() |
|
|
|
return true, "Done." |
|
|
|
end, |
|
|
|
}) |
|
|
|
|
|
|
|
minetest.register_chatcommand("creative_area_privs", { |
|
|
|
params = "<id>, <text>", |
|
|
|
description = "Set privstring for switch_creative area", |
|
|
|
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("^([+-]?%d+)%s*,%s*(.+)$") |
|
|
|
if not found then |
|
|
|
return false, "Syntax error" |
|
|
|
end |
|
|
|
area_id = tonumber(area_id) |
|
|
|
switch_creative:set_area_privs(area_id, privstring) |
|
|
|
minetest.chat_send_player(name, "[creative_area] Privstring set for area " .. area_id .. ": " .. privstring) |
|
|
|
switch_creative:save_areas() |
|
|
|
return true, "Done." |
|
|
|
end, |
|
|
|
}) |
|
|
|
|
|
|
|
minetest.register_chatcommand("creative_area_rm", { |
|
|
|
params = "<id>", |
|
|
|
description = "Remove a switch_creative area", |
|
|
|
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*$") |
|
|
|
if not found then |
|
|
|
return false, "Syntax error" |
|
|
|
end |
|
|
|
area_id = tonumber(area_id) |
|
|
|
local success = switch_creative.astore:remove_area(area_id) |
|
|
|
if success then |
|
|
|
minetest.chat_send_player(name, "[creative_area] Area " .. area_id .. "removed") |
|
|
|
else |
|
|
|
minetest.chat_send_player(name, "[creative_area] Error removing area " .. area_id) |
|
|
|
end |
|
|
|
switch_creative:save_areas() |
|
|
|
return true, "Done." |
|
|
|
end, |
|
|
|
}) |
|
|
|
|
|
|
|
function switch_creative:decode_privs_string(str) |
|
|
|
-- minetest/builtin/common/misc_helpers.lua:core.string_to_privs() |
|
|
|
assert(type(str) == "string") |
|
|
@ -148,7 +222,7 @@ function switch_creative:update_player(player) |
|
|
|
local smallest_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 area. You have protection_bypass priv") |
|
|
|
return |
|
|
|
end |
|
|
|
|
|
|
|