From 0fcf5f16f44b0cdb5c26e8ef94caf200a7e971c5 Mon Sep 17 00:00:00 2001 From: y Date: Sun, 30 Jun 2019 22:26:20 +0100 Subject: [PATCH 1/5] allow elevator to build into any buildable node --- elevator.lua | 11 ++++++----- travelnet.lua | 12 ++++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/elevator.lua b/elevator.lua index a428845..f71cd14 100644 --- a/elevator.lua +++ b/elevator.lua @@ -106,11 +106,11 @@ minetest.register_node("travelnet:elevator", { fixed = { { 0.48, -0.5,-0.5, 0.5, 0.5, 0.5}, - {-0.5 , -0.5, 0.48, 0.48, 0.5, 0.5}, + {-0.5 , -0.5, 0.48, 0.48, 0.5, 0.5}, {-0.5, -0.5,-0.5 ,-0.48, 0.5, 0.5}, --groundplate to stand on - { -0.5,-0.5,-0.5,0.5,-0.48, 0.5}, + { -0.5,-0.5,-0.5,0.5,-0.48, 0.5}, }, }, @@ -128,7 +128,7 @@ minetest.register_node("travelnet:elevator", { meta:set_string("station_network",""); meta:set_string("owner", placer:get_player_name() ); -- request initial data - meta:set_string("formspec", + meta:set_string("formspec", "size[12,10]".. "field[0.3,5.6;6,0.7;station_name;"..S("Name of this station:")..";]".. -- "field[0.3,6.6;6,0.7;station_network;Assign to Network:;]".. @@ -140,7 +140,7 @@ minetest.register_node("travelnet:elevator", { minetest.add_node(p, {name="travelnet:elevator_top", paramtype2="facedir", param2=p2}) travelnet.show_nearest_elevator( pos, placer:get_player_name(), p2 ); end, - + on_receive_fields = travelnet.on_receive_fields, on_punch = function(pos, node, puncher) travelnet.update_formspec(pos, puncher:get_player_name()) @@ -162,8 +162,9 @@ minetest.register_node("travelnet:elevator", { on_place = function(itemstack, placer, pointed_thing) local pos = pointed_thing.above; local node = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}); + local def = minetest.registered_nodes[node.name] -- leftover elevator_top nodes can be removed by placing a new elevator underneath - if( node ~= nil and node.name ~= "air" and node.name ~= 'travelnet:elevator_top') then + if not def or not def.buildable_to then minetest.chat_send_player( placer:get_player_name(), S('Not enough vertical space to place the travelnet box!')) return; end diff --git a/travelnet.lua b/travelnet.lua index 9fba7fe..286bd2a 100644 --- a/travelnet.lua +++ b/travelnet.lua @@ -25,13 +25,13 @@ minetest.register_node("travelnet:travelnet", { fixed = { { 0.45, -0.5,-0.5, 0.5, 1.45, 0.5}, - {-0.5 , -0.5, 0.45, 0.45, 1.45, 0.5}, + {-0.5 , -0.5, 0.45, 0.45, 1.45, 0.5}, {-0.5, -0.5,-0.5 ,-0.45, 1.45, 0.5}, --groundplate to stand on - { -0.5,-0.5,-0.5,0.5,-0.45, 0.5}, + { -0.5,-0.5,-0.5,0.5,-0.45, 0.5}, --roof - { -0.5, 1.45,-0.5,0.5, 1.5, 0.5}, + { -0.5, 1.45,-0.5,0.5, 1.5, 0.5}, -- control panel -- { -0.2, 0.6, 0.3, 0.2, 1.1, 0.5}, @@ -52,7 +52,7 @@ minetest.register_node("travelnet:travelnet", { travelnet.reset_formspec( meta ); meta:set_string("owner", placer:get_player_name() ); end, - + on_receive_fields = travelnet.on_receive_fields, on_punch = function(pos, node, puncher) travelnet.update_formspec(pos, puncher:get_player_name(), nil) @@ -74,8 +74,8 @@ minetest.register_node("travelnet:travelnet", { on_place = function(itemstack, placer, pointed_thing) local pos = pointed_thing.above; - local def = minetest.registered_nodes[ - minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}).name] + local node = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}) + local def = minetest.registered_nodes[node.name] if not def or not def.buildable_to then minetest.chat_send_player( placer:get_player_name(), S('Not enough vertical space to place the travelnet box!')) From 45acadea670c01413085017d6d9729548cb84fb4 Mon Sep 17 00:00:00 2001 From: luk3yx Date: Thu, 12 Dec 2019 19:48:15 +1300 Subject: [PATCH 2/5] Fix crash when invalid formspec sent by clients --- init.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/init.lua b/init.lua index edc083e..c492f6c 100644 --- a/init.lua +++ b/init.lua @@ -123,7 +123,7 @@ end travelnet.restore_data = function() - + local file = io.open( travelnet.mod_data_path, "r" ); if( not file ) then print(S("[Mod travelnet] Error: Savefile '%s' not found.") @@ -204,7 +204,8 @@ end -- (back from help page, moved travelnet up or down etc.) travelnet.form_input_handler = function( player, formname, fields) if(formname == "travelnet:show" and fields and fields.pos2str) then - local pos = minetest.string_to_pos( fields.pos2str ); + local pos = minetest.string_to_pos( fields.pos2str ) + if not pos then return end if( locks and (fields.locks_config or fields.locks_authorize)) then return locks:lock_handle_input( pos, formname, fields, player ) end @@ -843,7 +844,7 @@ travelnet.on_receive_fields = function(pos, formname, fields, player) local target_pos = travelnet.targets[ owner_name ][ station_network ][ fields.target ].pos; player:move_to( target_pos, false); - if( travelnet.travelnet_effect_enabled ) then + if( travelnet.travelnet_effect_enabled ) then minetest.add_entity( {x=target_pos.x,y=target_pos.y+0.5,z=target_pos.z}, "travelnet:effect"); -- it self-destructs after 20 turns end From c1e5ae5b19933a431b0fb4aced758f13e35bef2f Mon Sep 17 00:00:00 2001 From: flux <25628292+fluxionary@users.noreply.github.com> Date: Tue, 28 Jan 2020 17:36:28 +0000 Subject: [PATCH 3/5] fix mod.conf --- mod.conf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mod.conf b/mod.conf index 49fcb68..badf3ef 100644 --- a/mod.conf +++ b/mod.conf @@ -1 +1,3 @@ name = travelnet +description = Network of teleporter-boxes that allow easy travelling to other boxes on the same network. +optional_depends = areas, intllib, mesecons From 9d7c9c109e6dc7bb1a3800f7982f7190cd1ecf6d Mon Sep 17 00:00:00 2001 From: flux <25628292+fluxionary@users.noreply.github.com> Date: Tue, 28 Jan 2020 17:36:51 +0000 Subject: [PATCH 4/5] prevent players from removing unowned travelnets in areas they don't control --- init.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/init.lua b/init.lua index c492f6c..037d46a 100644 --- a/init.lua +++ b/init.lua @@ -716,6 +716,13 @@ travelnet.on_receive_fields = function(pos, formname, fields, player) return end + if minetest.get_modpath("areas") and areas.canInteract then + if owner ~= name and not areas:canInteract(pos, name) then + minetest.chat_send_player(name, S("You cannot remove this travelnet from an area you don't control")) + return + end + end + local pinv = player:get_inventory() if(not(pinv:room_for_item("main", node.name))) then minetest.chat_send_player(name, S("You do not have enough room in your inventory.")); From 7408ad02b04b2e9f6eae54fed144b44ef93f305a Mon Sep 17 00:00:00 2001 From: flux <25628292+fluxionary@users.noreply.github.com> Date: Tue, 28 Jan 2020 17:58:18 +0000 Subject: [PATCH 5/5] prevent players from messing w/ unconfigured elevators in areas they don't control --- init.lua | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/init.lua b/init.lua index 037d46a..8928d8d 100644 --- a/init.lua +++ b/init.lua @@ -282,6 +282,13 @@ travelnet.update_formspec = function( pos, puncher_name, fields ) if( is_elevator == true ) then + if minetest.get_modpath("areas") and areas.canInteract then + if owner_name ~= puncher_name and not areas:canInteract(pos, puncher_name) then + minetest.chat_send_player(puncher_name, S("You cannot configure an elevator in an area you don't control")) + return + end + end + travelnet.add_target( nil, nil, pos, puncher_name, meta, owner_name ); return; end @@ -738,12 +745,14 @@ travelnet.on_receive_fields = function(pos, formname, fields, player) return; end - - - -- if the box has not been configured yet if( meta:get_string("station_network")=="" ) then - + if minetest.get_modpath("areas") and areas.canInteract then + if fields.owner ~= name and not areas:canInteract(pos, name) then + minetest.chat_send_player(name, S("You cannot configure in an area you don't control")) + return + end + end travelnet.add_target( fields.station_name, fields.station_network, pos, name, meta, fields.owner ); return; end