From e7e605ea00b97d86d330671619428f478c6baad5 Mon Sep 17 00:00:00 2001 From: MayaTheShy Date: Sun, 22 Mar 2026 02:37:46 -0400 Subject: [PATCH] Add command ID generation for message idempotency in sendToMaster --- inventoryClient.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/inventoryClient.lua b/inventoryClient.lua index d7b9518..56803ce 100644 --- a/inventoryClient.lua +++ b/inventoryClient.lua @@ -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