Files
airship-autopilot/files/cockpit/link.lua
Stian 4cd2573f56 Airship autopilot: role-based wget installer for server
Mirrors the live CC autopilot (computer 0) and cockpit (computer 4) from the
Modda wii world. install.lua fetches each role's manifest over HTTP so the
system installs on any server regardless of computer id.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-23 12:53:41 +02:00

34 lines
1.2 KiB
Lua

-- link.lua -- lettvekts rednet-lenke mellom autopiloten (maskinrom) og piloten (pilot-hus).
-- Modem-agnostisk: virker over wired (nettverkskabel) ELLER wireless/ender modem. Graceful:
-- hvis ingen modem finnes, blir publish/send no-ops (autopiloten kjorer fint solo).
local M = {}
M.STATUS = "airship_status" -- autopilot -> pilot (status-kringkasting)
M.CMD = "airship_cmd" -- pilot -> autopilot (kommandoer)
local opened = false
-- aapne rednet paa ALLE tilkoblede modem (wired og/eller wireless)
function M.open()
for _, name in ipairs(peripheral.getNames()) do
if peripheral.getType(name) == "modem" and not rednet.isOpen(name) then
rednet.open(name); opened = true
end
end
-- ogsaa hvis et modem allerede var aapent
for _, name in ipairs(peripheral.getNames()) do
if peripheral.getType(name) == "modem" and rednet.isOpen(name) then opened = true end
end
return opened
end
function M.isOpen() return opened end
-- kringkast status (kalles hver tick av autopiloten)
function M.publishStatus(t) if opened then rednet.broadcast(t, M.STATUS) end end
-- send en kommando-tabell (kalles av piloten ved knappetrykk)
function M.sendCommand(t) if opened then rednet.broadcast(t, M.CMD) end end
return M