local eplib = require("entrypointlib") local function readTable() local file = fs.open("data.db","r") if not file then error("failed to open db file") end return textutils.unserialise(file.readAll() or "{}") or {} end local function writeTable(t) local file = fs.open("data.db", "w") if not file then error("failed to open db file") end file.write(textutils.serialise(t)) file.close() end local function receive() while true do sleep(0) local _,msg,id = os.pullEvent("network_packet") if msg.proto == "getTable" then eplib.send({proto = "resp", table = readTable()}, id) print("sent table to "..tostring(id)) elseif msg.proto == "setTable" then writeTable(msg.table) print("updated table from "..tostring(id)) eplib.send({proto="OK"},id) end end end parallel.waitForAny(eplib.loop,receive)