Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- AUTH SERVER INTERFACE
- local databasefile = "/disk/authdb01"
- local hostname = "authserver01"
- function loaddb(dbfile)
- local file = fs.open(dbfile, "r")
- local data = file.readAll()
- file.close()
- return textutils.unserialize(data)
- end
- -- Initialize modem settings
- rednet.open("right")
- rednet.host("auth", hostname)
- -- Load in the authdb
- local dbtable = loaddb(databasefile)
- -- Wait forever for auth requests
- term.clear()
- term.setCursorPos(1, 1)
- print("Welcome to the AUTHSERVER Interface!")
- print("Waiting for requests...\n")
- while true do
- local sourceid, message = rednet.receive("auth")
- write(os.time()..": ")
- if type(message) == "table" then
- local user = message[1]
- local pass = message[2]
- if user == nil or pass == nil then
- print("INVD REQUEST from "..sourceid)
- elseif dbtable[user] == pass then
- print("AUTH SUCCESS for "..user)
- rednet.send(sourceid, "SUCCESS", "auth")
- else
- print("AUTH FAILURE for "..user)
- rednet.send(sourceid, "FAILURE", "auth")
- end
- else
- print("INVD REQUEST from "..sourceid)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement