diff --git a/README.md b/README.md index f3f94f8..c0d7eaa 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ Remove nodes from players what are not anymore listed in the /players directory. Protector, Protector2, locked doors, locked trapdoors, protected chests, basic machines, enchantment tables, easy vending machines, city blocks and locked chest will be removed by defautlt. It's easy to edit what blocks should be removed from init.lua Also removes new players what will leave the game without having by default: { "default:stick 1", "default:steel_ingot 1" } in the inventory. -The items can be easily modified. Player file form /players directory will be removed and (after server shutdown) also player data from auth.txt will be removed. +The items can be easily modified. Player file from /players directory will be removed and (after server shutdown) also player data from auth.txt will be removed. After the player leaves the game with satisfied requirements (items in inventory), this player inventory will not be checked any more. So it's just for new players and only for the 1st time they have those items in invetory. -Prevents /players folder and auth.txt getting cluttered with players what only comes to the server to have a look or not really doing any work at the server. \ No newline at end of file +Prevents /players folder and auth.txt getting cluttered with players what only comes to the server to have a look or not really doing any work at the server. + +Tested on Linux server, for Windows you have to adjust the paths from common slash "/" to backslash "\". \ No newline at end of file diff --git a/description.txt b/description.txt index 2d1dc51..d2a7358 100644 --- a/description.txt +++ b/description.txt @@ -1,6 +1,6 @@ Remove nodes from players what are not anymore listed in the /players directory. Protector, Protector2, locked doors, locked trapdoors, protected chests, basic machines, enchantment tables, easy vending machines, city blocks and locked chest will be removed by defautlt. It's easy to edit what blocks should be removed from init.lua Also removes new players what will leave the game without having by default: { "default:stick 1", "default:steel_ingot 1" } in the inventory. -The items can be easily modified. Player file form /players directory will be removed and (after server shutdown) also player data from auth.txt will be removed. +The items can be easily modified. Player file from /players directory will be removed and (after server shutdown) also player data from auth.txt will be removed. After the player leaves the game with satisfied requirements (items in inventory), this player inventory will not be checked any more. So it's just for new players and only for the 1st time they have those items in invetory. Prevents /players folder and auth.txt getting cluttered with players what only comes to the server to have a look or not really doing any work at the server. \ No newline at end of file diff --git a/init.lua b/init.lua index 7b5a4aa..9d16832 100644 --- a/init.lua +++ b/init.lua @@ -94,7 +94,7 @@ minetest.register_on_joinplayer(function(player) -- set player inventory data inv:set_size("newplayer", 1) inv:set_stack("newplayer", 1, ItemStack("newplayer")) - + -- print("adding player: "..pname.." to playerstable") -- print("adding player: "..pname.." to newplayers") junk_removal.playerstable[pname] = true @@ -139,7 +139,7 @@ minetest.register_on_leaveplayer(function(player, timed_out) -- PROBLEM: deleting doesnt always work? seems minetest itself is saving stuff, so we wait a little and then we delete minetest.after(1, function() minetest.log("action", "[junk_removal] Removing player filename: "..pfilename) - + local err, msg = os.remove(pfilename) if err == nil then @@ -192,16 +192,16 @@ function junk_removal:remove_players_from_auth() if not file then return end - for i, l in ipairs(lines) do + for i, l in ipairs(lines) do file:write(l, "\n") end file:close() - minetest.log("action", "***************************[junk_removal]***************************") + minetest.log("action", "===========================[junk_removal]===========================") minetest.log("action", " written players to auth.txt: "..count) minetest.log("action", " removed players from auth.txt: "..removed) minetest.log("action", " removed players names: "..minetest.serialize(junk_removal.removed_from_auth)) - minetest.log("action", "**************************[/junk_removal]***************************") + minetest.log("action", "==========================[/junk_removal]===========================") end minetest.register_on_shutdown(function() @@ -210,15 +210,15 @@ minetest.register_on_shutdown(function() -- print("k: "..k) -- local filename = worldpath.."/players/"..k -- local file, msg = io.open(filename, "r") - + -- if not file then -- minetest.log("warning", "[junk_removal] Error while opening player data "..filename.." error message: "..msg) -- return -- end - + -- local content = file:read("*all") -- file:close() - + -- for _, item in ipairs(junk_removal.requirements) do -- print("Item "..item:split(" ")[1]) -- if not string.find(content, "Item "..item:split(" ")[1]) then @@ -251,7 +251,7 @@ minetest.register_lbm({ local nname = node.name if not nname or not meta or not owner then return end - + local replace_nodename = "default:apple" if math.random(2) == 1 then replace_nodename = "default:leaves" @@ -259,23 +259,22 @@ minetest.register_lbm({ -- handle city block if owner == "" and nname == "city_block:cityblock" and minetest.global_exists("city_block") then + for i, EachBlock in ipairs(city_block.blocks) do if vector.equals(EachBlock.pos, pos) and not junk_removal.playerstable[EachBlock.owner] then table.remove(city_block.blocks, i) city_block:save() - -- print("removing player junk ("..nname.."): "..owner.." at "..minetest.pos_to_string(pos)) - minetest.log("action", "removing player junk ("..nname.."): "..owner.." at "..minetest.pos_to_string(pos)) - minetest.set_node(pos, {name = "default:apple"}) + minetest.log("action", "removing player junk ("..nname.."): "..EachBlock.owner.." at "..minetest.pos_to_string(pos)) + minetest.set_node(pos, {name = replace_nodename}) break end end - + return elseif owner == "" then return end if not junk_removal.playerstable[owner] then - -- print("removing player junk ("..nname.."): "..owner.." at "..minetest.pos_to_string(pos)) minetest.log("action", "removing player junk ("..nname.."): "..owner.." at "..minetest.pos_to_string(pos)) minetest.set_node(pos, {name = replace_nodename}) end