feat: implement basic inferium server

This commit is contained in:
Guillaume ARM 2024-05-20 22:19:27 +02:00
parent 5e2234da78
commit cdb0e6e84f
3 changed files with 62 additions and 2 deletions

14
config/inferium-plan.lua Normal file
View File

@ -0,0 +1,14 @@
local function mystical(essenceName)
return 'mysticalagriculture:' .. essenceName .. '_seeds'
end
return {
mystical('coal'),
mystical('coal'),
mystical('coal'),
mystical('coal'),
mystical('experience'),
mystical('experience'),
mystical('experience'),
mystical('inferium')
}

44
inferium-server.lua Normal file
View File

@ -0,0 +1,44 @@
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
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

View File

@ -3,7 +3,8 @@ local LIST_FILES = {
'miner.lua',
'coal-crafter.lua',
'inferium-upgrader.lua',
'inferium-harvester.lua'
'inferium-harvester.lua',
'inferium-server.lua'
};
local LIST_LIBS_FILES = {
@ -16,7 +17,8 @@ local LIST_CONFIG_FILES = {
'startup.lua',
'upgrade.lua',
'config/mining.lua',
'config/harvesting.lua'
'config/harvesting.lua',
'config/inferium-plan.lua'
}