Stop writing privs to file

This commit is contained in:
ezhh 2017-10-23 02:33:14 +01:00
parent f7a25bec74
commit 8995163894

View File

@ -202,41 +202,6 @@ minetest.register_chatcommand("curses",{
-- Cage Commands -- Cage Commands
local priv_table = {}
-- save table to file
local function table_save()
local data = priv_table
local f, err = io.open(minetest.get_worldpath() .. "/curse_priv_table.txt", "w")
if err then
return err
end
f:write(minetest.serialize(data))
f:close()
end
-- read saved file
local function table_read()
local f, err = io.open(minetest.get_worldpath() .. "/curse_priv_table.txt", "r")
local data = minetest.deserialize(f:read("*a"))
f:close()
return data
end
minetest.after(3.0, function()
local f, err = io.open(minetest.get_worldpath() .. "/curse_priv_table.txt", "r")
if err then
table_save()
else
priv_table = table_read()
end
end)
minetest.register_on_shutdown(function()
table_save()
end)
-- put a player in the cage -- put a player in the cage
minetest.register_chatcommand("cage", { minetest.register_chatcommand("cage", {
params = "<person>", params = "<person>",
@ -261,15 +226,13 @@ minetest.register_chatcommand("cage", {
if not cagepos then if not cagepos then
return false, "No cage set..." return false, "No cage set..."
end end
-- add current target privs to table and save to file -- save then remove all privs other than shout
local privs = minetest.get_player_privs(target_name) local target_privs = minetest.privs_to_string(minetest.get_player_privs(target_name))
priv_table[target_name] = privs target:set_attribute("caged_privs", target_privs)
table_save() minetest.chat_send_player(warden_name, target:get_attribute("caged_privs"))
-- remove all privs but shout and cage
minetest.set_player_privs(target_name,{shout = true}) minetest.set_player_privs(target_name,{shout = true})
target:set_attribute("caged", "true") target:set_attribute("caged", "true")
sneak_mode(target, "none") sneak_mode(target, "none")
-- move target to cage location
target:setpos(cagepos) target:setpos(cagepos)
end end
}) })
@ -294,33 +257,16 @@ minetest.register_chatcommand("uncage", {
if not releasepos then if not releasepos then
return false, "No release point set..." return false, "No release point set..."
end end
-- get target's original privs from table and restore them -- restore privs and release
local original_privs = priv_table[target_name] local original_privs = minetest.string_to_privs(target:get_attribute("caged_privs"))
minetest.set_player_privs(target_name,original_privs) minetest.set_player_privs(target_name, original_privs)
-- remove entry for target from table and save to file target:set_attribute("caged_privs", nil)
priv_table[target_name] = nil
table_save()
-- restore sneak and move target to release point
sneak_mode(target, default_sneak_mode) sneak_mode(target, default_sneak_mode)
target:set_attribute("caged", "") target:set_attribute("caged", "")
target:setpos(releasepos) target:setpos(releasepos)
end end
}) })
-- list caged players
minetest.register_chatcommand("list_caged", {
params = "",
description = "List all caged players.",
privs = {server = true},
func = function (_, _)
local players = ""
for player, _ in pairs(priv_table) do
players = players .. player .. ", "
end
return true, "Currently caged players: " .. players
end
})
-- Other Commands -- Other Commands