From b5643fa13147543590e2c500d6a6466eee055bf1 Mon Sep 17 00:00:00 2001 From: David Leal Date: Sun, 3 May 2020 12:55:24 -0500 Subject: [PATCH] Add spam prevention (#37) --- config.lua | 3 ++ functions.lua | 79 +++++++++++++++++++++++++++++++++++++++++++++ locale/es.po | 8 +++++ locale/template.pot | 8 +++++ settingtypes.txt | 3 ++ 5 files changed, 101 insertions(+) diff --git a/config.lua b/config.lua index d81463c..a4583cd 100644 --- a/config.lua +++ b/config.lua @@ -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") diff --git a/functions.lua b/functions.lua index f091136..c1c0e62 100644 --- a/functions.lua +++ b/functions.lua @@ -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 ")) + if minetest.get_modpath("chat2") then + chat2.send_message(minetest.get_player_by_name(sender), S("Usage: /tpr "), 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 ")) + if minetest.get_modpath("chat2") then + chat2.send_message(minetest.get_player_by_name(sender), S("Usage. /tphr "), 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 ")) + if minetest.get_modpath("chat2") then + chat2.send_message(minetest.get_player_by_name(sender), S("Usage. /tphr "), 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 diff --git a/locale/es.po b/locale/es.po index 838ddc9..f9fb08f 100644 --- a/locale/es.po +++ b/locale/es.po @@ -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." diff --git a/locale/template.pot b/locale/template.pot index c083ab2..a899598 100644 --- a/locale/template.pot +++ b/locale/template.pot @@ -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 "" diff --git a/settingtypes.txt b/settingtypes.txt index 7a40d9d..f133649 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -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