diff --git a/CHANGES.txt b/CHANGES.txt index 4cbab4e..5b58660 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -14,4 +14,7 @@ Changes by Piezo_: Added permissions "msp_admin", which allows full control and access to all portals, and "msp_unlimited", which bypasses the portal cap. Portals and all associated nodes are now fully protection-aware. Reorganized/Split up files - Position and rotation relative to the portal are now maintained, making travel feel smoother. \ No newline at end of file + Position and rotation relative to the portal are now maintained, making travel feel smoother. + +Changes by SpaghettiToastBook: + Added meseportals.can_connect \ No newline at end of file diff --git a/meseportal_gui.lua b/meseportal_gui.lua index c1ca288..639c2f8 100644 --- a/meseportal_gui.lua +++ b/meseportal_gui.lua @@ -69,6 +69,12 @@ meseportals.searchportals = function(pos, player_name, isAdmin) end +-- Mods can override this to restict portal connections. +-- Admins ignore this. +meseportals.can_connect = function(src_portal, dest_portal) + return dest_portal["destination"] == nil, "Destination portal is busy." +end + --show formspec to player meseportals.portalFormspecHandler = function(pos, _, clicker, _) if (meseportals.findPortal(pos) ~= nil) then @@ -412,7 +418,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) if meseportals.findPortal(current_portal["destination"]) then local dest_portal = meseportals.findPortal(current_portal["destination"]) - if dest_portal["destination"] == nil or isAdmin then + local can_connect, fail_reason = meseportals.can_connect(table.copy(current_portal), table.copy(dest_portal)) + if can_connect or isAdmin then dest_portal.admin_lock = current_portal.admin_lock -- Connecting to a portal, its locked state becomes the same as this portal. if dest_portal["destination"] then --Admin can interrupt any existing connection @@ -425,7 +432,12 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) meseportals.activatePortal (dest_portal.pos) current_portal["time"] = meseportals.close_after else - minetest.chat_send_player(player_name, "Connection failed: Portal is busy.") + if fail_reason then + minetest.chat_send_player(player_name, "Connection failed: " .. fail_reason) + else + minetest.chat_send_player(player_name, "Connection failed.") + end + meseportals.deactivatePortal (current_portal["pos"]) end else