Add a 'x' minute temporary lockout feature when vote kicked

This commit is contained in:
MinetestSam 2018-11-29 21:15:17 +05:30 committed by rubenwardy
parent b82af22a05
commit 4161ba0bee

View file

@ -1,8 +1,11 @@
vote = {
active = {},
queue = {}
queue = {},
kick_cooldown = 600
}
local vlist = {} -- table storing player name, ip & lock status
function vote.new_vote(creator, voteset)
local max_votes = tonumber(minetest.setting_get("vote.maximum_active")) or 1
local max_queue = tonumber(minetest.setting_get("vote.maximum_active")) or 0
@ -214,8 +217,13 @@ function vote.update_hud(player)
end
end
minetest.register_on_leaveplayer(function(player)
vote.hud.players[player:get_player_name()] = nil
local name = player:get_player_name()
vote.hud.players[name] = nil
if not vlist[name].locked then
vlist[name] = nil
end
end)
function vote.update_all_hud()
local players = minetest.get_connected_players()
for _, player in pairs(players) do
@ -337,7 +345,13 @@ if set == nil or minetest.is_yes(set) then
minetest.chat_send_all("Vote passed, " ..
#results.yes .. " to " .. #results.no .. ", " ..
self.name .. " will be kicked.")
minetest.kick_player(self.name, "The vote to kick you passed")
minetest.kick_player(self.name,
("The vote to kick you passed.\n You have been temporarily banned" ..
" for %s minutes."):format(tostring(vote.kick_cooldown / 60)))
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 .. ", " ..
@ -353,3 +367,25 @@ if set == nil or minetest.is_yes(set) then
end
})
end
minetest.register_on_joinplayer(function(player)
local name = player:get_player_name()
if not vlist[name] then
vlist[name] = {
ip = minetest.get_player_ip(name),
locked = false
}
end
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
return "This IP has been temporarily blocked."..
" Please wait until the cool-down period has elapsed before rejoining."
end
end
end
end)