2018-12-30 23:07:22 +00:00
|
|
|
vote.kick_cooldown = 600
|
|
|
|
local vlist = {} -- table storing player name, ip & lock status
|
|
|
|
|
|
|
|
minetest.register_privilege("vote_kick", {
|
2019-10-18 05:52:18 +00:00
|
|
|
description = "Can start vote to kick a player",
|
2018-12-30 23:07:22 +00:00
|
|
|
on_grant = function(name, granter)
|
2019-05-10 12:09:01 +00:00
|
|
|
if not granter then
|
|
|
|
granter = "<nil>"
|
|
|
|
end
|
2019-10-18 05:52:18 +00:00
|
|
|
minetest.log("action", "Player '" .. name .. "' has been" ..
|
|
|
|
" granted 'vote_kick' by '" .. granter .. "'")
|
2018-12-30 23:07:22 +00:00
|
|
|
end,
|
|
|
|
on_revoke = function(name, revoker)
|
2019-05-10 12:09:01 +00:00
|
|
|
if not revoker then
|
|
|
|
revoker = "<nil>"
|
|
|
|
end
|
2019-10-18 05:52:18 +00:00
|
|
|
minetest.log("action", "Player '" .. name .. "' has been" ..
|
|
|
|
" revoked of 'vote_kick' by '" .. revoker .. "'")
|
2018-12-30 23:07:22 +00:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("vote_kick", {
|
|
|
|
params = "<name>",
|
|
|
|
description = "Start a vote to kick a player",
|
|
|
|
privs = {
|
|
|
|
interact = true,
|
|
|
|
vote_kick = true,
|
|
|
|
},
|
|
|
|
func = function(name, param)
|
|
|
|
param = param:trim()
|
|
|
|
if param == "" then
|
|
|
|
return false, "Please specify a player name to be vote-kicked!"
|
|
|
|
end
|
|
|
|
|
|
|
|
if not minetest.get_player_by_name(param) then
|
2019-10-18 05:52:18 +00:00
|
|
|
return false, "There is no player called '" .. param .. "'"
|
2018-12-30 23:07:22 +00:00
|
|
|
end
|
|
|
|
|
2020-12-22 16:21:22 +00:00
|
|
|
if minetest.check_player_privs(param, {kick = true}) then
|
2018-12-30 23:07:22 +00:00
|
|
|
return false, param .. " is a moderator, and can't be kicked!"
|
|
|
|
end
|
|
|
|
|
2019-10-18 05:52:18 +00:00
|
|
|
minetest.log("action", name .. " started a vote to kick " .. param)
|
2019-05-09 17:50:46 +00:00
|
|
|
|
|
|
|
if not vlist[param] then
|
|
|
|
vlist[param] = {
|
|
|
|
ip = minetest.get_player_ip(param),
|
|
|
|
locked = false
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-12-30 23:07:22 +00:00
|
|
|
return vote.new_vote(name, {
|
|
|
|
description = "Kick " .. param,
|
|
|
|
help = "/yes, /no or /abstain",
|
|
|
|
name = param,
|
|
|
|
duration = 60,
|
|
|
|
perc_needed = 0.8,
|
|
|
|
|
2019-10-02 14:32:09 +00:00
|
|
|
can_vote = function(self, pname)
|
2019-12-05 18:33:38 +00:00
|
|
|
return ctf_stats.is_pro(name)
|
2019-10-02 14:32:09 +00:00
|
|
|
end,
|
|
|
|
|
2018-12-30 23:07:22 +00:00
|
|
|
on_result = function(self, result, results)
|
|
|
|
if result == "yes" then
|
|
|
|
minetest.chat_send_all("Vote passed, " ..
|
|
|
|
#results.yes .. " to " .. #results.no .. ", " ..
|
|
|
|
self.name .. " will be kicked.")
|
|
|
|
minetest.kick_player(self.name,
|
2019-10-18 05:52:18 +00:00
|
|
|
("The vote to kick you passed.\n You have been temporarily banned" ..
|
|
|
|
" for %s minutes."):format(tostring(vote.kick_cooldown / 60)))
|
2018-12-30 23:07:22 +00:00
|
|
|
vlist[self.name].locked = true
|
|
|
|
minetest.after(vote.kick_cooldown, function()
|
|
|
|
vlist[self.name] = nil
|
|
|
|
end)
|
|
|
|
else
|
|
|
|
minetest.chat_send_all("Vote failed, " ..
|
|
|
|
#results.yes .. " to " .. #results.no .. ", " ..
|
|
|
|
self.name .. " remains ingame.")
|
2019-05-09 17:50:46 +00:00
|
|
|
if not minetest.get_player_by_name(self.name) then
|
|
|
|
vlist[self.name] = nil
|
|
|
|
end
|
2018-12-30 23:07:22 +00:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
|
|
|
|
on_vote = function(self, voter, value)
|
|
|
|
minetest.chat_send_all(voter .. " voted " .. value .. " to '" ..
|
|
|
|
self.description .. "'")
|
|
|
|
end
|
|
|
|
})
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("unblock", {
|
|
|
|
params = "<name>",
|
|
|
|
description = "Unblock a vote-kicked player before the cooldown expires",
|
2020-12-22 16:21:22 +00:00
|
|
|
privs = {kick = true},
|
2018-12-30 23:07:22 +00:00
|
|
|
func = function(name, param)
|
|
|
|
param = param:trim()
|
|
|
|
if param == "" then
|
|
|
|
return false, "Please specify a player name to be unblocked!"
|
|
|
|
end
|
|
|
|
|
2019-05-09 17:50:46 +00:00
|
|
|
if not vlist[param].locked then
|
2018-12-30 23:07:22 +00:00
|
|
|
return false, "Failed! " .. param .. " is not blocked"
|
|
|
|
end
|
|
|
|
|
2019-05-09 17:50:46 +00:00
|
|
|
vlist[param].locked = false
|
2019-10-18 05:52:18 +00:00
|
|
|
minetest.log("action", name .. " unblocked " .. param .. ", who was vote-kicked")
|
2018-12-30 23:07:22 +00:00
|
|
|
return true, param .. " has been successfully unblocked!"
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_on_prejoinplayer(function(name, ip)
|
|
|
|
if vlist[name] and vlist[name].locked then
|
|
|
|
return "Please wait until the vote cool down period has elapsed before rejoining!"
|
|
|
|
else
|
|
|
|
for k, v in pairs(vlist) do
|
|
|
|
if v.ip == ip and v.locked then
|
2019-10-18 05:52:18 +00:00
|
|
|
return "This IP has been temporarily blocked." ..
|
|
|
|
" Please wait until the cool-down period has elapsed before rejoining."
|
2018-12-30 23:07:22 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|