1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-11-15 23:10:31 +01:00

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
This commit is contained in:
LeMagnesium 2015-06-29 20:19:40 +02:00
parent 9fc3cfb9a9
commit 11a121f7df
3 changed files with 126 additions and 29 deletions

1
mods/_misc/depends.txt Executable file
View File

@ -0,0 +1 @@
interact

View File

@ -6,9 +6,11 @@ minetest.register_globalstep(function(dtime)
for _,player in ipairs(minetest.get_connected_players()) do for _,player in ipairs(minetest.get_connected_players()) do
local name = player:get_player_name() local name = player:get_player_name()
if not minetest.check_player_privs(name, {interact=true}) then if not minetest.check_player_privs(name, {interact=true}) then
if minetest.check_player_privs(name, {shout=true}) then if not interact.blacklist[name] 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.") if minetest.check_player_privs(name, {shout=true}) then
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.") 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 end
end end

View File

@ -203,18 +203,27 @@ minetest.register_chatcommand("rules",{
privs = interact.priv, privs = interact.priv,
func = function (name,params) func = function (name,params)
local player = minetest.get_player_by_name(name) local player = minetest.get_player_by_name(name)
if interact.screen1 ~= false then if not interact.blacklist[name] then
minetest.after(1, function() if interact.screen1 ~= false then
minetest.show_formspec(name, "welcome", make_formspec(player)) minetest.after(1, function()
end) minetest.show_formspec(name, "welcome", make_formspec(player))
elseif interact.screen2 ~= false then end)
minetest.after(1, function() elseif interact.screen2 ~= false then
minetest.show_formspec(name, "visit", make_formspec2(player)) minetest.after(1, function()
end) 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 else
minetest.after(1, function() minetest.log("action", "[interact] Blacklisted player " .. name .. " tried to get back " ..
minetest.show_formspec(name, "rules", make_formspec3(player)) "his revoked privilege")
end) return false, "Sorry, you've been blacklisted by " ..
(interact.blacklist[name].emitter or "<unknown>") .. " on " ..
(interact.blacklist[name].date or "<unknown>") .. " . Thus, you can't use " ..
" this command to get interact back. Sorry."
end end
end end
}) })
@ -222,26 +231,111 @@ minetest.register_chatcommand("rules",{
function start_formspecs(player) function start_formspecs(player)
local name = player:get_player_name() local name = player:get_player_name()
if not minetest.get_player_privs(name).interact then if not minetest.get_player_privs(name).interact then
if interact.screen1 ~= false then if not interact.blacklist[name] then
minetest.show_formspec(name, "welcome", make_formspec(player)) if interact.screen1 ~= false then
elseif interact.screen2 ~= false then minetest.show_formspec(name, "welcome", make_formspec(player))
minetest.show_formspec(name, "visit", make_formspec2(player)) elseif interact.screen2 ~= false then
else minetest.show_formspec(name, "visit", make_formspec2(player))
minetest.show_formspec(name, "rules", make_formspec3(player)) else
minetest.show_formspec(name, "rules", make_formspec3(player))
end
end end
end end
end end
minetest.register_on_joinplayer(start_formspecs) minetest.register_on_joinplayer(start_formspecs)
minetest.register_chatcommand("rules", {
description = "Obtain interact privilege / Obtenir le privilege interact", -- Blacklist
params = "",
privs = {}, interact.blacklist = {}
func = function(name)
local player = minetest.get_player_by_name(name) minetest.register_chatcommand("unblacklist", {
if player then params = "<playername>",
start_formspecs(player) 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
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 "<unknown>") ..
" by " .. (interact.blacklist[param].emitter or "<unknown>") .. ")")
interact.blacklist[param] = nil
return true, "Done."
end
}) })
minetest.register_chatcommand("blacklist", {
params = "<playername>",
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()