feat(inferium-server): add listharvesters
This commit is contained in:
parent
877773bb5a
commit
3bdfec3eda
@ -2,7 +2,8 @@ local net = require('libs/net')
|
||||
local utils = require('libs/utils')
|
||||
local inferium = require('config/inferium')
|
||||
|
||||
local VERSION = "1.1.2"
|
||||
local DEFAULT_HARVESTER_NAME = 'harvester'
|
||||
local VERSION = "1.2.0"
|
||||
local INFERIUM_SERVER = 'inferium.com'
|
||||
|
||||
local PERSISTED_CONFIGS = '/data/inferium-configs'
|
||||
@ -42,7 +43,7 @@ local function getConfigForComputer(computerId)
|
||||
return LOCAL_CONFIGS[tostring(computerId)]
|
||||
end
|
||||
|
||||
local function setConfigForComputer(computerId, config)
|
||||
local function saveConfigForComputer(computerId, config)
|
||||
LOCAL_CONFIGS[tostring(computerId)] = config
|
||||
savePersistedConfigs(LOCAL_CONFIGS)
|
||||
end
|
||||
@ -55,7 +56,7 @@ local function getConfigWithLength(config)
|
||||
end
|
||||
|
||||
|
||||
local function getConfig(computerId)
|
||||
local function getConfig(_, computerId)
|
||||
if not computerId == nil then
|
||||
print('getconfig error: no computerId found')
|
||||
return nil
|
||||
@ -65,7 +66,7 @@ local function getConfig(computerId)
|
||||
|
||||
if not config then
|
||||
print('new harvester detected: ' .. tostring(computerId))
|
||||
setConfigForComputer(computerId, defaultConfig)
|
||||
saveConfigForComputer(computerId, defaultConfig)
|
||||
config = defaultConfig
|
||||
end
|
||||
|
||||
@ -75,10 +76,32 @@ local function getConfig(computerId)
|
||||
}
|
||||
end
|
||||
|
||||
-- return a table of harvesters { id: string, name: string }[]
|
||||
local function listHarvesters()
|
||||
local result = {}
|
||||
|
||||
for k, v in pairs(LOCAL_CONFIGS) do
|
||||
table.insert(result, { id = k, name = v.name or DEFAULT_HARVESTER_NAME })
|
||||
end
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
local function exitServer(_, _, stopServer)
|
||||
stopServer();
|
||||
return true
|
||||
end
|
||||
|
||||
local function upgradeServer()
|
||||
shell.execute(UPGRADE_SCRIPT)
|
||||
return true
|
||||
end
|
||||
|
||||
local ROUTES = {
|
||||
['getconfig'] = function(_, computerId) return getConfig(computerId) end,
|
||||
['exit-server'] = function(_, _, stopServer) stopServer() ; return true end,
|
||||
['upgrade-server'] = function() shell.execute(UPGRADE_SCRIPT) ; return true end,
|
||||
['getconfig'] = getConfig,
|
||||
['listHarvesters'] = listHarvesters,
|
||||
['exit-server'] = exitServer,
|
||||
['upgrade-server'] = upgradeServer,
|
||||
}
|
||||
|
||||
net.openRednet()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user