Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local stateFile = "stayOnlineStates.json"
- local function loadNodeStates(nodes)
- if not fs.exists(stateFile) then return end
- local file = fs.open(stateFile, "r")
- local data = textutils.unserializeJSON(file.readAll())
- file.close()
- if type(data) == "table" then
- for hostName, state in pairs(data) do
- if nodes[hostName] then
- nodes[hostName].stayOnline = state.stayOnline
- nodes[hostName].status = state.status
- end
- end
- end
- end
- local function saveNodeStates(nodes)
- local data = {}
- for hostName, node in pairs(nodes) do
- data[hostName] = {
- stayOnline = node.stayOnline,
- status = node.status,
- }
- end
- local file = fs.open(stateFile, "w")
- file.write(textutils.serializeJSON(data))
- file.close()
- end
- return {
- loadNodeStates = loadNodeStates,
- saveNodeStates = saveNodeStates,
- }
Add Comment
Please, Sign In to add comment