feat(inferium-harvester): crash the process when no response from the inferium server

This commit is contained in:
Guillaume ARM 2024-05-21 18:51:02 +02:00
parent d4cbe6e808
commit b075b953ab
2 changed files with 5 additions and 24 deletions

View File

@ -1,21 +1,4 @@
local function mystical(essenceName)
return 'mysticalagriculture:' .. essenceName .. '_seeds'
end
-- FALLBACK WHEN CANNOT FETCH THE REMOTE PLAN
local DEFAULT_REMOTE_PLAN = {
mystical('coal'),
mystical('inferium'),
mystical('inferium'),
mystical('inferium'),
mystical('inferium'),
mystical('inferium'),
mystical('inferium'),
mystical('inferium')
}
return {
length = 8,
firstCropZ = 2,
defaultRemotePlan = DEFAULT_REMOTE_PLAN
firstCropZ = 2
}

View File

@ -263,14 +263,12 @@ local function retrieveLocalPlan()
goBackToHome()
end
-- TODO: fetch timeout ?
-- TODO: fetch retry + timeout ?
local function fetchRemotePlan()
local fallbackPlan = config.defaultRemotePlan or {}
local modem = peripheral.find("modem")
if not modem then
return fallbackPlan
error('no modem found')
end
modem.open(INFERIUM_REPLY_PORT)
@ -286,7 +284,7 @@ local function fetchRemotePlan()
modem.close(INFERIUM_REPLY_PORT)
if not replyRawMessage then
return fallbackPlan
error('empty response from the server')
end
local replyMessage = textutils.unserialize(replyRawMessage)
@ -295,7 +293,7 @@ local function fetchRemotePlan()
return replyMessage.payload
end
return fallbackPlan
error('message received but there is no payload: ' .. replyRawMessage)
end
local function removeSeeds(seeds)