From 11a121f7dff89ff43beaf14e193743af9f9e5890 Mon Sep 17 00:00:00 2001 From: LeMagnesium Date: Mon, 29 Jun 2015 20:19:40 +0200 Subject: [PATCH] Fixed /rules and added blacklist system - Removed useless copy of /rules - Added a blacklist system avoiding people to get back the interact privilege using /rules when blacklisted --- mods/_misc/depends.txt | 1 + mods/_misc/nointeract_messages.lua | 8 +- mods/interact/init.lua | 146 ++++++++++++++++++++++++----- 3 files changed, 126 insertions(+), 29 deletions(-) create mode 100755 mods/_misc/depends.txt diff --git a/mods/_misc/depends.txt b/mods/_misc/depends.txt new file mode 100755 index 00000000..8b7c3683 --- /dev/null +++ b/mods/_misc/depends.txt @@ -0,0 +1 @@ +interact diff --git a/mods/_misc/nointeract_messages.lua b/mods/_misc/nointeract_messages.lua index 40c21e31..3e04bd16 100755 --- a/mods/_misc/nointeract_messages.lua +++ b/mods/_misc/nointeract_messages.lua @@ -6,9 +6,11 @@ minetest.register_globalstep(function(dtime) for _,player in ipairs(minetest.get_connected_players()) do local name = player:get_player_name() if not minetest.check_player_privs(name, {interact=true}) then - if minetest.check_player_privs(name, {shout=true}) then - minetest.chat_send_player(name, "Hey " .. name .. " ! Pour pouvoir construire et intéragir sur ce serveur, tu dois lire les règles du serveur et les accepter. Tape /rules.") - minetest.chat_send_player(name, "Hey " .. name .. " ! To build and interact on this server, you have to read the rules of our server and agree them. Type /rules.") + if not interact.blacklist[name] then + if minetest.check_player_privs(name, {shout=true}) then + minetest.chat_send_player(name, "Hey " .. name .. " ! Pour pouvoir construire et intéragir sur ce serveur, tu dois lire les règles du serveur et les accepter. Tape /rules.") + minetest.chat_send_player(name, "Hey " .. name .. " ! To build and interact on this server, you have to read the rules of our server and agree them. Type /rules.") + end end end end diff --git a/mods/interact/init.lua b/mods/interact/init.lua index a156f3ae..4a8f1b20 100755 --- a/mods/interact/init.lua +++ b/mods/interact/init.lua @@ -203,18 +203,27 @@ minetest.register_chatcommand("rules",{ privs = interact.priv, func = function (name,params) local player = minetest.get_player_by_name(name) - if interact.screen1 ~= false then - minetest.after(1, function() - minetest.show_formspec(name, "welcome", make_formspec(player)) - end) - elseif interact.screen2 ~= false then - minetest.after(1, function() - minetest.show_formspec(name, "visit", make_formspec2(player)) - end) + if not interact.blacklist[name] then + if interact.screen1 ~= false then + minetest.after(1, function() + minetest.show_formspec(name, "welcome", make_formspec(player)) + end) + elseif interact.screen2 ~= false then + minetest.after(1, function() + minetest.show_formspec(name, "visit", make_formspec2(player)) + end) + else + minetest.after(1, function() + minetest.show_formspec(name, "rules", make_formspec3(player)) + end) + end else - minetest.after(1, function() - minetest.show_formspec(name, "rules", make_formspec3(player)) - end) + minetest.log("action", "[interact] Blacklisted player " .. name .. " tried to get back " .. + "his revoked privilege") + return false, "Sorry, you've been blacklisted by " .. + (interact.blacklist[name].emitter or "") .. " on " .. + (interact.blacklist[name].date or "") .. " . Thus, you can't use " .. + " this command to get interact back. Sorry." end end }) @@ -222,26 +231,111 @@ minetest.register_chatcommand("rules",{ function start_formspecs(player) local name = player:get_player_name() if not minetest.get_player_privs(name).interact then - if interact.screen1 ~= false then - minetest.show_formspec(name, "welcome", make_formspec(player)) - elseif interact.screen2 ~= false then - minetest.show_formspec(name, "visit", make_formspec2(player)) - else - minetest.show_formspec(name, "rules", make_formspec3(player)) + if not interact.blacklist[name] then + if interact.screen1 ~= false then + minetest.show_formspec(name, "welcome", make_formspec(player)) + elseif interact.screen2 ~= false then + minetest.show_formspec(name, "visit", make_formspec2(player)) + else + minetest.show_formspec(name, "rules", make_formspec3(player)) + end end end end minetest.register_on_joinplayer(start_formspecs) -minetest.register_chatcommand("rules", { - description = "Obtain interact privilege / Obtenir le privilege interact", - params = "", - privs = {}, - func = function(name) - local player = minetest.get_player_by_name(name) - if player then - start_formspecs(player) + +-- Blacklist + +interact.blacklist = {} + +minetest.register_chatcommand("unblacklist", { + params = "", + description = "Remove a player from the interact blacklist", + privs = {basic_privs = true, interact = true}, + func = function(name, param) + if param == "" then + return false, "Give a player's name to remove from the blacklist." end - end, + + if not interact.blacklist[param] then + return true, "Player " .. param " is not actually blacklisted." + end + + if name == param then + return true, "Ahahaha. Well tried looser." + end + + minetest.log("action", "[interact] " .. name .. " removed " .. param .. " from " .. + "blacklist (added on " .. (interact.blacklist[param].date or "") .. + " by " .. (interact.blacklist[param].emitter or "") .. ")") + interact.blacklist[param] = nil + return true, "Done." + end }) + +minetest.register_chatcommand("blacklist", { + params = "", + description = "Blacklist a player. [S]He won't be able to use /rules.", + privs = {basic_privs = true, interact = true}, + func = function(name, param) + if param == "" then + return false, "Give a player's name to blacklist." + end + + local blackfile = io.open(minetest.get_worldpath() .. "/players/" .. param, "r") + if not blackfile then + return false, "Player doesn't exist." + end + io.close(blackfile) + + if name == param then + return true, "You know this wouldn't work, right?" + end + + if interact.blacklist[param] then + return true, "Player already blacklisted." + end + + if minetest.get_player_privs(param).interact == true then + return true, "Warning: This player has interact! Use revoke before blacklisting." + end + + interact.blacklist[param] = { + emitter = name, + date = os.date("%m/%d/%Y") + } + minetest.log("action", "[interact] " .. name .. " added " .. param .. " on /rules blacklist.") + return true, "Player " .. param .. " blacklisted." + end +}) + +function load_blacklist() + local file = io.open(minetest.get_worldpath().."/interact_blacklist.txt", "r") + if not file then + file = io.open(minetest.get_worldpath().."/interact_blacklist.txt", "w") + if not file then + minetest.log("error", "[interact] Error opening blacklist file") + return + end + minetest.log("action", "[interact] Blacklist created") + end + interact.blacklist = minetest.deserialize(file:read()) + minetest.log("action", "[interact] Blacklist loaded") + file:close() +end + +function save_blacklist() + local file = io.open(minetest.get_worldpath().."/interact_blacklist.txt", "w") + if not file then + minetest.log("error", "[interact] Error opening blacklist file") + return + end + file:write(minetest.serialize(interact.blacklist)) + minetest.log("action", "[interact] Blacklist saved") + file:close() +end + +minetest.register_on_shutdown(save_blacklist) +load_blacklist()