Add command ID generation for message idempotency in sendToMaster
This commit is contained in:
@@ -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 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
|
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
|
-- Send command to master
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
|
|
||||||
local function sendToMaster(message)
|
local function sendToMaster(message)
|
||||||
if not networkModem then return end
|
if not networkModem then return end
|
||||||
|
if not message.commandId then
|
||||||
|
message.commandId = newCommandId()
|
||||||
|
end
|
||||||
networkModem.transmit(ORDER_CHANNEL, CLIENT_CHANNEL, message)
|
networkModem.transmit(ORDER_CHANNEL, CLIENT_CHANNEL, message)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1310,7 +1323,7 @@ local function main()
|
|||||||
|
|
||||||
elseif channel == CLIENT_CHANNEL and type(message) == "table" and message.type == "craft_result" then
|
elseif channel == CLIENT_CHANNEL and type(message) == "table" and message.type == "craft_result" then
|
||||||
-- Craft result from master
|
-- 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
|
statusColor = message.success and colors.lime or colors.red
|
||||||
statusTimer = 5
|
statusTimer = 5
|
||||||
smelterNeedsRedraw = true
|
smelterNeedsRedraw = true
|
||||||
|
|||||||
Reference in New Issue
Block a user