Advertisement
Guest User

authserver

a guest
Dec 13th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.12 KB | None | 0 0
  1. -- AUTH SERVER INTERFACE
  2. local databasefile = "/disk/authdb01"
  3. local hostname = "authserver01"
  4.  
  5. function loaddb(dbfile)
  6.   local file = fs.open(dbfile, "r")
  7.   local data = file.readAll()
  8.   file.close()
  9.   return textutils.unserialize(data)
  10. end
  11.  
  12. -- Initialize modem settings
  13. rednet.open("right")
  14. rednet.host("auth", hostname)
  15.  
  16. -- Load in the authdb
  17. local dbtable = loaddb(databasefile)
  18.  
  19. -- Wait forever for auth requests
  20. term.clear()
  21. term.setCursorPos(1, 1)
  22. print("Welcome to the AUTHSERVER Interface!")
  23. print("Waiting for requests...\n")
  24. while true do
  25.   local sourceid, message = rednet.receive("auth")
  26.  
  27.   write(os.time()..": ")
  28.  
  29.   if type(message) == "table" then  
  30.     local user = message[1]
  31.     local pass = message[2]
  32.      
  33.     if user == nil or pass == nil then
  34.       print("INVD REQUEST from "..sourceid)
  35.     elseif dbtable[user] == pass then
  36.       print("AUTH SUCCESS for "..user)
  37.       rednet.send(sourceid, "SUCCESS", "auth")
  38.     else
  39.       print("AUTH FAILURE for "..user)
  40.       rednet.send(sourceid, "FAILURE", "auth")
  41.     end
  42.   else
  43.     print("INVD REQUEST from "..sourceid)
  44.   end
  45. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement