From fae093dfadd018124bdca91dc502f771843ea260 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Sun, 5 Oct 2014 01:37:10 +0200 Subject: [PATCH] added optional self-healing feature via abm in case of loss of savedata; version switched to 2.2 --- config.lua | 2 ++ init.lua | 20 +++++++++++++++++--- restore_network_via_abm.lua | 24 ++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 restore_network_via_abm.lua diff --git a/config.lua b/config.lua index 6708ecb..7673833 100644 --- a/config.lua +++ b/config.lua @@ -15,6 +15,8 @@ travelnet.elevator_enabled = true; -- if you set this to false, doors will be disabled travelnet.doors_enabled = true; +-- starts an abm which re-adds travelnet stations to networks in case the savefile got lost +travelnet.abm_enabled = false; -- change these if you want other receipes for travelnet or elevator travelnet.travelnet_recipe = { diff --git a/init.lua b/init.lua index dec181f..0a58c91 100644 --- a/init.lua +++ b/init.lua @@ -17,11 +17,15 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - Version: 2.1 (with config file) + Version: 2.2 (with optional abm for self-healing) Please configure this mod in config.lua Changelog: + 05.11.14 - Added an optional abm so that the travelnet network can heal itshelf in case of loss of the savefile. + If you want to use this, set + travelnet.enable_abm = true + in config.lua and edit the interval in the abm to suit your needs. 19.11.13 - moved doors and travelnet definition into an extra file - moved configuration to config.lua 05.08.13 - fixed possible crash when the node in front of the travelnet is unknown @@ -463,11 +467,17 @@ travelnet.on_receive_fields = function(pos, formname, fields, player) or not( travelnet.targets[ owner_name ][ station_network ] )) then - minetest.chat_send_player(name, "Error: There is something wrong with the configuration of this station. ".. + if( owner_name + and station_name + and station_network ) then + travelnet.add_target( station_name, station_network, pos, owner_name, meta, owner_name ); + else + minetest.chat_send_player(name, "Error: There is something wrong with the configuration of this station. ".. " DEBUG DATA: owner: "..( owner_name or "?").. " station_name: "..(station_name or "?").. " station_network: "..(station_network or "?").."."); - return + return + end end local this_node = minetest.env:get_node( pos ); @@ -664,6 +674,10 @@ if( travelnet.doors_enabled ) then dofile(minetest.get_modpath("travelnet").."/doors.lua"); -- doors that open and close automaticly when the travelnet or elevator is used end +if( travelnet.abm_enabled ) then + dofile(minetest.get_modpath("travelnet").."/restore_network_via_abm.lua"); -- restore travelnet data when players pass by broken networks +end -- upon server start, read the savefile travelnet.restore_data(); + diff --git a/restore_network_via_abm.lua b/restore_network_via_abm.lua new file mode 100644 index 0000000..3bd1dda --- /dev/null +++ b/restore_network_via_abm.lua @@ -0,0 +1,24 @@ + +minetest.register_abm({ + nodenames = {"travelnet:travelnet"}, + interval = 20, + chance = 1, + action = function(pos, node) + local meta = minetest.get_meta( pos ); + + local owner_name = meta:get_string( "owner" ); + local station_name = meta:get_string( "station_name" ); + local station_network = meta:get_string( "station_network" ); + + if( owner_name and station_name and station_network + and ( not( travelnet.targets ) + or not( travelnet.targets[ owner_name ] ) + or not( travelnet.targets[ owner_name ][ station_network ] ) + or not( travelnet.targets[ owner_name ][ station_network ][ station_name ] ))) then + + travelnet.add_target( station_name, station_network, pos, owner_name, meta, owner_name ); + print( 'TRAVELNET: re-adding '..tostring( station_name )..' to '..tostring( station_network )..' owned by '..tostring( owner_name )); + end + end +}) +