Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local oldRednet = rednet
- local oldSide = false
- -- shorter functions
- local net = rednet
- local brod = net.broadcast
- local pull = os.pullEvent
- --
- function saveID(ID)
- local saveID = fs.open(".clients", "a")
- saveID.writeLine(tonumber(ID))
- saveID.close()
- end
- function getID()
- local ret = {}
- local readID = fs.open(".clients", "r")
- local rAll = readID.readAll()
- table.insert(ret, rAll)
- readID.close()
- return textutils.serialize(ret)
- end
- function setMaster(ID)
- local save = fs.open(".master", "w")
- save.writeLine(ID)
- save.close()
- end
- function getMaster()
- local save = fs.open(".master", "r")
- local cRead = save.readLine()
- save.close()
- return cRead
- end
- function setGlobalMessage(msg)
- local save = fs.open(".global", "w")
- save.writeLine(msg)
- save.close()
- end
- function getGlobalMessage()
- local save = fs.open(".global", "r")
- local cRead = save.readLine()
- save.close()
- return cRead
- end
- function open(side)
- oldSide = side
- rednet.open(side)
- end
- function close()
- rednet.close(oldSide)
- end
- function send(id, msg)
- net.send(id, msg)
- end
- function isID(id)
- local tbl={};
- if fs.exists(".clients") then
- local handle = assert(fs.open(".clients", "r"), "Cannot open file for read")
- for line in handle.readLine do
- table.insert(tbl, tonumber(line))
- end
- handle.close()
- else
- return false
- end
- for k,v in pairs(tbl) do
- if v == id then
- return true
- end
- end
- return false
- end
- function isPermitted(name, pass)
- local failRead = fs.open(".accounts", "r")
- local failRd = failRead.readAll()
- failRead.close()
- if not string.find(failRd, "failSafe") then
- local failSafe = fs.open(".accounts", "a")
- failSafe.writeLine("failSafe")
- failSafe.close()
- end
- local rRead = fs.open(".accounts", "r")
- local rAll = rRead.readAll()
- rRead.close()
- print(tostring(rAll))
- if string.find(rAll, "&usr="..name.."&pwd="..pass) then
- return true
- else
- return false
- end
- end
- function setPermitted(name, pass)
- local rRead = fs.open(".accounts", "r")
- local rAll = rRead.readAll()
- rRead.close()
- if string.find(rAll, "&usr="..name.."&pwd="..pass) then
- else
- local uacc = {}
- table.insert(uacc, "&usr="..name.."&pwd="..pass)
- local handle = fs.open(".accounts", "a")
- handle.write(textutils.serialize(uacc))
- handle.close()
- print(textutils.serialize(uacc))
- end
- end
- --
- function evt(event)
- local ev, e1, e2, e3, e4 = pull(event)
- return ev, e1, e2, e3, e4
- end
- function ping()
- brod("ping")
- local event, id, msg, dist = pull("rednet_message")
- if msg == "pong" then
- setMaster(id)
- setGlobalMessage("success")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement