Add error handling for network order and craft message transmissions
This commit is contained in:
@@ -3256,15 +3256,25 @@ local function main()
|
||||
while true do
|
||||
local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
|
||||
if channel == ORDER_CHANNEL and type(message) == "table" then
|
||||
local handlerOk, handlerErr = pcall(function()
|
||||
if message.type == "order" and message.itemName and message.amount then
|
||||
print(string.format("[NET] Order: %s x%d", message.itemName, message.amount))
|
||||
local success = orderItem(message.itemName, message.amount, message.dropperName)
|
||||
networkModem.transmit(replyChannel, ORDER_CHANNEL, {
|
||||
type = "order_result",
|
||||
success = success,
|
||||
message = statusMessage,
|
||||
color = statusColor,
|
||||
})
|
||||
local pok, success = pcall(orderItem, message.itemName, message.amount, message.dropperName)
|
||||
if not pok then
|
||||
print("[NET] orderItem crashed: " .. tostring(success))
|
||||
success = false
|
||||
statusMessage = "Order error"
|
||||
statusColor = colors.red
|
||||
statusTimer = 5
|
||||
end
|
||||
pcall(function()
|
||||
networkModem.transmit(replyChannel, ORDER_CHANNEL, {
|
||||
type = "order_result",
|
||||
success = success,
|
||||
message = statusMessage,
|
||||
color = statusColor,
|
||||
})
|
||||
end)
|
||||
pcall(broadcastState)
|
||||
elseif message.type == "scan" then
|
||||
print("[NET] Scan request from client")
|
||||
@@ -3316,15 +3326,21 @@ local function main()
|
||||
err = tostring(ok)
|
||||
ok = false
|
||||
end
|
||||
networkModem.transmit(replyChannel, ORDER_CHANNEL, {
|
||||
type = "craft_result",
|
||||
success = ok,
|
||||
error = err,
|
||||
})
|
||||
pcall(function()
|
||||
networkModem.transmit(replyChannel, ORDER_CHANNEL, {
|
||||
type = "craft_result",
|
||||
success = ok,
|
||||
error = err,
|
||||
})
|
||||
end)
|
||||
smelterNeedsRedraw = true
|
||||
needsRedraw = true
|
||||
pcall(broadcastState)
|
||||
end
|
||||
end) -- end pcall handler
|
||||
if not handlerOk then
|
||||
print("[NET] Handler error: " .. tostring(handlerErr))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user