From 7f4aac280beefecd836f458595588c065583449a Mon Sep 17 00:00:00 2001 From: Oversword Date: Sun, 8 Aug 2021 20:55:25 +0100 Subject: [PATCH 01/11] Fix indentation --- functions.lua | 200 +++++++++++++++++++++++++------------------------- 1 file changed, 101 insertions(+), 99 deletions(-) diff --git a/functions.lua b/functions.lua index 40a3bf2..615b22b 100644 --- a/functions.lua +++ b/functions.lua @@ -225,24 +225,24 @@ function tp.tpr_send(sender, receiver) if minetest.get_modpath("chat2") then chat2.send_message(minetest.get_player_by_name(sender), S("You are not allowed to send requests because you're muted."), 0xFFFFFF) end - return + return + end end - end if minetest.check_player_privs(sender, {tp_admin = true}) and tp.enable_immediate_teleport then 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 + 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 + 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 @@ -255,57 +255,57 @@ function tp.tpr_send(sender, receiver) return end - 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 + 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 + 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 - if minetest.get_modpath("gamehub") then -- Compatibility with gamehub (UNTESTED) - if gamehub.players[receiver] then - minetest.chat_send_player(sender, S("Teleport request denied, player is in the gamehub!")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Teleport request denied, player is in the gamehub!"), 0xFFFFFF) - end - return + if minetest.get_modpath("gamehub") then -- Compatibility with gamehub (UNTESTED) + if gamehub.players[receiver] then + minetest.chat_send_player(sender, S("Teleport request denied, player is in the gamehub!")) + if minetest.get_modpath("chat2") then + chat2.send_message(minetest.get_player_by_name(sender), S("Teleport request denied, player is in the gamehub!"), 0xFFFFFF) end + return end + end - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(receiver), S("@1 is requesting to teleport to you. /tpy to accept.", sender), 0xFFFFFF) - chat2.send_message(minetest.get_player_by_name(sender), S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay), 0xFFFFFF) - end + if minetest.get_modpath("chat2") then + chat2.send_message(minetest.get_player_by_name(receiver), S("@1 is requesting to teleport to you. /tpy to accept.", sender), 0xFFFFFF) + chat2.send_message(minetest.get_player_by_name(sender), S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay), 0xFFFFFF) + end - minetest.chat_send_player(receiver, S("@1 is requesting to teleport to you. /tpy to accept.", sender)) - minetest.chat_send_player(sender, S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay)) + minetest.chat_send_player(receiver, S("@1 is requesting to teleport to you. /tpy to accept.", sender)) + minetest.chat_send_player(sender, S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay)) - -- Write name values to list and clear old values. - tp.tpr_list[receiver] = sender - tp.tpn_list[sender] = receiver + -- Write name values to list and clear old values. + tp.tpr_list[receiver] = sender + tp.tpn_list[sender] = receiver - -- Teleport timeout delay - minetest.after(tp.timeout_delay, function(name) - if tp.tpr_list[name] and tp.tpn_list[sender] then - tp.tpr_list[name] = nil - tp.tpn_list[sender] = nil + -- Teleport timeout delay + minetest.after(tp.timeout_delay, function(name) + if tp.tpr_list[name] and tp.tpn_list[sender] then + tp.tpr_list[name] = nil + tp.tpn_list[sender] = nil - minetest.chat_send_player(sender, S("Request timed-out.")) - minetest.chat_send_player(receiver, S("Request timed-out.")) + minetest.chat_send_player(sender, S("Request timed-out.")) + minetest.chat_send_player(receiver, S("Request timed-out.")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Request timed-out."), 0xFFFFFF) - chat2.send_message(minetest.get_player_by_name(receiver), S("Request timed-out."), 0xFFFFFF) - end + if minetest.get_modpath("chat2") then + chat2.send_message(minetest.get_player_by_name(sender), S("Request timed-out."), 0xFFFFFF) + chat2.send_message(minetest.get_player_by_name(receiver), S("Request timed-out."), 0xFFFFFF) + end return end end, receiver) @@ -375,24 +375,24 @@ function tp.tphr_send(sender, receiver) if minetest.get_modpath("chat2") then chat2.send_message(minetest.get_player_by_name(sender), S("You are not allowed to send requests because you're muted."), 0xFFFFFF) end - return + return + end end - end if minetest.check_player_privs(sender, {tp_admin = true}) and tp.enable_immediate_teleport 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 + 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 + 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 @@ -405,52 +405,54 @@ function tp.tphr_send(sender, receiver) return end - 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 + 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 + 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 - if minetest.get_modpath("gamehub") then -- Compatibility with gamehub (UNTESTED) - if gamehub.players[receiver] then - minetest.chat_send_player(sender, S("Teleport request denied, player is in the gamehub!")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Teleport request denied, player is in the gamehub!"), 0xFFFFFF) - end - return + if minetest.get_modpath("gamehub") then -- Compatibility with gamehub (UNTESTED) + if gamehub.players[receiver] then + minetest.chat_send_player(sender, S("Teleport request denied, player is in the gamehub!")) + if minetest.get_modpath("chat2") then + chat2.send_message(minetest.get_player_by_name(sender), S("Teleport request denied, player is in the gamehub!"), 0xFFFFFF) end + return end + end - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(receiver), S("@1 is requesting that you teleport to them. /tpy to accept; /tpn to deny.", sender), 0xFFFFFF) - chat2.send_message(minetest.get_player_by_name(sender), S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay), 0xFFFFFF) - end + - minetest.chat_send_player(receiver, S("@1 is requesting that you teleport to them. /tpy to accept; /tpn to deny.", sender)) - minetest.chat_send_player(sender, S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay)) + if minetest.get_modpath("chat2") then + chat2.send_message(minetest.get_player_by_name(receiver), S("@1 is requesting that you teleport to them. /tpy to accept; /tpn to deny.", sender), 0xFFFFFF) + chat2.send_message(minetest.get_player_by_name(sender), S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay), 0xFFFFFF) + end - -- Write name values to list and clear old values. - tp.tphr_list[receiver] = sender - tp.tpn_list[sender] = receiver + minetest.chat_send_player(receiver, S("@1 is requesting that you teleport to them. /tpy to accept; /tpn to deny.", sender)) + minetest.chat_send_player(sender, S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay)) - -- Teleport timeout delay - minetest.after(tp.timeout_delay, function(name) - if tp.tphr_list[name] and tp.tpn_list[sender] then - tp.tphr_list[name] = nil - tp.tpn_list[sender] = nil + -- Write name values to list and clear old values. + tp.tphr_list[receiver] = sender + tp.tpn_list[sender] = receiver - minetest.chat_send_player(sender, S("Request timed-out.")) - minetest.chat_send_player(receiver, S("Request timed-out.")) + -- Teleport timeout delay + minetest.after(tp.timeout_delay, function(name) + if tp.tphr_list[name] and tp.tpn_list[sender] then + tp.tphr_list[name] = nil + tp.tpn_list[sender] = nil + + minetest.chat_send_player(sender, S("Request timed-out.")) + minetest.chat_send_player(receiver, S("Request timed-out.")) if minetest.get_modpath("chat2") then chat2.send_message(minetest.get_player_by_name(sender), S("Request timed-out"), 0xFFFFFF) @@ -467,9 +469,9 @@ function tp.tpc_send(sender, coordinates) local pname = minetest.get_player_by_name(sender) if posx ~= nil or posy ~= nil or posz ~= nil then - posx = tonumber(posx) + 0.0 - posy = tonumber(posy) + 0.0 - posz = tonumber(posz) + 0.0 + posx = tonumber(posx) + 0.0 + posy = tonumber(posy) + 0.0 + posz = tonumber(posz) + 0.0 end if posx==nil or posy==nil or posz==nil or string.len(posx) > 6 or string.len(posy) > 6 or string.len(posz) > 6 then @@ -548,15 +550,15 @@ function tp.tpc_send(sender, coordinates) return end end, area.owner) - else - minetest.record_protection_violation(target_coords, sender) + else + minetest.record_protection_violation(target_coords, sender) end end - else - minetest.record_protection_violation(target_coords, sender) - end - return + else + minetest.record_protection_violation(target_coords, sender) end + return + end tp.tpc_teleport_player(sender) target_coords = nil From 3894f8c7baf85bd794b7c1f09d13750c075d4272 Mon Sep 17 00:00:00 2001 From: Oversword Date: Sun, 8 Aug 2021 20:58:04 +0100 Subject: [PATCH 02/11] Remove additions --- functions.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/functions.lua b/functions.lua index 615b22b..7f5c1a3 100644 --- a/functions.lua +++ b/functions.lua @@ -431,8 +431,6 @@ function tp.tphr_send(sender, receiver) end end - - if minetest.get_modpath("chat2") then chat2.send_message(minetest.get_player_by_name(receiver), S("@1 is requesting that you teleport to them. /tpy to accept; /tpn to deny.", sender), 0xFFFFFF) chat2.send_message(minetest.get_player_by_name(sender), S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay), 0xFFFFFF) From dfd22811ab097808cae6b4d6aa83529acd477055 Mon Sep 17 00:00:00 2001 From: Oversword Date: Sun, 8 Aug 2021 21:12:38 +0100 Subject: [PATCH 03/11] Fix minetest.after calls --- functions.lua | 75 ++++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/functions.lua b/functions.lua index 7f5c1a3..1f2a802 100644 --- a/functions.lua +++ b/functions.lua @@ -189,15 +189,15 @@ function tp.tpr_send(sender, receiver) 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 + minetest.after(tp.timeout_delay, function(sender_name, receiver_name) + spam_prevention[receiver_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)) + if spam_prevention[receiver_name] == nil then + minetest.chat_send_player(sender_name, S("You can now send teleport requests to @1.", receiver_name)) band = true end - end, receiver) + end, sender, receiver) else @@ -294,21 +294,21 @@ function tp.tpr_send(sender, receiver) tp.tpn_list[sender] = receiver -- Teleport timeout delay - minetest.after(tp.timeout_delay, function(name) - if tp.tpr_list[name] and tp.tpn_list[sender] then - tp.tpr_list[name] = nil - tp.tpn_list[sender] = nil + minetest.after(tp.timeout_delay, function(sender_name, receiver_name) + if tp.tpr_list[receiver_name] and tp.tpn_list[sender_name] then + tp.tpr_list[receiver_name] = nil + tp.tpn_list[sender_name] = nil - minetest.chat_send_player(sender, S("Request timed-out.")) - minetest.chat_send_player(receiver, S("Request timed-out.")) + minetest.chat_send_player(sender_name, S("Request timed-out.")) + minetest.chat_send_player(receiver_name, S("Request timed-out.")) if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Request timed-out."), 0xFFFFFF) - chat2.send_message(minetest.get_player_by_name(receiver), S("Request timed-out."), 0xFFFFFF) + chat2.send_message(minetest.get_player_by_name(sender_name), S("Request timed-out."), 0xFFFFFF) + chat2.send_message(minetest.get_player_by_name(receiver_name), S("Request timed-out."), 0xFFFFFF) end return end - end, receiver) + end, sender, receiver) end end @@ -339,15 +339,15 @@ function tp.tphr_send(sender, receiver) 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 + minetest.after(tp.timeout_delay, function(sender_name, receiver_name) + spam_prevention[receiver_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)) + if spam_prevention[receiver_name] == nil then + minetest.chat_send_player(sender_name, S("You can now send teleport requests to @1.", receiver_name)) band = true end - end, receiver) + end, sender, receiver) else @@ -444,21 +444,22 @@ function tp.tphr_send(sender, receiver) tp.tpn_list[sender] = receiver -- Teleport timeout delay - minetest.after(tp.timeout_delay, function(name) - if tp.tphr_list[name] and tp.tpn_list[sender] then - tp.tphr_list[name] = nil - tp.tpn_list[sender] = nil - minetest.chat_send_player(sender, S("Request timed-out.")) - minetest.chat_send_player(receiver, S("Request timed-out.")) + minetest.after(tp.timeout_delay, function(sender_name, receiver_name) + if tp.tphr_list[receiver_name] and tp.tpn_list[sender_name] then + tp.tphr_list[receiver_name] = nil + tp.tpn_list[sender_name] = nil + + minetest.chat_send_player(sender_name, S("Request timed-out.")) + minetest.chat_send_player(receiver_name, S("Request timed-out.")) if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Request timed-out"), 0xFFFFFF) - chat2.send_message(minetest.get_player_by_name(receiver), S("Request timed-out"), 0xFFFFFF) + chat2.send_message(minetest.get_player_by_name(sender_name), S("Request timed-out"), 0xFFFFFF) + chat2.send_message(minetest.get_player_by_name(receiver_name), S("Request timed-out"), 0xFFFFFF) end return end - end, receiver) + end, sender, receiver) end end @@ -533,21 +534,21 @@ function tp.tpc_send(sender, coordinates) tp.tpc_list[area.owner] = sender tp.tpn_list[sender] = area.owner - minetest.after(tp.timeout_delay, function(name) - if tp.tpc_list[name] and tp.tpn_list[sender] then - tp.tpc_list[name] = nil - tp.tpn_list[sender] = nil + minetest.after(tp.timeout_delay, function(sender_name, receiver_name) + if tp.tpc_list[receiver_name] and tp.tpn_list[sender_name] then + tp.tpc_list[receiver_name] = nil + tp.tpn_list[sender_name] = nil - minetest.chat_send_player(sender, S("Request timed-out.")) - minetest.chat_send_player(area.owner, S("Request timed-out.")) + minetest.chat_send_player(sender_name, S("Request timed-out.")) + minetest.chat_send_player(receiver_name, S("Request timed-out.")) if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Request timed-out."), 0xFFFFFF) - chat2.send_message(minetest.get_player_by_name(area.owner), S("Request timed-out."), 0xFFFFFF) + chat2.send_message(minetest.get_player_by_name(sender_name), S("Request timed-out."), 0xFFFFFF) + chat2.send_message(minetest.get_player_by_name(receiver_name), S("Request timed-out."), 0xFFFFFF) end return end - end, area.owner) + end, sender, area.owner) else minetest.record_protection_violation(target_coords, sender) end From a5a805aa90ded48d6701c9cec1ae9ed486ec3d8b Mon Sep 17 00:00:00 2001 From: Oversword Date: Sun, 8 Aug 2021 21:38:13 +0100 Subject: [PATCH 04/11] Remove chat message code duplication; Allow setting of chat color --- config.lua | 3 + functions.lua | 389 +++++++++++++---------------------------------- settingtypes.txt | 3 + 3 files changed, 114 insertions(+), 281 deletions(-) diff --git a/config.lua b/config.lua index bcfae82..df6108d 100644 --- a/config.lua +++ b/config.lua @@ -22,6 +22,9 @@ USA tp.timeout_delay = tonumber(minetest.settings:get("tp.timeout_delay")) or 60 tp.version = "1.5" +-- Message color +tp.message_color = minetest.settings:get("tp.message_color") or "#FFFFFF" + -- Enable teleporting immediately to the specified player for those with "tp_admin" privilege. tp.enable_immediate_teleport = minetest.settings:get_bool("tp.enable_immediate_teleport") diff --git a/functions.lua b/functions.lua index 1f2a802..624919b 100644 --- a/functions.lua +++ b/functions.lua @@ -30,6 +30,32 @@ local band = false local muted_players = {} +local message_color = tp.message_color + +local function color_string_to_number(color) + if string.sub(color,1,1) == '#' then + color = string.sub(color, 2) + end + if #color < 6 then + local r = string.sub(color,1,1) + local g = string.sub(color,2,2) + local b = string.sub(color,3,3) + color = r..r .. g..g .. b..b + elseif #color > 6 then + color = string.sub(color, 1, 6) + end + return tonumber(color, 16) +end + +local message_color_number = color_string_to_number(message_color) + +local function send_message(player, message) + minetest.chat_send_player(player, minetest.colorize(message_color, message)) + if minetest.get_modpath("chat2") then + chat2.send_message(minetest.get_player_by_name(player), message, message_color_number) + end +end + 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 @@ -105,96 +131,78 @@ end -- Mutes a player from sending you teleport requests function tp.tpr_mute(player, muted_player) if muted_player == "" then - minetest.chat_send_player(player, S("Usage: /tpr_mute ")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(player), S("Usage: /tpr_mute "), 0xFFFFFF) - end + send_message(player, S("Usage: /tpr_mute ")) return end if not minetest.get_player_by_name(muted_player) then - minetest.chat_send_player(player, 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(player), S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online."), 0xFFFFFF) - end + send_message(player, S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online.")) return end if minetest.check_player_privs(muted_player, {tp_admin = true}) and not minetest.check_player_privs(player, {server = true}) then - minetest.chat_send_player(player, S("tpr_mute: Failed to mute player @1: they have the tp_admin privilege.", muted_player)) + send_message(player, S("tpr_mute: Failed to mute player @1: they have the tp_admin privilege.", muted_player)) return end if muted_players[player] == muted_player then - minetest.chat_send_player(player, S("tpr_mute: Player @1 is already muted.", muted_player)) + send_message(player, S("tpr_mute: Player @1 is already muted.", muted_player)) return end muted_players[player] = muted_player - minetest.chat_send_player(player, S("tpr_mute: Player @1 successfully muted.", muted_player)) + send_message(player, S("tpr_mute: Player @1 successfully muted.", muted_player)) end -- Unmutes a player from sending you teleport requests function tp.tpr_unmute(player, muted_player) if muted_player == "" then - minetest.chat_send_player(player, S("Usage: /tpr_unmute ")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(player), S("Usage: /tpr_unmute "), 0xFFFFFF) - end + send_message(player, S("Usage: /tpr_unmute ")) return end if not minetest.get_player_by_name(muted_player) then - minetest.chat_send_player(player, 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(player), S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online."), 0xFFFFFF) - end + send_message(player, S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online.")) return end if muted_players[player] ~= muted_player then - minetest.chat_send_player(player, S("tpr_mute: Player @1 is not muted yet.", muted_player)) + send_message(player, S("tpr_mute: Player @1 is not muted yet.", muted_player)) return end muted_players[player] = nil - minetest.chat_send_player(player, S("tpr_mute: Player @1 successfully unmuted.", muted_player)) + send_message(player, S("tpr_mute: Player @1 successfully unmuted.", muted_player)) end -- Teleport Request System function tp.tpr_send(sender, receiver) -- Check if the sender is muted if muted_players[receiver] == sender and not minetest.check_player_privs(sender, {server = true}) then - minetest.chat_send_player(sender, S("Cannot send request to @1 (you have been muted).", receiver)) + send_message(sender, S("Cannot send request to @1 (you have been muted).", receiver)) return end 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 + send_message(sender, S("Usage: /tpr ")) 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 + send_message(sender, S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online")) 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)) + send_message(sender, S("Wait @1 seconds before you can send teleport requests to @2 again.", tp.timeout_delay, receiver)) minetest.after(tp.timeout_delay, function(sender_name, receiver_name) spam_prevention[receiver_name] = nil if band == true then return end if spam_prevention[receiver_name] == nil then - minetest.chat_send_player(sender_name, S("You can now send teleport requests to @1.", receiver_name)) + send_message(sender_name, S("You can now send teleport requests to @1.", receiver_name)) band = true end end, sender, receiver) @@ -204,90 +212,58 @@ function tp.tpr_send(sender, receiver) -- 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: /tpr ")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Usage: /tpr "), 0xFFFFFF) - end + send_message(sender, S("Usage: /tpr ")) 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 + send_message(sender, S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online")) return end local player_receiver = minetest.get_player_by_name(receiver) if player_receiver:get_meta():get_string("beerchat:muted:" .. sender) == "true" then - minetest.chat_send_player(sender, S("You are not allowed to send requests because you're muted.")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("You are not allowed to send requests because you're muted."), 0xFFFFFF) - end + send_message(sender, S("You are not allowed to send requests because you're muted.")) return end end if minetest.check_player_privs(sender, {tp_admin = true}) and tp.enable_immediate_teleport then 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 + send_message(sender, S("Usage: /tpr ")) 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 + send_message(sender, S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online")) return end tp.tpr_list[receiver] = sender tp.tpr_accept(receiver) - minetest.chat_send_player(sender, S("You are teleporting to @1.", receiver)) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("You are teleporting to @1.", receiver), 0xFFFFFF) - end + send_message(sender, S("You are teleporting to @1.", receiver)) return end 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 + send_message(sender, S("Usage: /tpr ")) 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 + send_message(sender, S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online")) return end if minetest.get_modpath("gamehub") then -- Compatibility with gamehub (UNTESTED) if gamehub.players[receiver] then - minetest.chat_send_player(sender, S("Teleport request denied, player is in the gamehub!")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Teleport request denied, player is in the gamehub!"), 0xFFFFFF) - end + send_message(sender, S("Teleport request denied, player is in the gamehub!")) return end end - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(receiver), S("@1 is requesting to teleport to you. /tpy to accept.", sender), 0xFFFFFF) - chat2.send_message(minetest.get_player_by_name(sender), S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay), 0xFFFFFF) - end - - minetest.chat_send_player(receiver, S("@1 is requesting to teleport to you. /tpy to accept.", sender)) - minetest.chat_send_player(sender, S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay)) + send_message(receiver, S("@1 is requesting to teleport to you. /tpy to accept.", sender)) + send_message(sender, S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay)) -- Write name values to list and clear old values. tp.tpr_list[receiver] = sender @@ -299,13 +275,8 @@ function tp.tpr_send(sender, receiver) tp.tpr_list[receiver_name] = nil tp.tpn_list[sender_name] = nil - minetest.chat_send_player(sender_name, S("Request timed-out.")) - minetest.chat_send_player(receiver_name, S("Request timed-out.")) - - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender_name), S("Request timed-out."), 0xFFFFFF) - chat2.send_message(minetest.get_player_by_name(receiver_name), S("Request timed-out."), 0xFFFFFF) - end + send_message(sender_name, S("Request timed-out.")) + send_message(receiver_name, S("Request timed-out.")) return end end, sender, receiver) @@ -315,36 +286,30 @@ end function tp.tphr_send(sender, receiver) -- Check if the sender is muted if muted_players[receiver] == sender and not minetest.check_player_privs(sender, {server = true}) then - minetest.chat_send_player(sender, S("Cannot send request to @1 (you have been muted).", receiver)) + send_message(sender, S("Cannot send request to @1 (you have been muted).", receiver)) return end 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 + send_message(sender, S("Usage: /tphr ")) 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 + send_message(sender, S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online.")) 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)) + send_message(sender, S("Wait @1 seconds before you can send teleport requests to @2 again.", tp.timeout_delay, receiver)) minetest.after(tp.timeout_delay, function(sender_name, receiver_name) spam_prevention[receiver_name] = nil if band == true then return end if spam_prevention[receiver_name] == nil then - minetest.chat_send_player(sender_name, S("You can now send teleport requests to @1.", receiver_name)) + send_message(sender_name, S("You can now send teleport requests to @1.", receiver_name)) band = true end end, sender, receiver) @@ -354,90 +319,58 @@ function tp.tphr_send(sender, receiver) -- 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 + send_message(sender, S("Usage: /tphr ")) 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 + send_message(sender, S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online.")) return end local player_receiver = minetest.get_player_by_name(receiver) if player_receiver:get_meta():get_string("beerchat:muted:" .. sender) == "true" then - minetest.chat_send_player(sender, S("You are not allowed to send requests because you're muted.")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("You are not allowed to send requests because you're muted."), 0xFFFFFF) - end + send_message(sender, S("You are not allowed to send requests because you're muted.")) return end end if minetest.check_player_privs(sender, {tp_admin = true}) and tp.enable_immediate_teleport 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 + send_message(sender, S("Usage: /tphr ")) 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 + send_message(sender, S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online.")) return end tp.tphr_list[receiver] = sender tp.tpr_accept(receiver) - minetest.chat_send_player(sender, S("@1 is teleporting to you.", receiver)) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("@1 is teleporting to you.", receiver), 0xFFFFFF) - end + send_message(sender, S("@1 is teleporting to you.", receiver)) return end 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 + send_message(sender, S("Usage: /tphr ")) 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 + send_message(sender, S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online.")) return end if minetest.get_modpath("gamehub") then -- Compatibility with gamehub (UNTESTED) if gamehub.players[receiver] then - minetest.chat_send_player(sender, S("Teleport request denied, player is in the gamehub!")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Teleport request denied, player is in the gamehub!"), 0xFFFFFF) - end + send_message(sender, S("Teleport request denied, player is in the gamehub!")) return end end - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(receiver), S("@1 is requesting that you teleport to them. /tpy to accept; /tpn to deny.", sender), 0xFFFFFF) - chat2.send_message(minetest.get_player_by_name(sender), S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay), 0xFFFFFF) - end - - minetest.chat_send_player(receiver, S("@1 is requesting that you teleport to them. /tpy to accept; /tpn to deny.", sender)) - minetest.chat_send_player(sender, S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay)) + send_message(receiver, S("@1 is requesting that you teleport to them. /tpy to accept; /tpn to deny.", sender)) + send_message(sender, S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay)) -- Write name values to list and clear old values. tp.tphr_list[receiver] = sender @@ -450,13 +383,8 @@ function tp.tphr_send(sender, receiver) tp.tphr_list[receiver_name] = nil tp.tpn_list[sender_name] = nil - minetest.chat_send_player(sender_name, S("Request timed-out.")) - minetest.chat_send_player(receiver_name, S("Request timed-out.")) - - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender_name), S("Request timed-out"), 0xFFFFFF) - chat2.send_message(minetest.get_player_by_name(receiver_name), S("Request timed-out"), 0xFFFFFF) - end + send_message(sender_name, S("Request timed-out.")) + send_message(receiver_name, S("Request timed-out.")) return end end, sender, receiver) @@ -474,20 +402,14 @@ function tp.tpc_send(sender, coordinates) end if posx==nil or posy==nil or posz==nil or string.len(posx) > 6 or string.len(posy) > 6 or string.len(posz) > 6 then - minetest.chat_send_player(sender, S("Usage: /tpc ")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Usage: /tpc "), 0xFFFFFF) - end + send_message(sender, S("Usage: /tpc ")) return nil end target_coords = {x=posx, y=posy, z=posz} if tp.can_teleport(target_coords) == false then - minetest.chat_send_player(sender, S("You cannot teleport to a location outside the map!")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("You cannot teleport to a location outside the map!"), 0xFFFFFF) - end + send_message(sender, S("You cannot teleport to a location outside the map!")) return nil end @@ -496,10 +418,7 @@ function tp.tpc_send(sender, coordinates) if minetest.check_player_privs(pname, {tp_admin = true}) then tp.tpc_teleport_player(sender) target_coords = nil - minetest.chat_send_player(sender, S("Teleporting to: @1, @2, @3", posx, posy, posz)) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Teleporting to: @1, @2, @3", posx, posy, posz), 0xFFFFFF) - end + send_message(sender, S("Teleporting to: @1, @2, @3", posx, posy, posz)) else if minetest.check_player_privs(pname, {tp_tpc = true}) then local protected = minetest.is_protected(target_coords, sender) @@ -518,19 +437,11 @@ function tp.tpc_send(sender, coordinates) tpc_target_coords[area.owner] = {x=posx, y=posy, z=posz} end - minetest.chat_send_player(sender, S("Area request sent! Waiting for @1 to accept your request." .. + send_message(sender, S("Area request sent! Waiting for @1 to accept your request." .. " It will timeout in @2 seconds.", table.concat(areas:getNodeOwners(tpc_target_coords[area.owner]), S(", or ")), tp.timeout_delay)) - minetest.chat_send_player(area.owner, S("@1 is requesting to teleport to a protected area" .. + send_message(area.owner, S("@1 is requesting to teleport to a protected area" .. " of yours @2.", sender, minetest.pos_to_string(tpc_target_coords[area.owner]))) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Area request sent! Waiting for @1 to accept your request." .. - " It will timeout in @2 seconds.", table.concat(areas:getNodeOwners(tpc_target_coords[area.owner]), S(", or ")), tp.timeout_delay), 0xFFFFFF) - - chat2.send_message(minetest.get_player_by_name(area.owner), S("@1 is requesting to teleport to a protected area" .. - " of yours @2.", sender, minetest.pos_to_string(tpc_target_coords[area.owner])), 0xFFFFFF) - end - tp.tpc_list[area.owner] = sender tp.tpn_list[sender] = area.owner @@ -539,13 +450,8 @@ function tp.tpc_send(sender, coordinates) tp.tpc_list[receiver_name] = nil tp.tpn_list[sender_name] = nil - minetest.chat_send_player(sender_name, S("Request timed-out.")) - minetest.chat_send_player(receiver_name, S("Request timed-out.")) - - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender_name), S("Request timed-out."), 0xFFFFFF) - chat2.send_message(minetest.get_player_by_name(receiver_name), S("Request timed-out."), 0xFFFFFF) - end + send_message(sender_name, S("Request timed-out.")) + send_message(receiver_name, S("Request timed-out.")) return end end, sender, area.owner) @@ -561,15 +467,9 @@ function tp.tpc_send(sender, coordinates) tp.tpc_teleport_player(sender) target_coords = nil - minetest.chat_send_player(sender, S("Teleporting to: @1, @2, @3", posx, posy, posz)) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Teleporting to: @1, @2, @3", posx, posy, posz), 0xFFFFFF) - end + send_message(sender, S("Teleporting to: @1, @2, @3", posx, posy, posz)) else - minetest.chat_send_player(sender, S("Error: You do not have permission to teleport to those coordinates.")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Error: You do not have permission to teleport to those coordinates."), 0xFFFFFF) - end + send_message(sender, S("Error: You do not have permission to teleport to those coordinates.")) return end end @@ -578,22 +478,15 @@ end function tp.tpr_deny(name) if not tp.tpr_list[name] and not tp.tphr_list[name] and not tp.tpc_list[name] and not tp.tpn_list[name] then - minetest.chat_send_player(name, S("Usage: /tpn allows you to deny teleport/area requests sent to you by other players.")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(name), S("Usage: /tpn allows you to deny teleport/area requests sent to you by other players."), 0xFFFFFF) - end + send_message(name, S("Usage: /tpn allows you to deny teleport/area requests sent to you by other players.")) return end -- Area requests if tp.tpc_list[name] then name2 = tp.tpc_list[name] - minetest.chat_send_player(name2, S("Area request denied.")) - minetest.chat_send_player(name, S("You denied the request @1 sent you.", name2)) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(name2), S("Area request denied."), 0xFFFFFF) - chat2.send_message(minetest.get_player_by_name(name), S("You denied the request @1 sent you.", name2), 0xFFFFFF) - end + send_message(name2, S("Area request denied.")) + send_message(name, S("You denied the request @1 sent you.", name2)) tp.tpc_list[name] = nil -- Don't allow re-denying requests. @@ -604,12 +497,8 @@ function tp.tpr_deny(name) -- Teleport requests if tp.tpr_list[name] then name2 = tp.tpr_list[name] - minetest.chat_send_player(name2, S("Teleport request denied.")) - minetest.chat_send_player(name, S("You denied the request @1 sent you.", name2)) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(name2), S("Teleport request denied."), 0xFFFFFF) - chat2.send_message(minetest.get_player_by_name(name), S("You denied the request @1 sent you.", name2), 0xFFFFFF) - end + send_message(name2, S("Teleport request denied.")) + send_message(name, S("You denied the request @1 sent you.", name2)) tp.tpr_list[name] = nil spam_prevention[name] = name2 @@ -619,12 +508,8 @@ function tp.tpr_deny(name) elseif tp.tphr_list[name] then name2 = tp.tphr_list[name] - minetest.chat_send_player(name2, S("Teleport request denied.")) - minetest.chat_send_player(name, S("You denied the request @1 sent you.", name2)) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(name2), S("Teleport request denied."), 0xFFFFFF) - chat2.send_message(minetest.get_player_by_name(name), S("You denied the request @1 sent you.", name2), 0xFFFFFF) - end + send_message(name2, S("Teleport request denied.")) + send_message(name, S("You denied the request @1 sent you.", name2)) tp.tphr_list[name] = nil spam_prevention[name] = name2 @@ -634,12 +519,8 @@ function tp.tpr_deny(name) elseif tp.tpn_list[name] then name2 = tp.tpn_list[name] - minetest.chat_send_player(name, S("You denied your request sent to @1.", name2)) - minetest.chat_send_player(name2, S("@1 denied their request sent to you.", name)) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(name), S("You denied your request sent to @1.", name2), 0xFFFFFF) - chat2.send_message(minetest.get_player_by_name(name2), S("@1 denied their request sent to you.", name), 0xFFFFFF) - end + send_message(name, S("You denied your request sent to @1.", name2)) + send_message(name2, S("@1 denied their request sent to you.", name)) if tp.tpr_list[name2] then tp.tpr_list[name2] = nil @@ -661,10 +542,7 @@ function tp.tpr_accept(name) -- Check to prevent constant teleporting if not tp.tpr_list[name] and not tp.tphr_list[name] and not tp.tpc_list[name] then - minetest.chat_send_player(name, S("Usage: /tpy allows you to accept teleport/area requests sent to you by other players.")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(name), S("Usage: /tpy allows you to accept teleport/area requests sent to you by other players."), 0xFFFFFF) - end + send_message(name, S("Usage: /tpy allows you to accept teleport/area requests sent to you by other players.")) return end @@ -683,11 +561,8 @@ function tp.tpr_accept(name) -- If source or target are not present, abort request. if not source or not target then - minetest.chat_send_player(name, S("@1 is not online right now.", name2)) + send_message(name, S("@1 is not online right now.", name2)) tp.tpc_list[name] = nil - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(name), S("@1 is not online right now.", name2), 0xFFFFFF) - end return end @@ -707,17 +582,11 @@ function tp.tpr_accept(name) tp.tpn_list[name2] = nil end - minetest.chat_send_player(name, chatmsg) - minetest.chat_send_player(name2, S("Request Accepted!")) + send_message(name, chatmsg) + send_message(name2, S("Request Accepted!")) -- Avoid abusing with area requests target_coords = nil - - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(name2), S("Request Accepted!"), 0xFFFFFF) - chat2.send_message(minetest.get_player_by_name(name), chatmsg, 0xFFFFFF) - return - end end -- Teleport requests. @@ -741,12 +610,9 @@ function tp.tpr_accept(name) -- Could happen if either player disconnects (or timeout); if so just abort if not source or not target then - minetest.chat_send_player(name, S("@1 is not online right now.", name2)) + send_message(name, S("@1 is not online right now.", name2)) tp.tpr_list[name] = nil tp.tphr_list[name] = nil - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(name), S("@1 is not online right now.", name2), 0xFFFFFF) - end return end @@ -761,24 +627,14 @@ function tp.tpr_accept(name) tp.tpn_list[name2] = nil end - minetest.chat_send_player(name, chatmsg) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(name), chatmsg, 0xFFFFFF) - end + send_message(name, chatmsg) if minetest.check_player_privs(name2, {tp_admin = true}) == false then - minetest.chat_send_player(name2, S("Request Accepted!")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(name2), S("Request Accepted!"), 0xFFFFFF) - end - + send_message(name2, S("Request Accepted!")) else if tp.enable_immediate_teleport then return end - minetest.chat_send_player(name2, S("Request Accepted!")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(name2), S("Request Accepted!"), 0xFFFFFF) - end + send_message(name2, S("Request Accepted!")) return end end @@ -786,26 +642,18 @@ end -- Teleport Jump - Relative Position Teleportation by number of nodes function tp.tpj(player, param) if param == "" then - minetest.chat_send_player(player, S("Usage: ")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(player), S("Usage: "), 0xFFFFFF) - end + send_message(player, S("Usage: ")) return false end local args = param:split(" ") -- look into this. Can it crash if the player does not have two parameters? if #args < 2 then - minetest.chat_send_player(player, S("Usage: ")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(player), S("Usage: "), 0xFFFFFF) - end + send_message(player, S("Usage: ")) return false end if not tonumber(args[2]) then - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(player), S("Not a number!"), 0xFFFFFF) - end + send_message(player, S("Not a number!")) return false, S("Not a number!") end @@ -818,18 +666,12 @@ function tp.tpj(player, param) elseif args[1] == "z" then target_coords["z"] = target_coords["z"] + tonumber(args[2]) else - minetest.chat_send_player(player, S("Not a valid axis. Valid options are X, Y or Z")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(player), S("Not a valid axis. Valid options are X, Y or Z"), 0xFFFFFF) - end + send_message(player, S("Not a valid axis. Valid options are X, Y or Z")) return end if tp.can_teleport(target_coords) == false then - minetest.chat_send_player(player, S("You cannot teleport to a location outside the map!")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(player), S("You cannot teleport to a location outside the map!"), 0xFFFFFF) - end + send_message(player, S("You cannot teleport to a location outside the map!")) return end tp.tpc_teleport_player(player) @@ -840,10 +682,7 @@ end -- Evade function tp.tpe(player) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(player), S("EVADE!"), 0xFFFFFF) - end - minetest.chat_send_player(player, S("EVADE!")) + send_message(player, S("EVADE!")) local mindistance = 15 local maxdistance = 50 local times = math.random(6,20) -- how many times to jump - minimum,maximum @@ -876,20 +715,14 @@ if tp.enable_tpp_command then local places = {} if not tp.available_places then tp.available_places = {} end for key, value in pairs(tp.available_places) do - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(player), key, 0xFFFFFF) - end + send_message(player, key) table.insert(places, key) end if #places == 0 then - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(player), S("There are no places yet."), 0xFFFFFF) - end + send_message(player, S("There are no places yet.")) return true, S("There are no places yet.") end - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(player), S("Usage: /tpp "), 0xFFFFFF) - end + send_message(player, S("Usage: /tpp ")) table.insert(places, S("Usage: /tpp ")) return true, table.concat(places, "\n") @@ -897,17 +730,11 @@ if tp.enable_tpp_command then elseif tp.available_places[param] then local pos = {x = tp.available_places[param].x, y = tp.available_places[param].y, z = tp.available_places[param].z} tp.tpp_teleport_player(player, pos) - minetest.chat_send_player(player, S("Teleporting to @1.", param)) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(player), S("Teleporting to @1.", param), 0xFFFFFF) - end + send_message(player, S("Teleporting to @1.", param)) -- Check if the place exists. elseif not tp.available_places[param] then - minetest.chat_send_player(player, S("There is no place by that name. Keep in mind this is case-sensitive.")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(player), S("There is no place by that name. Keep in mind this is case-sensitive."), 0xFFFFFF) - end + send_message(player, S("There is no place by that name. Keep in mind this is case-sensitive.")) return end end diff --git a/settingtypes.txt b/settingtypes.txt index f133649..4cbdd5d 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -1,6 +1,9 @@ # Timeout delay (default is 60) tp.timeout_delay (Timeout delay after a request is sent) int 60 +# Message color (default is #FFFFFF) +tp.message_color (The color of the messages sent to players by this mod) string #FFFFFF + # Enables immediate teleport to players for those who have tp_admin privilege (enabled by default) tp.enable_immediate_teleport (Immediate teleport for those with tp_admin privilege) bool true From 18cba12412f2dc6fbeb29615f2ba161c7c2c369d Mon Sep 17 00:00:00 2001 From: Oversword Date: Sun, 8 Aug 2021 22:01:18 +0100 Subject: [PATCH 05/11] No need to specify it's mod specific --- settingtypes.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settingtypes.txt b/settingtypes.txt index 4cbdd5d..754f505 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -2,7 +2,7 @@ tp.timeout_delay (Timeout delay after a request is sent) int 60 # Message color (default is #FFFFFF) -tp.message_color (The color of the messages sent to players by this mod) string #FFFFFF +tp.message_color (The color of the messages sent to players) string #FFFFFF # Enables immediate teleport to players for those who have tp_admin privilege (enabled by default) tp.enable_immediate_teleport (Immediate teleport for those with tp_admin privilege) bool true From e4da8605c2df554f7963e8c92e81397b6ffecfc2 Mon Sep 17 00:00:00 2001 From: Oversword Date: Mon, 9 Aug 2021 01:44:48 +0100 Subject: [PATCH 06/11] Allow selection from multiple requests --- commands.lua | 6 + functions.lua | 479 ++++++++++++++++++++++++++++++++------------------ 2 files changed, 317 insertions(+), 168 deletions(-) diff --git a/commands.lua b/commands.lua index fd9ff76..6d3cf8b 100644 --- a/commands.lua +++ b/commands.lua @@ -67,6 +67,12 @@ minetest.register_chatcommand("tpn", { func = tp.tpr_deny }) +minetest.register_chatcommand("tpf", { + description = S("Show all teleport requests, made by you or to you, that are still active"), + privs = {interact = true, tp = true}, + func = tp.list_requests +}) + minetest.register_chatcommand("tpr_mute", { description = S("Mutes a player: denies them from sending you teleport requests"), params = S(" | leave playername empty to see help message"), diff --git a/functions.lua b/functions.lua index 624919b..0c7a640 100644 --- a/functions.lua +++ b/functions.lua @@ -22,7 +22,7 @@ USA local S = tp.intllib -- Placeholders -local chatmsg, source, target, name2, +local chatmsg, source, target, target_coords, tpc_target_coords, old_tpc_target_coords local spam_prevention = {} @@ -56,6 +56,276 @@ local function send_message(player, message) end end + +local request_id = 0 +local request_list = {} +local sender_list = {} +local receiver_list = {} + +function tp.make_request(sender, receiver, direction) + request_id = request_id+1 + request_list[request_id] = { + time = os.time(), + direction = direction or "receiver", + receiver = receiver, + sender = sender + } + + receiver_list[receiver] = receiver_list[receiver] or {count=0} + receiver_list[receiver][request_id] = true + receiver_list[receiver].count = receiver_list[receiver].count+1 + + sender_list[sender] = sender_list[sender] or {count=0} + sender_list[sender][request_id] = true + sender_list[sender].count = sender_list[sender].count+1 + + return request_id +end + +function tp.clear_request(id) + local request = request_list[id] + request_list[id] = nil + + sender_list[request.sender][id] = nil + receiver_list[request.receiver][id] = nil + + sender_list[request.sender].count = sender_list[request.sender].count-1 + receiver_list[request.receiver].count = receiver_list[request.receiver].count-1 + + return request +end + +function tp.accept_request(id) + + local request = tp.clear_request(id) + + if request.direction == "area" then + source = minetest.get_player_by_name(request.receiver) + target = minetest.get_player_by_name(request.sender) + chatmsg = S("@1 is teleporting to your protected area @2.", request.sender, minetest.pos_to_string(tpc_target_coords[request.receiver])) + -- If source or target are not present, abort request. + if not source or not target then + send_message(request.receiver, S("@1 is not online right now.", request.sender)) + return + end + if not tpc_target_coords[request.receiver] then + tpc_target_coords[request.sender] = old_tpc_target_coords[request.receiver] + tp.tpp_teleport_player(request.sender, tpc_target_coords[request.sender]) + + chatmsg = S("@1 is teleporting to your protected area @2.", request.sender, minetest.pos_to_string(tpc_target_coords[request.sender])) + else + tp.tpp_teleport_player(request.sender, tpc_target_coords[request.receiver]) + chatmsg = S("@1 is teleporting to your protected area @2.", request.sender, minetest.pos_to_string(tpc_target_coords[request.receiver])) + end + + send_message(request.receiver, chatmsg) + send_message(request.sender, S("Request Accepted!")) + + -- Avoid abusing with area requests + target_coords = nil + elseif request.direction == "receiver" then + source = minetest.get_player_by_name(request.receiver) + target = minetest.get_player_by_name(request.sender) + chatmsg = S("@1 is teleporting to you.", request.sender) + -- Could happen if either player disconnects (or timeout); if so just abort + if not source + or not target then + send_message(request.receiver, S("@1 is not online right now.", request.sender)) + return + end + + tp.tpr_teleport_player() + + -- Avoid abusing with area requests + target_coords = nil + + send_message(request.receiver, chatmsg) + + if minetest.check_player_privs(request.sender, {tp_admin = true}) == false then + send_message(request.sender, S("Request Accepted!")) + else + if tp.enable_immediate_teleport then return end + + send_message(request.sender, S("Request Accepted!")) + return + end + elseif request.direction == "sender" then + source = minetest.get_player_by_name(request.sender) + target = minetest.get_player_by_name(request.receiver) + chatmsg = S("You are teleporting to @1.", request.sender) + -- Could happen if either player disconnects (or timeout); if so just abort + if not source + or not target then + send_message(request.receiver, S("@1 is not online right now.", request.sender)) + return + end + + tp.tpr_teleport_player() + + -- Avoid abusing with area requests + target_coords = nil + + send_message(request.receiver, chatmsg) + + if minetest.check_player_privs(request.sender, {tp_admin = true}) == false then + send_message(request.sender, S("Request Accepted!")) + else + if tp.enable_immediate_teleport then return end + + send_message(request.sender, S("Request Accepted!")) + return + end + end + return request +end + +function tp.deny_request(id, own) + local request = tp.clear_request(id) + if own then + send_message(request.sender, S("You denied your request sent to @1.", request.receiver)) + send_message(request.receiver, S("@1 denied their request sent to you.", request.sender)) + else + if request.direction == "area" then + send_message(request.sender, S("Area request denied.")) + send_message(request.receiver, S("You denied the request @1 sent you.", request.sender)) + elseif request.direction == "receiver" then + send_message(request.sender, S("Teleport request denied.")) + send_message(request.receiver, S("You denied the request @1 sent you.", request.sender)) + spam_prevention[request.receiver] = request.sender + elseif request.direction == "sender" then + send_message(request.sender, S("Teleport request denied.")) + send_message(request.receiver, S("You denied the request @1 sent you.", request.sender)) + spam_prevention[request.receiver] = request.sender + end + end +end + +function tp.list_requests(playername) + local sent_requests = tp.get_requests(playername, "sender") + local received_requests = tp.get_requests(playername, "receiver") + + local formspec + if sent_requests.count == 0 and received_requests.count == 0 then + formspec = ("size[5,2]label[1,0.3;%s:]"):format(S("Teleport Requests")) + formspec = formspec..("label[1,1.2;%s]"):format(S("You have no requests.")) + else + local y = 1 + local request_list_formspec = "" + if sent_requests.count ~= 0 then + request_list_formspec = request_list_formspec..("label[0.2,%f;%s:]"):format(y, S("Sent by you")) + y = y+0.7 + for request_id, _ in pairs(sent_requests) do + if request_id ~= "count" then + local request = request_list[request_id] + if request.direction == "receiver" then + request_list_formspec = request_list_formspec..("label[0.3,%f;%s]button[7,%f;1,1;deny_%s;Cancel]") + :format( + y, tostring(os.time()-request.time).."s ago: "..S("You are requesting to teleport to @1.", request.receiver), + y, tostring(request_id) + ) + elseif request.direction == "sender" then + request_list_formspec = request_list_formspec..("label[0.3,%f;%s]button[7,%f;1,1;deny_%s;Cancel]") + :format( + y, tostring(os.time()-request.time).."s: "..S("You are requesting that @1 teleports to you.", request.receiver), + y, tostring(request_id) + ) + end + y = y+0.8 + end + end + end + if received_requests.count ~= 0 then + y = y+0.5 + request_list_formspec = request_list_formspec..("label[0.2,%f;%s:]"):format(y, S("Sent to you")) + y = y+0.7 + for request_id, _ in pairs(received_requests) do + if request_id ~= "count" then + local request = request_list[request_id] + if request.direction == "receiver" then + request_list_formspec = request_list_formspec..("label[0.3,%f;%s]button[6,%f;1,1;accept_%s;Accept]button[7,%f;1,1;deny_%s;Deny]") + :format( + y, tostring(os.time()-request.time).."s ago: "..S("@1 is requesting to teleport to you.", request.sender), + y, tostring(request_id), + y, tostring(request_id) + ) + elseif request.direction == "sender" then + request_list_formspec = request_list_formspec..("label[0.3,%f;%s]button[6,%f;1,1;accept_%s;Accept]button[7,%f;1,1;deny_%s;Deny]") + :format( + y, tostring(os.time()-request.time).."s ago: "..S("@1 is requesting that you teleport to them.", request.sender), + y, tostring(request_id), + y, tostring(request_id) + ) + end + y = y+0.8 + end + end + end + formspec = ("size[8,%f]label[1,0.3;%s:]"):format(math.min(y,10),S("Teleport Requests")) + ..request_list_formspec + end + minetest.show_formspec(playername, "teleport_request_list", formspec) +end + +minetest.register_on_player_receive_fields(function(player, formname, fields) + if formname ~= "teleport_request_list" then return end + + local playername = player:get_player_name() + + local accepts = {} + local denys = {} + for button_name, _ in pairs(fields) do + if string.sub(button_name, 1, 5) == "deny_" then + table.insert(denys, tonumber(string.sub(button_name, 6))) + elseif string.sub(button_name, 1, 7) == "accept_" then + table.insert(accepts, tonumber(string.sub(button_name, 8))) + end + end + for _, id in ipairs(accepts) do + if request_list[id] and request_list[id].receiver == playername then + tp.accept_request(id) + end + end + for _, id in ipairs(denys) do + if request_list[id] and (request_list[id].sender == playername or request_list[id].receiver == playername) then + tp.deny_request(id, request_list[id].sender == playername) + end + end + + tp.list_requests(playername) +end) + + +function tp.get_requests(playername, party) + local list + if party == "sender" then + list = sender_list + elseif party == "receiver" then + list = receiver_list + end + if not list then return end + + return list[playername] or {count=0} +end + +function tp.count_requests(playername, party) + local player_list = tp.get_requests(playername, party) + if not player_list then return 0 end + + return player_list.count or 0 +end + +function tp.first_request(playername, party) + local player_list = tp.get_requests(playername, party) + if not player_list then return end + + local request + for request_id, _ in pairs(player_list) do + if request_id ~= "count" then + return request_id + end + end +end + 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 @@ -265,21 +535,18 @@ function tp.tpr_send(sender, receiver) send_message(receiver, S("@1 is requesting to teleport to you. /tpy to accept.", sender)) send_message(sender, S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay)) - -- Write name values to list and clear old values. - tp.tpr_list[receiver] = sender - tp.tpn_list[sender] = receiver + local tp_id = tp.make_request(sender, receiver, "sender") -- Teleport timeout delay - minetest.after(tp.timeout_delay, function(sender_name, receiver_name) - if tp.tpr_list[receiver_name] and tp.tpn_list[sender_name] then - tp.tpr_list[receiver_name] = nil - tp.tpn_list[sender_name] = nil + minetest.after(tp.timeout_delay, function(id) + if request_list[id] then + local request = tp.clear_request(id) - send_message(sender_name, S("Request timed-out.")) - send_message(receiver_name, S("Request timed-out.")) + send_message(request.sender, S("Request timed-out.")) + send_message(request.receiver, S("Request timed-out.")) return end - end, sender, receiver) + end, tp_id) end end @@ -372,22 +639,18 @@ function tp.tphr_send(sender, receiver) send_message(receiver, S("@1 is requesting that you teleport to them. /tpy to accept; /tpn to deny.", sender)) send_message(sender, S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay)) - -- Write name values to list and clear old values. - tp.tphr_list[receiver] = sender - tp.tpn_list[sender] = receiver + local tp_id = tp.make_request(sender, receiver, "receiver") -- Teleport timeout delay + minetest.after(tp.timeout_delay, function(id) + if request_list[id] then + local request = tp.clear_request(id) - minetest.after(tp.timeout_delay, function(sender_name, receiver_name) - if tp.tphr_list[receiver_name] and tp.tpn_list[sender_name] then - tp.tphr_list[receiver_name] = nil - tp.tpn_list[sender_name] = nil - - send_message(sender_name, S("Request timed-out.")) - send_message(receiver_name, S("Request timed-out.")) + send_message(request.sender, S("Request timed-out.")) + send_message(request.receiver, S("Request timed-out.")) return end - end, sender, receiver) + end, tp_id) end end @@ -442,19 +705,17 @@ function tp.tpc_send(sender, coordinates) send_message(area.owner, S("@1 is requesting to teleport to a protected area" .. " of yours @2.", sender, minetest.pos_to_string(tpc_target_coords[area.owner]))) - tp.tpc_list[area.owner] = sender - tp.tpn_list[sender] = area.owner + local tp_id = tp.make_request(sender, area.owner, "area") - minetest.after(tp.timeout_delay, function(sender_name, receiver_name) - if tp.tpc_list[receiver_name] and tp.tpn_list[sender_name] then - tp.tpc_list[receiver_name] = nil - tp.tpn_list[sender_name] = nil + minetest.after(tp.timeout_delay, function(id) + if request_list[id] then + local request = tp.clear_request(id) - send_message(sender_name, S("Request timed-out.")) - send_message(receiver_name, S("Request timed-out.")) + send_message(request.sender, S("Request timed-out.")) + send_message(request.receiver, S("Request timed-out.")) return end - end, sender, area.owner) + end, tp_id) else minetest.record_protection_violation(target_coords, sender) end @@ -476,63 +737,26 @@ function tp.tpc_send(sender, coordinates) end function tp.tpr_deny(name) - if not tp.tpr_list[name] and not tp.tphr_list[name] - and not tp.tpc_list[name] and not tp.tpn_list[name] then + if tp.count_requests(name, "sender") == 0 and tp.count_requests(name, "receiver") == 0 then send_message(name, S("Usage: /tpn allows you to deny teleport/area requests sent to you by other players.")) return end - -- Area requests - if tp.tpc_list[name] then - name2 = tp.tpc_list[name] - send_message(name2, S("Area request denied.")) - send_message(name, S("You denied the request @1 sent you.", name2)) - tp.tpc_list[name] = nil - - -- Don't allow re-denying requests. - tp.tpn_list[name2] = nil + if (tp.count_requests(name, "sender") + tp.count_requests(name, "receiver")) > 1 then + -- Show formspec for decision + tp.list_requests(name) return end - -- Teleport requests - if tp.tpr_list[name] then - name2 = tp.tpr_list[name] - send_message(name2, S("Teleport request denied.")) - send_message(name, S("You denied the request @1 sent you.", name2)) - - tp.tpr_list[name] = nil - spam_prevention[name] = name2 - - -- Don't allow re-denying requests. - tp.tpn_list[name2] = nil - - elseif tp.tphr_list[name] then - name2 = tp.tphr_list[name] - send_message(name2, S("Teleport request denied.")) - send_message(name, S("You denied the request @1 sent you.", name2)) - - tp.tphr_list[name] = nil - spam_prevention[name] = name2 - - -- Don't allow re-denying requests. - tp.tpn_list[name2] = nil - - elseif tp.tpn_list[name] then - name2 = tp.tpn_list[name] - send_message(name, S("You denied your request sent to @1.", name2)) - send_message(name2, S("@1 denied their request sent to you.", name)) - - if tp.tpr_list[name2] then - tp.tpr_list[name2] = nil - - elseif tp.tphr_list[name2] then - tp.tphr_list[name2] = nil - - elseif tp.tpc_list[name2] then - tp.tpc_list[name2] = nil - end + local received_request = tp.first_request(name, "receiver") + if received_request then + tp.deny_request(received_request, false) + return + end - tp.tpn_list[name] = nil + local sent_request = tp.first_request(name, "sender") + if sent_request then + tp.deny_request(sent_request, true) return end end @@ -540,103 +764,22 @@ end -- Teleport Accept Systems function tp.tpr_accept(name) -- Check to prevent constant teleporting - if not tp.tpr_list[name] and not tp.tphr_list[name] - and not tp.tpc_list[name] then + if tp.count_requests(name, "receiver") == 0 then send_message(name, S("Usage: /tpy allows you to accept teleport/area requests sent to you by other players.")) return end - -- Area requests - if tp.tpc_list[name] then - - if tp.tpc_list[name] then - name2 = tp.tpc_list[name] - source = minetest.get_player_by_name(name) - target = minetest.get_player_by_name(name2) - chatmsg = S("@1 is teleporting to your protected area @2.", name2, minetest.pos_to_string(tpc_target_coords[name])) - tp.tpc_list[name] = nil - else - return - end - - -- If source or target are not present, abort request. - if not source or not target then - send_message(name, S("@1 is not online right now.", name2)) - tp.tpc_list[name] = nil - return - end - - if not tpc_target_coords[name] then - tpc_target_coords[name2] = old_tpc_target_coords[name] - tp.tpp_teleport_player(name2, tpc_target_coords[name2]) - - chatmsg = S("@1 is teleporting to your protected area @2.", name2, minetest.pos_to_string(tpc_target_coords[name2])) - else - tp.tpp_teleport_player(name2, tpc_target_coords[name]) - chatmsg = S("@1 is teleporting to your protected area @2.", name2, minetest.pos_to_string(tpc_target_coords[name])) - end - - -- Don't allow re-denying requests. - if tp.tpn_list[name] or tp.tpn_list[name2] then - tp.tpn_list[name] = nil - tp.tpn_list[name2] = nil - end - - send_message(name, chatmsg) - send_message(name2, S("Request Accepted!")) - - -- Avoid abusing with area requests - target_coords = nil - end - - -- Teleport requests. - if tp.tpr_list[name] then - name2 = tp.tpr_list[name] - source = minetest.get_player_by_name(name) - target = minetest.get_player_by_name(name2) - chatmsg = S("@1 is teleporting to you.", name2) - tp.tpr_list[name] = nil - - elseif tp.tphr_list[name] then - name2 = tp.tphr_list[name] - source = minetest.get_player_by_name(name2) - target = minetest.get_player_by_name(name) - chatmsg = S("You are teleporting to @1.", name2) - tp.tphr_list[name] = nil - else - return - end - - -- Could happen if either player disconnects (or timeout); if so just abort - if not source - or not target then - send_message(name, S("@1 is not online right now.", name2)) - tp.tpr_list[name] = nil - tp.tphr_list[name] = nil + if tp.count_requests(name, "receiver") > 1 then + -- Show formspec for decision + tp.list_requests(name) return end - tp.tpr_teleport_player() + local received_request = tp.first_request(name, "receiver") - -- Avoid abusing with area requests - target_coords = nil - - -- Don't allow re-denying requests. - if tp.tpn_list[name] or tp.tpn_list[name2] then - tp.tpn_list[name] = nil - tp.tpn_list[name2] = nil - end - - send_message(name, chatmsg) + if not received_request then return end -- This shouldn't happen, but who knows - if minetest.check_player_privs(name2, {tp_admin = true}) == false then - send_message(name2, S("Request Accepted!")) - else - if tp.enable_immediate_teleport then return end - - send_message(name2, S("Request Accepted!")) - return - end + tp.accept_request(received_request) end -- Teleport Jump - Relative Position Teleportation by number of nodes From 26593c3057e84a7974ae406e6ac28f2d85541892 Mon Sep 17 00:00:00 2001 From: Oversword Date: Mon, 23 Aug 2021 20:47:03 +0100 Subject: [PATCH 07/11] Fix teleport direction and admin tpr --- functions.lua | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/functions.lua b/functions.lua index 1290d0d..2a7a3a3 100644 --- a/functions.lua +++ b/functions.lua @@ -508,9 +508,8 @@ function tp.tpr_send(sender, receiver) return end - tp.tpr_list[receiver] = sender - tp.tpr_accept(receiver) - send_message(sender, S("You are teleporting to @1.", receiver)) + local id = tp.make_request(sender, receiver, "receiver") + tp.accept_request(id) return end @@ -534,7 +533,7 @@ function tp.tpr_send(sender, receiver) send_message(receiver, S("@1 is requesting to teleport to you. /tpy to accept.", sender)) send_message(sender, S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay)) - local tp_id = tp.make_request(sender, receiver, "sender") + local tp_id = tp.make_request(sender, receiver, "receiver") -- Teleport timeout delay minetest.after(tp.timeout_delay, function(id) @@ -638,7 +637,7 @@ function tp.tphr_send(sender, receiver) send_message(receiver, S("@1 is requesting that you teleport to them. /tpy to accept; /tpn to deny.", sender)) send_message(sender, S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay)) - local tp_id = tp.make_request(sender, receiver, "receiver") + local tp_id = tp.make_request(sender, receiver, "sender") -- Teleport timeout delay minetest.after(tp.timeout_delay, function(id) From 71ac385c57d12705019cd05e54f233fa28355a92 Mon Sep 17 00:00:00 2001 From: Oversword Date: Mon, 23 Aug 2021 20:53:10 +0100 Subject: [PATCH 08/11] Linting, variable conflicts --- functions.lua | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/functions.lua b/functions.lua index 2a7a3a3..15ac772 100644 --- a/functions.lua +++ b/functions.lua @@ -56,14 +56,14 @@ local function send_message(player, message) end end -local request_id = 0 +local next_request_id = 0 local request_list = {} local sender_list = {} local receiver_list = {} function tp.make_request(sender, receiver, direction) - request_id = request_id+1 - request_list[request_id] = { + next_request_id = next_request_id+1 + request_list[next_request_id] = { time = os.time(), direction = direction or "receiver", receiver = receiver, @@ -71,14 +71,14 @@ function tp.make_request(sender, receiver, direction) } receiver_list[receiver] = receiver_list[receiver] or {count=0} - receiver_list[receiver][request_id] = true + receiver_list[receiver][next_request_id] = true receiver_list[receiver].count = receiver_list[receiver].count+1 sender_list[sender] = sender_list[sender] or {count=0} - sender_list[sender][request_id] = true + sender_list[sender][next_request_id] = true sender_list[sender].count = sender_list[sender].count+1 - return request_id + return next_request_id end function tp.clear_request(id) @@ -317,7 +317,6 @@ function tp.first_request(playername, party) local player_list = tp.get_requests(playername, party) if not player_list then return end - local request for request_id, _ in pairs(player_list) do if request_id ~= "count" then return request_id From efb27fdef4a4f77de05c8421cbdc53ffc38c8a0b Mon Sep 17 00:00:00 2001 From: Oversword Date: Tue, 31 Aug 2021 13:03:29 +0100 Subject: [PATCH 09/11] Ensure form is not re-displayed if quitting or if there are no changes --- functions.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/functions.lua b/functions.lua index 15ac772..96bc57a 100644 --- a/functions.lua +++ b/functions.lua @@ -279,18 +279,22 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) table.insert(accepts, tonumber(string.sub(button_name, 8))) end end + local changes = false for _, id in ipairs(accepts) do if request_list[id] and request_list[id].receiver == playername then tp.accept_request(id) + changes = true end end for _, id in ipairs(denys) do if request_list[id] and (request_list[id].sender == playername or request_list[id].receiver == playername) then tp.deny_request(id, request_list[id].sender == playername) + changes = true end end - - tp.list_requests(playername) + if chnages and not fields.quit then + tp.list_requests(playername) + end end) From b8de28d4680ddbb6cfc088b7b5365163a394b33f Mon Sep 17 00:00:00 2001 From: Oversword Date: Tue, 31 Aug 2021 13:18:44 +0100 Subject: [PATCH 10/11] Spelling --- functions.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions.lua b/functions.lua index 96bc57a..54f7f50 100644 --- a/functions.lua +++ b/functions.lua @@ -292,7 +292,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) changes = true end end - if chnages and not fields.quit then + if changes and not fields.quit then tp.list_requests(playername) end end) From 21b02debf7a9c7ee6a8cf2402ec93d2ec17cd7ae Mon Sep 17 00:00:00 2001 From: David Leal Date: Mon, 23 Oct 2023 13:01:11 -0600 Subject: [PATCH 11/11] Add area support --- functions.lua | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/functions.lua b/functions.lua index 54f7f50..dc7e2bb 100644 --- a/functions.lua +++ b/functions.lua @@ -60,6 +60,7 @@ local next_request_id = 0 local request_list = {} local sender_list = {} local receiver_list = {} +local area_list = {} function tp.make_request(sender, receiver, direction) next_request_id = next_request_id+1 @@ -187,6 +188,7 @@ function tp.deny_request(id, own) if request.direction == "area" then send_message(request.sender, S("Area request denied.")) send_message(request.receiver, S("You denied the request @1 sent you.", request.sender)) + spam_prevention[request.receiver] = request.sender elseif request.direction == "receiver" then send_message(request.sender, S("Teleport request denied.")) send_message(request.receiver, S("You denied the request @1 sent you.", request.sender)) @@ -202,9 +204,10 @@ end function tp.list_requests(playername) local sent_requests = tp.get_requests(playername, "sender") local received_requests = tp.get_requests(playername, "receiver") + local area_requests = tp.get_requests(playername, "area") local formspec - if sent_requests.count == 0 and received_requests.count == 0 then + if sent_requests.count == 0 and received_requests.count == 0 and area_requests.count == 0 then formspec = ("size[5,2]label[1,0.3;%s:]"):format(S("Teleport Requests")) formspec = formspec..("label[1,1.2;%s]"):format(S("You have no requests.")) else @@ -228,6 +231,12 @@ function tp.list_requests(playername) y, tostring(os.time()-request.time).."s: "..S("You are requesting that @1 teleports to you.", request.receiver), y, tostring(request_id) ) + elseif request.direction == "area" then + request_list_formspec = request_list_formspec..("label[0.3,%f;%s]button[7,%f;1,1;deny_%s;Cancel]") + :format( + y, tostring(os.time()-request.time).."s: "..S("You are requesting to teleport to @1's protected area.", request.receiver), + y, tostring(request_id) + ) end y = y+0.8 end @@ -254,6 +263,13 @@ function tp.list_requests(playername) y, tostring(request_id), y, tostring(request_id) ) + elseif request.direction == "area" then + request_list_formspec = request_list_formspec..("label[0.3,%f;%s]button[6,%f;1,1;accept_%s;Accept]button[7,%f;1,1;deny_%s;Deny]") + :format( + y, tostring(os.time()-request.time).."s ago: "..S("@1 is requesting to teleport to your protected area.", request.sender), + y, tostring(request_id), + y, tostring(request_id) + ) end y = y+0.8 end @@ -304,6 +320,10 @@ function tp.get_requests(playername, party) list = sender_list elseif party == "receiver" then list = receiver_list + elseif party == "area" then + list = area_list + else + return -- Invalid party end if not list then return end