From e588717ca0c31231dfdb070b28f4da48ad4c347c Mon Sep 17 00:00:00 2001 From: Ombridride Date: Mon, 15 Dec 2014 01:23:00 +0100 Subject: [PATCH] Add "future_ban" mod MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Useful if the xban2 method doesn’t work --- mods/future_ban/README.md | 0 mods/future_ban/init.lua | 63 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100755 mods/future_ban/README.md create mode 100755 mods/future_ban/init.lua diff --git a/mods/future_ban/README.md b/mods/future_ban/README.md new file mode 100755 index 00000000..e69de29b diff --git a/mods/future_ban/init.lua b/mods/future_ban/init.lua new file mode 100755 index 00000000..d3854c8c --- /dev/null +++ b/mods/future_ban/init.lua @@ -0,0 +1,63 @@ +future_ban_list = {} + +local file = io.open(minetest.get_worldpath().."/future_banlist.txt", "r") +if file then + future_ban_list = minetest.deserialize(file:read("*all")) + file:close() + if not future_ban_list then + future_ban_list = {} + end +end + +local function save_file() + local file = io.open(minetest.get_worldpath().."/future_banlist.txt", "w") + if file then + file:write(minetest.serialize(future_ban_list)) + file:close() + end +end + +minetest.register_chatcommand("future_ban", { + params = " | leave playername out to see the future ban list", + description = "The player will be banned when trying to join", + privs = {ban=true}, + func = function(name, param) + if param == "" then + minetest.chat_send_player(name, "Future ban list: " .. dump(future_ban_list)) + return + end + if not minetest.get_player_by_name(param) then + table.insert(future_ban_list, param) + minetest.chat_send_player(name, param .. " to future ban list added.") + minetest.log("action", name .. " added " .. param .. " to future ban list.") + save_file() + return + end + if not minetest.ban_player(param) then + table.insert(future_ban_list, param) + minetest.chat_send_player(name, desc .. " to future ban list added.") + minetest.log("action", name .. " added " .. desc .. " to future ban list.") + save_file() + else + local desc = minetest.get_ban_description(param) + minetest.chat_send_player(name, "Banned " .. desc .. ".") + minetest.log("action", name .. " bans " .. desc .. ".") + end + end +}) + +minetest.register_on_joinplayer(function(player) + local name = player:get_player_name() + for i,n in ipairs(future_ban_list) do + if n == name then + if not minetest.ban_player(name) then + minetest.chat_send_player(name, "Failed to ban player " .. name .. " (from future ban list).") + else + local desc = minetest.get_ban_description(name) + minetest.log("action", desc .. " banned (from future ban list).") + table.remove(future_ban_list, i) + save_file() + end + end + end +end)