Allow sharing an area with all players, this changes the save format.

To convert to the new format run 'sed -i "s/\*//g" landclaim.0gb.us' in the world directory.
This commit is contained in:
ShadowNinja 2013-04-14 20:20:35 -04:00
parent 60fdfea4c8
commit a07014dfc8
2 changed files with 9 additions and 12 deletions

View File

@ -18,7 +18,7 @@ function landclaim_0gb_us.load_claims()
if line ~= "" then if line ~= "" then
local area = line:split(" ") local area = line:split(" ")
local shared = {} local shared = {}
if area[3] and area[3] ~= "*" then if area[3] then
for k,v in ipairs(area[3]:split(",")) do for k,v in ipairs(area[3]:split(",")) do
shared[v] = v shared[v] = v
end end
@ -33,15 +33,12 @@ end
function landclaim_0gb_us.save_claims() function landclaim_0gb_us.save_claims()
local file = io.open(filename, "w") local file = io.open(filename, "w")
for key,value in pairs(claims) do for key,value in pairs(claims) do
local sharedata = "" local sharestring = ""
for k,v in pairs(value.shared) do for k,v in pairs(value.shared) do
sharedata = sharedata..v.."," sharestring = sharestring..v..","
end end
local sharestring if sharestring ~= "" then
if sharedata == "" then sharestring = sharestring:sub(1,-2)
sharestring = "*"
else
sharestring = sharedata:sub(1,-2)
end end
file:write(key.." "..value.owner.." "..sharestring.."\n") file:write(key.." "..value.owner.." "..sharestring.."\n")
end end
@ -71,7 +68,7 @@ end
function landclaim_0gb_us.can_interact(name, pos) function landclaim_0gb_us.can_interact(name, pos)
local chunk = landclaim_0gb_us.get_chunk(pos) local chunk = landclaim_0gb_us.get_chunk(pos)
return claims[chunk] == nil or claims[chunk].owner == name or claims[chunk].shared[name] return claims[chunk] == nil or claims[chunk].owner == name or claims[chunk].shared[name] or claims[chunk].shared["*"]
or (landclaim_0gb_us.override[name] and minetest.check_player_privs(name, {claim_admin=true})) or (landclaim_0gb_us.override[name] and minetest.check_player_privs(name, {claim_admin=true}))
end end

View File

@ -85,7 +85,7 @@ minetest.register_chatcommand("unclaim", {
}) })
minetest.register_chatcommand("sharearea", { minetest.register_chatcommand("sharearea", {
params = "<name>", params = "<name|*>",
description = "shares the current map chunk with <name>", description = "shares the current map chunk with <name>",
privs = {interact=true}, privs = {interact=true},
func = function(name, param) func = function(name, param)
@ -98,7 +98,7 @@ minetest.register_chatcommand("sharearea", {
local owner = landclaim_0gb_us.get_owner(pos) local owner = landclaim_0gb_us.get_owner(pos)
if owner then if owner then
if (owner == name or minetest.check_player_privs(name, {claim_admin=true})) and name ~= param then if (owner == name or minetest.check_player_privs(name, {claim_admin=true})) and name ~= param then
if minetest.auth_table[param] then if minetest.auth_table[param] or param == "*" then
claims[landclaim_0gb_us.get_chunk(pos)].shared[param] = param claims[landclaim_0gb_us.get_chunk(pos)].shared[param] = param
landclaim_0gb_us.save_claims() landclaim_0gb_us.save_claims()
minetest.chat_send_player(name, param.." may now edit this area.") minetest.chat_send_player(name, param.." may now edit this area.")
@ -118,7 +118,7 @@ minetest.register_chatcommand("sharearea", {
}) })
minetest.register_chatcommand("unsharearea", { minetest.register_chatcommand("unsharearea", {
params = "<name>", params = "<name|*>",
description = "unshares the current map chunk with <name>", description = "unshares the current map chunk with <name>",
privs = {interact=true}, privs = {interact=true},
func = function(name, param) func = function(name, param)