feat(inferium-server): add a warning when computerId is not known by the system
This commit is contained in:
parent
cdad0204ba
commit
6294b38806
@ -1,6 +1,6 @@
|
|||||||
local inferiumPlans = require('config/inferium-plans') -- temporary default plan
|
local inferiumPlans = require('config/inferium-plans') -- temporary default plan
|
||||||
|
|
||||||
local VERSION = "0.2.1"
|
local VERSION = "0.3.0"
|
||||||
|
|
||||||
local INFERIUM_QUERY_PORT = 111
|
local INFERIUM_QUERY_PORT = 111
|
||||||
local INFERIUM_REPLY_PORT = 112
|
local INFERIUM_REPLY_PORT = 112
|
||||||
@ -12,21 +12,29 @@ local modem = peripheral.find("modem") or error("No modem attached", 0)
|
|||||||
modem.open(INFERIUM_QUERY_PORT)
|
modem.open(INFERIUM_QUERY_PORT)
|
||||||
|
|
||||||
local function getPlanForComputer(computerId)
|
local function getPlanForComputer(computerId)
|
||||||
return inferiumPlans[tostring(computerId)] or defaultPlan
|
return inferiumPlans[tostring(computerId)]
|
||||||
end
|
end
|
||||||
|
|
||||||
local function messageReceived(message)
|
local function messageReceived(message)
|
||||||
if message.type == 'getplan' then
|
if message.type == 'getplan' then
|
||||||
local payload = message.payload or {}
|
local payload = message.payload or {}
|
||||||
|
local computerId = payload.computerId
|
||||||
|
|
||||||
if payload.computerId == nil then
|
if not computerId == nil then
|
||||||
print('getplan error: no computerId found in received payload')
|
print('getplan error: no computerId found in received payload')
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local plan = getPlanForComputer(computerId)
|
||||||
|
|
||||||
|
if not plan then
|
||||||
|
print('getplan warning: no plan found for computerID ' .. tostring(computerId))
|
||||||
|
plan = defaultPlan
|
||||||
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type = "getplan/response",
|
type = "getplan/response",
|
||||||
payload = getPlanForComputer(payload.computerId)
|
payload = plan
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user