local inferiumPlan = require('config/inferium-plan') -- temporary default plan local INFERIUM_QUERY_PORT = 111 local INFERIUM_REPLY_PORT = 112 local modem = peripheral.find("modem") or error("No modem attached", 0) modem.open(INFERIUM_QUERY_PORT) local function getPlanForComputer(computerId) return inferiumPlan end local function messageReceived(message) if message.type == 'getplan' then local payload = message.payload or {} if payload.computerId == nil then print('Error: no computerId found in payload') return nil end return { type = "getplan/response", payload = getPlanForComputer(payload.computerId) } end end print('Inferium server listening on port ' .. INFERIUM_QUERY_PORT) while true do local _, _, channel, replyChannel, rawMessage, _ = os.pullEvent("modem_message") if channel == INFERIUM_QUERY_PORT and replyChannel == INFERIUM_REPLY_PORT then local message = textutils.unserialize(rawMessage) local replyMessage = messageReceived(message) if replyMessage then local rawReplyMessage = textutils.serialize(replyMessage) modem.transmit(INFERIUM_REPLY_PORT, INFERIUM_QUERY_PORT, rawReplyMessage) else print('warning: unknown message') end end end