This commit is contained in:
2026-04-06 14:13:46 -07:00
commit eb4659817e
11 changed files with 857 additions and 0 deletions

31
remotedbserver.lua Normal file
View File

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