Add spam prevention (#37)

This commit is contained in:
David Leal 2020-05-03 12:55:24 -05:00 committed by GitHub
parent 97bbeb0f08
commit b5643fa131
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 101 additions and 0 deletions

@ -34,3 +34,6 @@ tp.available_places = {
-- Enable tpp command
tp.enable_tpp_command = minetest.settings:get_bool("tp.enable_tpp_command")
-- Spam prevention
tp.spam_prevention = minetest.settings:get_bool("tp.enable_spam_prevention")

@ -25,6 +25,9 @@ local S = tp.intllib
local chatmsg, source, target, name2,
target_coords, tpc_target_coords, old_tpc_target_coords
local spam_prevention = {}
local band = false
local map_size = 30912
function tp.can_teleport(to)
return to.x < map_size and to.x > -map_size and to.y < map_size and to.y > -map_size and to.z < map_size and to.z > -map_size
@ -99,6 +102,38 @@ end
-- Teleport Request System
function tp.tpr_send(sender, receiver)
if receiver == "" then
minetest.chat_send_player(sender, S("Usage: /tpr <Player name>"))
if minetest.get_modpath("chat2") then
chat2.send_message(minetest.get_player_by_name(sender), S("Usage: /tpr <Player name>"), 0xFFFFFF)
end
return
end
if not minetest.get_player_by_name(receiver) then
minetest.chat_send_player(sender, S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online"))
if minetest.get_modpath("chat2") then
chat2.send_message(minetest.get_player_by_name(sender), S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online"), 0xFFFFFF)
end
return
end
-- Spam prevention
if spam_prevention[receiver] == sender and not minetest.check_player_privs(sender, {tp_admin = true}) then
minetest.chat_send_player(sender, S("Wait @1 seconds before you can send teleport requests to @2 again.", tp.timeout_delay, receiver))
minetest.after(tp.timeout_delay, function(name)
spam_prevention[name] = nil
if band == true then return end
if spam_prevention[receiver] == nil then
minetest.chat_send_player(sender, S("You can now send teleport requests to @1.", receiver))
band = true
end
end, receiver)
else
-- Compatibility with beerchat
if minetest.get_modpath("beerchat") and not minetest.check_player_privs(sender, {tp_admin = true}) then
if receiver == "" then
@ -207,11 +242,52 @@ function tp.tpr_send(sender, receiver)
return
end
end, receiver)
end
end
function tp.tphr_send(sender, receiver)
if receiver == "" then
minetest.chat_send_player(sender, S("Usage: /tphr <Player name>"))
if minetest.get_modpath("chat2") then
chat2.send_message(minetest.get_player_by_name(sender), S("Usage. /tphr <Player name>"), 0xFFFFFF)
end
return
end
if not minetest.get_player_by_name(receiver) then
minetest.chat_send_player(sender, S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online."))
if minetest.get_modpath("chat2") then
chat2.send_message(minetest.get_player_by_name(sender), S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online."), 0xFFFFFF)
end
return
end
-- Spam prevention
if spam_prevention[receiver] == sender and not minetest.check_player_privs(sender, {tp_admin = true}) then
minetest.chat_send_player(sender, S("Wait @1 seconds before you can send teleport requests to @2 again.", tp.timeout_delay, receiver))
minetest.after(tp.timeout_delay, function(name)
spam_prevention[name] = nil
if band == true then return end
if spam_prevention[receiver] == nil then
minetest.chat_send_player(sender, S("You can now send teleport requests to @1.", receiver))
band = true
end
end, receiver)
else
-- Compatibility with beerchat
if minetest.get_modpath("beerchat") and not minetest.check_player_privs(sender, {tp_admin = true}) then
if receiver == "" then
minetest.chat_send_player(sender, S("Usage: /tphr <Player name>"))
if minetest.get_modpath("chat2") then
chat2.send_message(minetest.get_player_by_name(sender), S("Usage. /tphr <Player name>"), 0xFFFFFF)
end
return
end
if not minetest.get_player_by_name(receiver) then
minetest.chat_send_player(sender, S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online."))
if minetest.get_modpath("chat2") then
@ -310,6 +386,7 @@ function tp.tphr_send(sender, receiver)
return
end
end, receiver)
end
end
function tp.tpc_send(sender, coordinates)
@ -461,6 +538,7 @@ function tp.tpr_deny(name)
end
tp.tpr_list[name] = nil
spam_prevention[name] = name2
-- Don't allow re-denying requests.
tp.tpn_list[name2] = nil
@ -475,6 +553,7 @@ function tp.tpr_deny(name)
end
tp.tphr_list[name] = nil
spam_prevention[name] = name2
-- Don't allow re-denying requests.
tp.tpn_list[name2] = nil

@ -28,6 +28,14 @@ msgstr "Da acceso total de administrador a un jugador."
msgid "Allow player to teleport to coordinates (if allowed by area protection)"
msgstr "Permite a los jugadores teletransportarse a las coordenadas especificadas (si esta permitido por la protección de la área)"
#: init.lua
msgid "Wait @1 seconds before you can send teleport requests to @2 again."
msgstr "Espere @1 segundos antes de que pueda mandar solicitudes de teletransporte a @2."
#: init.lua
msgid "You can now send teleport requests to @1."
msgstr "Ya puede mandar solicitudes de teletransporte a @1."
#: init.lua
msgid "You are not allowed to send requests because you're muted."
msgstr "No tienes permiso para mandar solicitudes de teletransporte porque estás silenciado."

@ -28,6 +28,14 @@ msgstr ""
msgid "Allow player to teleport to coordinates (if allowed by area protection)"
msgstr ""
#: init.lua
msgid "Wait @1 seconds before you can send teleport requests to @2 again."
msgstr ""
#: init.lua
msgid "You can now send teleport requests to @1."
msgstr ""
#: init.lua
msgid "You are not allowed to send requests because you're muted."
msgstr ""

@ -6,3 +6,6 @@ tp.enable_immediate_teleport (Immediate teleport for those with tp_admin privile
# Enables Teleport To Place command (disabled by default)
tp.enable_tpp_command (Enable Teleport To Place command) bool false
# Spam prevention (enabled by default)
tp.enable_spam_prevention (Enable spam prevention) bool true