feat(inferium-server): configs are persisted
This commit is contained in:
parent
77210784ff
commit
24ffcce68d
@ -1,14 +1,39 @@
|
|||||||
local net = require('libs/net')
|
local net = require('libs/net')
|
||||||
local inferium = require('config/inferium')
|
local inferium = require('config/inferium')
|
||||||
|
|
||||||
|
local VERSION = "1.1.0"
|
||||||
local INFERIUM_SERVER = 'inferium.com'
|
local INFERIUM_SERVER = 'inferium.com'
|
||||||
|
|
||||||
|
local PERSISTED_CONFIGS = '/data/inferium-configs'
|
||||||
local UPGRADE_SCRIPT = '/upgrade.lua'
|
local UPGRADE_SCRIPT = '/upgrade.lua'
|
||||||
local VERSION = "1.0.0"
|
|
||||||
|
|
||||||
local defaultConfig= inferium.defaultConfig or error('no default config provided in config', 0)
|
local defaultConfig = inferium.defaultConfig or error('no default config provided in config', 0)
|
||||||
|
|
||||||
-- TODO: persistance
|
local readPersistedConfigs = function()
|
||||||
local LOCAL_CONFIGS = {}
|
local file = fs.open(PERSISTED_CONFIGS, 'r')
|
||||||
|
|
||||||
|
if not file then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local serializedConfigs = file.readAll()
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
return textutils.unserialize(serializedConfigs)
|
||||||
|
end
|
||||||
|
|
||||||
|
local savePersistedConfigs = function(configs)
|
||||||
|
local file = fs.open(PERSISTED_CONFIGS, 'w')
|
||||||
|
|
||||||
|
if not file then
|
||||||
|
error('savePersistedConfigs: cannot open .minerstate file!')
|
||||||
|
end
|
||||||
|
|
||||||
|
file.write(textutils.serialize(configs))
|
||||||
|
file.close()
|
||||||
|
end
|
||||||
|
|
||||||
|
local LOCAL_CONFIGS = readPersistedConfigs() or {}
|
||||||
|
|
||||||
local function getConfigForComputer(computerId)
|
local function getConfigForComputer(computerId)
|
||||||
return LOCAL_CONFIGS[tostring(computerId)]
|
return LOCAL_CONFIGS[tostring(computerId)]
|
||||||
@ -16,6 +41,7 @@ end
|
|||||||
|
|
||||||
local function setConfigForComputer(computerId, config)
|
local function setConfigForComputer(computerId, config)
|
||||||
LOCAL_CONFIGS[tostring(computerId)] = config
|
LOCAL_CONFIGS[tostring(computerId)] = config
|
||||||
|
savePersistedConfigs(LOCAL_CONFIGS)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function getConfig(computerId)
|
local function getConfig(computerId)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user