smigger22

Door Lock - Server

Feb 9th, 2015
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.99 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2. serverID = 3604
  3. serverName = "EpicServer"
  4. serverPass = "smiggerryan12"
  5.  
  6. if not fs.exists("db") then
  7.     downloadDB = http.get("http://pastebin.com/raw.php?i=SfXFSh0a")
  8.     downloadDBView = downloadDB.readAll()
  9.     downloadDB.close()
  10.  
  11.     writeDB = fs.open("db", "w")
  12.     writeDB.write(downloadDBView)
  13.     writeDB.close()
  14.  
  15.     os.loadAPI("db")
  16. elseif fs.exists("db") then
  17.     os.loadAPI("db")
  18. end
  19.  
  20. x, y = term.getSize()
  21.  
  22. function centered(str, height)
  23.     term.setCursorPos(x / 2 - #str / 2, height)
  24.     term.write(str)
  25. end
  26.  
  27. function indented(str, indent, height)
  28.     term.setCursorPos(indent, height)
  29.     term.write(str)
  30. end
  31.  
  32. function left(str, height)
  33.     term.setCursorPos(1, height)
  34.     term.write(str)
  35. end
  36.  
  37. function right(str, height)
  38.     term.setCursorPos(x - #str, height)
  39. end
  40.  
  41. function clearLine(colour, height)
  42.     term.setCursorPos(1, height)
  43.     term.setBackgroundColour(colours[colour])
  44.     term.clearLine()
  45. end
  46.  
  47.  
  48. function doorLock()
  49.     while true do
  50.         rednet.open("back")
  51.         term.setBackgroundColour(colours.cyan)
  52.         term.clear()
  53.         term.setTextColour(colours.lightBlue)
  54.         clearLine("blue", 1)
  55.         clearLine("blue", 2)
  56.         clearLine("blue", 3)
  57.         indented("EpicCo", 2, 2)
  58.         term.setBackgroundColour(colours.cyan)
  59.         indented("Username: ", 2, 6)
  60.         indented("Password: ", 2, 8)
  61.         term.setCursorPos(12, 6)
  62.         usernameAuth = read()
  63.         term.setCursorPos(12, 8)
  64.         passwordAuth = read("*")
  65.         if db.checkUser(serverID, serverName, serverPass, usernameAuth, passwordAuth) then
  66.             rs.setOutput("bottom", true)
  67.             sleep(5)
  68.             rs.setOutput("bottom", false)
  69.         end
  70.     end
  71. end
  72.  
  73. function pocketOpen()
  74.     while true do
  75.         rednet.open("back")
  76.         local id, msg, dis = rednet.receive()
  77.         if type(msg) == "table" and msg.username and msg.password then
  78.             if db.checkUser(serverID, serverName, serverPass, msg.username, msg.password) then
  79.                 rs.setOutput("bottom", true)
  80.                 sleep(5)
  81.                 rs.setOutput("bottom", false)
  82.             end
  83.         end
  84.     end
  85. end
  86.  
  87. term.clear()
  88. parallel.waitForAny(doorLock, pocketOpen)
Advertisement
Add Comment
Please, Sign In to add comment