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