Add remote reboot functionality via system channel
This commit is contained in:
@@ -28,6 +28,9 @@ local BROADCAST_INTERVAL = 1 -- seconds between state broadcasts
|
|||||||
local CRAFT_CHANNEL = 4203
|
local CRAFT_CHANNEL = 4203
|
||||||
local CRAFT_REPLY_CHANNEL = 4204
|
local CRAFT_REPLY_CHANNEL = 4204
|
||||||
|
|
||||||
|
-- Remote reboot system channel (all devices listen on this)
|
||||||
|
local SYSTEM_CHANNEL = 4205
|
||||||
|
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
-- Idempotent command tracking
|
-- Idempotent command tracking
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
@@ -2571,6 +2574,7 @@ local function main()
|
|||||||
networkModemName = name
|
networkModemName = name
|
||||||
networkModem.open(ORDER_CHANNEL)
|
networkModem.open(ORDER_CHANNEL)
|
||||||
networkModem.open(CRAFT_REPLY_CHANNEL)
|
networkModem.open(CRAFT_REPLY_CHANNEL)
|
||||||
|
networkModem.open(SYSTEM_CHANNEL)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -2967,6 +2971,20 @@ local function main()
|
|||||||
cache.droppers = merged
|
cache.droppers = merged
|
||||||
bumpStateVersion()
|
bumpStateVersion()
|
||||||
pcall(broadcastState)
|
pcall(broadcastState)
|
||||||
|
elseif message.type == "reboot" then
|
||||||
|
local target = message.target or "all"
|
||||||
|
log.info("NET", "Reboot command received, target: %s", target)
|
||||||
|
-- Broadcast reboot to all clients on system channel
|
||||||
|
networkModem.transmit(SYSTEM_CHANNEL, ORDER_CHANNEL, {
|
||||||
|
type = "reboot",
|
||||||
|
target = target,
|
||||||
|
})
|
||||||
|
-- If manager itself is targeted, reboot after a short delay
|
||||||
|
if target == "all" or target == "manager" then
|
||||||
|
log.info("NET", "Manager rebooting in 1s...")
|
||||||
|
sleep(1)
|
||||||
|
os.reboot()
|
||||||
|
end
|
||||||
elseif message.type == "craft" and message.recipeIdx then
|
elseif message.type == "craft" and message.recipeIdx then
|
||||||
log.info("NET", "Craft request: recipe #%d", message.recipeIdx)
|
log.info("NET", "Craft request: recipe #%d", message.recipeIdx)
|
||||||
local pok, ok, err = pcall(craftItem, message.recipeIdx)
|
local pok, ok, err = pcall(craftItem, message.recipeIdx)
|
||||||
|
|||||||
Reference in New Issue
Block a user