From 82987b1a4f74074088a414d90898ad19ec8c4b20 Mon Sep 17 00:00:00 2001 From: Maverick2797 Date: Fri, 25 Nov 2022 18:38:10 +0800 Subject: small security fixes in advtrains_luaautomation/ - fixed file permissions of advtrains_luaautomation/README.md (755->644) - fixed file permissions of advtrains_luaautomation/environment.lua (755->644) - prevented LuaATC section_occupancy() from having direct access to the interlocking section id occupancy table - simplify section_occupancy() logic --- advtrains_luaautomation/environment.lua | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) mode change 100755 => 100644 advtrains_luaautomation/environment.lua (limited to 'advtrains_luaautomation/environment.lua') diff --git a/advtrains_luaautomation/environment.lua b/advtrains_luaautomation/environment.lua old mode 100755 new mode 100644 index 6b1a283..d85bedc --- a/advtrains_luaautomation/environment.lua +++ b/advtrains_luaautomation/environment.lua @@ -229,11 +229,8 @@ if advtrains.interlocking then if not ts_id then return nil end ts_id = tostring(ts_id) local response = advtrains.interlocking.db.get_ts(ts_id) - if response == nil then - return false - else - return response.trains - end + if not response then return false end + return table.copy(response.trains) end end -- cgit v1.2.3 From 2ea4a8cff1d8e335fda472e4c7988424ca522610 Mon Sep 17 00:00:00 2001 From: orwell Date: Tue, 6 Feb 2024 23:06:38 +0100 Subject: Add chatcommand and luaatc function to get global_slowdown --- advtrains/init.lua | 10 ++++++++++ advtrains_luaautomation/environment.lua | 3 +++ 2 files changed, 13 insertions(+) (limited to 'advtrains_luaautomation/environment.lua') diff --git a/advtrains/init.lua b/advtrains/init.lua index 9c977eb..cc8f8d1 100644 --- a/advtrains/init.lua +++ b/advtrains/init.lua @@ -758,6 +758,16 @@ minetest.register_chatcommand("at_disable_step", end, }) +minetest.register_chatcommand("at_status", + { + params = "", + description = "Print advtrains status info", + privs = {train_operator = true}, + func = function(name, param) + return true, advtrains.print_concat_table({"Advtrains Status: no_action",no_action,"slowdown",advtrains.global_slowdown,"(log",math.log(advtrains.global_slowdown),")"}) + end, +}) + advtrains.is_no_action = function() return no_action end diff --git a/advtrains_luaautomation/environment.lua b/advtrains_luaautomation/environment.lua index d85bedc..9fcba1d 100644 --- a/advtrains_luaautomation/environment.lua +++ b/advtrains_luaautomation/environment.lua @@ -164,6 +164,9 @@ local static_env = { return false end end, + get_slowdown = function() + return advtrains.global_slowdown + end } -- If interlocking is present, enable route setting functions -- cgit v1.2.3 From b28ceaa2b48f39855183b982c9668d0154a626df Mon Sep 17 00:00:00 2001 From: gpcf Date: Sun, 14 May 2023 19:48:30 +0200 Subject: Add register_function command so mods can register their own functons, low-level interface for departure boards --- advtrains_luaautomation/environment.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'advtrains_luaautomation/environment.lua') diff --git a/advtrains_luaautomation/environment.lua b/advtrains_luaautomation/environment.lua index 9fcba1d..6df5248 100644 --- a/advtrains_luaautomation/environment.lua +++ b/advtrains_luaautomation/environment.lua @@ -262,6 +262,11 @@ if advtrains.lines then } end + +atlatc.register_function = function (name, f) + static_env[name] = f +end + for _, name in pairs(safe_globals) do static_env[name] = _G[name] end -- cgit v1.2.3 From 7c4f1377e452134ab9e4addd0f01360dfa72564a Mon Sep 17 00:00:00 2001 From: Blockhead Date: Wed, 5 Jun 2024 04:09:04 +1000 Subject: Fix section_occupancy: Return empty table Fixes the functioning of the LuaATC function section_occupancy in the presence of no trains. Currently, if there is no train in the section, advtrains.interlocking.db.get_ts will return a table with a nil entry. When that nil value is passed to table.copy, Minetest throws out an error. Instead of passing nil to table.copy, just make a new empty table. --- advtrains_luaautomation/environment.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'advtrains_luaautomation/environment.lua') diff --git a/advtrains_luaautomation/environment.lua b/advtrains_luaautomation/environment.lua index 6df5248..761e227 100644 --- a/advtrains_luaautomation/environment.lua +++ b/advtrains_luaautomation/environment.lua @@ -233,7 +233,7 @@ if advtrains.interlocking then ts_id = tostring(ts_id) local response = advtrains.interlocking.db.get_ts(ts_id) if not response then return false end - return table.copy(response.trains) + return (response.trains and table.copy(response.trains)) or {} end end -- cgit v1.2.3 From 216f28e51aa3f8fea78f4fc054cb1071f3a9ce72 Mon Sep 17 00:00:00 2001 From: Maverick2797 Date: Tue, 7 May 2024 20:58:26 +0800 Subject: Fix set_aspect() Actually send aspect to advtrains.interlocking.signal_set_aspect() from LuaATC set_aspect() --- advtrains_luaautomation/environment.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'advtrains_luaautomation/environment.lua') diff --git a/advtrains_luaautomation/environment.lua b/advtrains_luaautomation/environment.lua index 761e227..ee7628d 100644 --- a/advtrains_luaautomation/environment.lua +++ b/advtrains_luaautomation/environment.lua @@ -224,7 +224,7 @@ if advtrains.interlocking then end static_env.set_aspect = function(signal, asp) local pos = atlatc.pcnaming.resolve_pos(signal) - return advtrains.interlocking.signal_set_aspect(pos) + return advtrains.interlocking.signal_set_aspect(pos,asp) end --section_occupancy() -- cgit v1.2.3 From 852e2f4219c4e7a9bebf7b27bb1c026f98719f97 Mon Sep 17 00:00:00 2001 From: Maverick2797 Date: Fri, 30 Aug 2024 17:25:01 +0800 Subject: LuaATC add trainparts(train_id) Returns a copy of the trainparts table to allow tracking individual wagon ids Also fixed a couple of file permissions from previous commits --- advtrains_luaautomation/README.md | 3 +++ advtrains_luaautomation/environment.lua | 6 ++++++ advtrains_luaautomation/operation_panel.lua | 0 3 files changed, 9 insertions(+) mode change 100755 => 100644 advtrains_luaautomation/operation_panel.lua (limited to 'advtrains_luaautomation/environment.lua') diff --git a/advtrains_luaautomation/README.md b/advtrains_luaautomation/README.md index 0bf56bb..f98f7a0 100644 --- a/advtrains_luaautomation/README.md +++ b/advtrains_luaautomation/README.md @@ -93,6 +93,9 @@ Removes any pending interrupts of this node. Make this active component send a digiline message on the specified channel. Not available in init code. + - `trainparts(train_id)` + returns a table with the ids of the cars the train is composed of, or false if `train_id` is invalid. `train_id` can be replaced with `atc_id` when used in LuaATC Rails. + - `atc_send_to_train(, )` Sends the specified ATC command to the train specified by its train id. This happens regardless of where the train is in the world, and can be used to remote-control trains. Returns true on success. If the train ID does not exist, returns false and does nothing. See [atc_command.txt](../atc_command.txt) for the ATC command syntax. diff --git a/advtrains_luaautomation/environment.lua b/advtrains_luaautomation/environment.lua index ee7628d..b54d45c 100644 --- a/advtrains_luaautomation/environment.lua +++ b/advtrains_luaautomation/environment.lua @@ -153,6 +153,12 @@ local static_env = { local pos=atlatc.pcnaming.resolve_pos(parpos, "interrupt_pos") atlatc.interrupt.add(0, pos, {type="ext_int", ext_int=true, message=imesg}) end, + train_parts = function(train_id) + if not train_id then return false end + local train = advtrains.trains[train_id] + if not train then return false end + return table.copy(train.trainparts or {}) + end, -- sends an atc command to train regardless of where it is in the world atc_send_to_train = function(train_id, command) assertt(command, "string") diff --git a/advtrains_luaautomation/operation_panel.lua b/advtrains_luaautomation/operation_panel.lua old mode 100755 new mode 100644 -- cgit v1.2.3 From 8c91ce1ec178d6d49f3ddefc57d99eecd0caef3c Mon Sep 17 00:00:00 2001 From: orwell Date: Thu, 9 Jan 2025 00:57:32 +0100 Subject: Various bugfixes found in lunixforks debug --- advtrains/occupation.lua | 4 ++-- advtrains/trainlogic.lua | 4 ++-- advtrains/wagons.lua | 2 +- advtrains_interlocking/database.lua | 9 +++++---- advtrains_interlocking/route_ui.lua | 2 +- advtrains_interlocking/routesetting.lua | 9 ++++++--- advtrains_interlocking/signal_api.lua | 1 + advtrains_interlocking/tcb_ts_ui.lua | 5 ++++- advtrains_luaautomation/environment.lua | 10 +++++++--- 9 files changed, 29 insertions(+), 17 deletions(-) (limited to 'advtrains_luaautomation/environment.lua') diff --git a/advtrains/occupation.lua b/advtrains/occupation.lua index 26e1f79..20a986e 100644 --- a/advtrains/occupation.lua +++ b/advtrains/occupation.lua @@ -89,8 +89,8 @@ function o.set_item(train_id, pos, idx) assert(idx) local i = 1 while t[i] do - if t[i]==train_id and t[i+1]==index then - break + if t[i]==train_id and t[i+1]==idx then + return end i = i + 2 end diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua index e4939df..0e588c7 100644 --- a/advtrains/trainlogic.lua +++ b/advtrains/trainlogic.lua @@ -630,7 +630,7 @@ function advtrains.train_step_b(id, train, dtime) local ocn = otrn.path_cn[ob_idx] local ocp = otrn.path_cp[ob_idx] - local target_is_inside, ref_index, facing + local target_is_inside, ref_index, facing, same_dir if base_cn == ocn then -- same direction @@ -1049,7 +1049,7 @@ function advtrains.update_trainpart_properties(train_id, invert_flipstate) if not wagon then local ent = advtrains.wagon_objects[w_id] local pdesc - if ent then + if ent and ent:get_pos() then pdesc = "at " .. minetest.pos_to_string(ent:get_pos()) elseif train.last_pos then pdesc = "near " .. minetest.pos_to_string(train.last_pos) diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua index ef057e5..01c60ec 100644 --- a/advtrains/wagons.lua +++ b/advtrains/wagons.lua @@ -1333,7 +1333,7 @@ function advtrains.get_wagon_prototype(data) end local rt, proto = advtrains.resolve_wagon_alias(wt) if not rt then - atwarn("Unable to load wagon type",wt,", using placeholder") + --atwarn("Unable to load wagon type",wt,", using placeholder") rt = "advtrains:wagon_placeholder" proto = advtrains.wagon_prototypes[rt] end diff --git a/advtrains_interlocking/database.lua b/advtrains_interlocking/database.lua index 9c72a72..d80fb76 100644 --- a/advtrains_interlocking/database.lua +++ b/advtrains_interlocking/database.lua @@ -84,7 +84,7 @@ function ildb.load(data) if pos then -- that was a pos_to_string local epos = advtrains.encode_pos(pos) - --atdebug("ILDB converting TCB position format",pts,"->",epos) + atdebug("ILDB converting TCB position format",pts,"->",epos) track_circuit_breaks[epos] = tcb else -- keep entry, it is already new @@ -100,7 +100,7 @@ function ildb.load(data) local lpos = minetest.string_to_pos(lpts) if lpos then local epos = advtrains.encode_pos(lpos) - --atdebug("ILDB converting tcb",pts,"side",t_side,"route",t_route,"lock position format",lpts,"->",epos) + atdebug("ILDB converting tcb",pts,"side",t_side,"route",t_route,"lock position format",lpts,"->",epos) locks_n[epos] = state else -- already correct format @@ -131,7 +131,7 @@ function ildb.load(data) if pos then -- that was a pos_to_string local epos = advtrains.encode_pos(pos) - --atdebug("ILDB converting Route Lock position format",pts,"->",epos) + atdebug("ILDB converting Route Lock position format",pts,"->",epos) advtrains.interlocking.route.rte_locks[epos] = lta else -- keep entry, it is already new @@ -412,6 +412,7 @@ function ildb.check_and_repair_ts_at_pos(pos, tcb_connid, notify_pname, force_cr return ildb.repair_ts_merge_all(all_tcbs, force_create, notify_pname) end --tsrepair_notify(notify_pname, "Found section", ts.name or ts_id, "here.") + ildb.update_rs_cache(ts_id) return ts_id end @@ -457,7 +458,7 @@ function ildb.get_all_tcbs_adjacent(inipos, inidir, per_track_callback) pos, connid = ti:next_branch() --atdebug("get_all_tcbs_adjacent: BRANCH: ",pos, connid) bconnid = nil - is_branch_start = true + local is_branch_start = true repeat -- callback if per_track_callback then diff --git a/advtrains_interlocking/route_ui.lua b/advtrains_interlocking/route_ui.lua index 7dddc6e..3c7bd64 100644 --- a/advtrains_interlocking/route_ui.lua +++ b/advtrains_interlocking/route_ui.lua @@ -67,7 +67,7 @@ function atil.show_route_edit_form(pname, sigd, routeid, sel_rpartidx) if c_rseg.locks then for pts, state in pairs(c_rseg.locks) do - local pos = minetest.string_to_pos(pts) + local pos = advtrains.decode_pos(pts) itab(i, "L "..pts.." -> "..state, "lock", pos) if not advtrains.is_passive(pos) then itab(i, "-!- No passive component at "..pts..". Please reconfigure route!", "err", nil) diff --git a/advtrains_interlocking/routesetting.lua b/advtrains_interlocking/routesetting.lua index 28c8c3c..0668e62 100644 --- a/advtrains_interlocking/routesetting.lua +++ b/advtrains_interlocking/routesetting.lua @@ -104,7 +104,7 @@ function ilrs.set_route(signal, route, try) end for lp, state in pairs(c_locks) do - local confl = ilrs.has_route_lock(pts, state) + local confl = ilrs.has_route_lock(lp, state) local pos = advtrains.decode_pos(lp) if advtrains.is_passive(pos) then @@ -131,7 +131,8 @@ function ilrs.set_route(signal, route, try) local nvar = c_rseg.next if nvar then local re_tcbs = ildb.get_tcbs({p = nvar.p, s = (nvar.s==1) and 2 or 1}) - if not re_tcbs or not re_tcbs.ts_id or re_tcbs.ts_id~=c_ts_id then + if (not re_tcbs or not re_tcbs.ts_id or re_tcbs.ts_id~=c_ts_id) + and route[i+1] then --FIX 2025-01-08: in old worlds the final TCB may be wrong (it didn't matter back then), don't error out here (route still shown invalid in UI) if not try then atwarn("Encountered inconsistent ts (front~=back) while a real run of routesetting routine, at position",pts,"while setting route",rtename,"of",signal) end return false, "TCB at "..minetest.pos_to_string(nvar.p).." has different section than previous TCB. Please update track section or reconfigure route!" end @@ -413,7 +414,9 @@ function ilrs.update_route(sigd, tcbs, newrte, cancel) -- set_route now sets the signal aspects --has_changed_aspect = true -- route success. apply default_autoworking flag if requested - tcbs.route_auto = route.default_autoworking + if route.default_autoworking then + tcbs.route_auto = true --FIX 2025-01-08: never set it to false if it was true! + end end end if has_changed_aspect then diff --git a/advtrains_interlocking/signal_api.lua b/advtrains_interlocking/signal_api.lua index b607750..e92658d 100644 --- a/advtrains_interlocking/signal_api.lua +++ b/advtrains_interlocking/signal_api.lua @@ -375,6 +375,7 @@ function signal.reapply_aspect(pts) local rem_aspt = signal.aspects[remote] --atdebug("resolving remote",advtrains.decode_pos(remote),"aspt",rem_aspt) local rem_pos = advtrains.decode_pos(remote) + local _,rem_ndef rem_masp, _, _, rem_ndef = signal.get_aspect_internal(rem_pos, rem_aspt) if rem_masp then if rem_ndef.advtrains and rem_ndef.advtrains.get_aspect_info then diff --git a/advtrains_interlocking/tcb_ts_ui.lua b/advtrains_interlocking/tcb_ts_ui.lua index 59d3be4..814a11a 100755 --- a/advtrains_interlocking/tcb_ts_ui.lua +++ b/advtrains_interlocking/tcb_ts_ui.lua @@ -776,7 +776,7 @@ function advtrains.interlocking.check_route_valid(route, sigd) if c_rseg.locks then for pts, state in pairs(c_rseg.locks) do - local pos = minetest.string_to_pos(pts) + local pos = advtrains.decode_pos(pts) if not advtrains.is_passive(pos) then return false, "No passive component for lock at "..pts end @@ -795,6 +795,9 @@ function advtrains.interlocking.check_route_valid(route, sigd) i = i + 1 end -- check end TCB + if not c_sigd then + return false, "Final TCBS unset (legacy-style buffer route)" + end c_tcbs = ildb.get_tcbs(c_sigd) if not c_tcbs then return false, "Final TCBS missing at "..sigd_to_string(c_sigd) diff --git a/advtrains_luaautomation/environment.lua b/advtrains_luaautomation/environment.lua index b54d45c..a6ed2c7 100644 --- a/advtrains_luaautomation/environment.lua +++ b/advtrains_luaautomation/environment.lua @@ -226,11 +226,15 @@ if advtrains.interlocking then end static_env.get_aspect = function(signal) local pos = atlatc.pcnaming.resolve_pos(signal) - return advtrains.interlocking.signal_get_aspect(pos) + return advtrains.interlocking.signal.get_aspect_info(pos) end - static_env.set_aspect = function(signal, asp) + static_env.set_aspect = function(signal, main_asp, rem_signal) + if type(main_asp) == "table" then + error("set_aspect: Parameters of this method have changed to (signal, main_asp, rem_signal) with introduction of distant signalling: parameter 2 is now the main aspect name (a string)") + end local pos = atlatc.pcnaming.resolve_pos(signal) - return advtrains.interlocking.signal_set_aspect(pos,asp) + local rem_pos = rem_signal and atlatc.pcnaming.resolve_pos(rem_signal) + return advtrains.interlocking.signal_set_aspect(pos, main_asp, rem_pos) end --section_occupancy() -- cgit v1.2.3