Add command ID generation for message idempotency in sendToMaster

This commit is contained in:
MayaTheShy
2026-03-22 02:37:46 -04:00
parent 6fa7ae5e8f
commit e7e605ea00

View File

@@ -229,12 +229,25 @@ local function monCenter(y, text, fg, bg) ui.monCenter(y, text, fg, bg) end
local function monBar(x, y, w, r, bc, bgc) ui.monBar(x, y, w, r, bc, bgc) end
local function drawButton(x, y, t, fg, bg, pl, pr) return ui.drawButton(x, y, t, fg, bg, pl, pr) end
-------------------------------------------------
-- Command ID generation (idempotency)
-------------------------------------------------
local cmdCounter = 0
local function newCommandId()
cmdCounter = cmdCounter + 1
return string.format("client_%d_%d_%d", os.getComputerID(), os.epoch("utc"), cmdCounter)
end
-------------------------------------------------
-- Send command to master
-------------------------------------------------
local function sendToMaster(message)
if not networkModem then return end
if not message.commandId then
message.commandId = newCommandId()
end
networkModem.transmit(ORDER_CHANNEL, CLIENT_CHANNEL, message)
end
@@ -1310,7 +1323,7 @@ local function main()
elseif channel == CLIENT_CHANNEL and type(message) == "table" and message.type == "craft_result" then
-- Craft result from master
statusMessage = message.message or ""
statusMessage = message.error or (message.success and "Craft complete" or "Craft failed")
statusColor = message.success and colors.lime or colors.red
statusTimer = 5
smelterNeedsRedraw = true