Skip to content

Commit

Permalink
Add spam prevention (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
Panquesito7 authored May 3, 2020
1 parent 97bbeb0 commit b5643fa
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
79 changes: 79 additions & 0 deletions functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -310,6 +386,7 @@ function tp.tphr_send(sender, receiver)
return
end
end, receiver)
end
end

function tp.tpc_send(sender, coordinates)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions locale/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
8 changes: 8 additions & 0 deletions locale/template.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down
3 changes: 3 additions & 0 deletions settingtypes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b5643fa

Please sign in to comment.