Advertisement
Guest User

client

a guest
Aug 5th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.35 KB | None | 0 0
  1. local oldPull = os.pullEvent
  2. os.pullEvent = os.pullEventRaw
  3.  
  4. local serverId = 45
  5.  
  6. function listenToInput()
  7.   term.setTextColor(colors.yellow)
  8.   write("> ")
  9.   term.setTextColor(colors.white)
  10.   local input = read()
  11.   local lInput = string.lower(input)
  12.   if lInput == "edit startup" then
  13.     term.setTextColor(colors.red)
  14.     print("edit:9: Access Denied.")
  15.     listenToInput()
  16.   elseif lInput == "startup" then
  17.     term.setTextColor(colors.red)
  18.     print("No such program")
  19.     listenToInput()
  20.   elseif string.find(lInput, "cp") and string.find(lInput, "startup") then
  21.     term.setTextColor(colors.red)
  22.     print("copy:9: Access Denied.")
  23.     listenToInput()
  24.   elseif string.find(lInput, "delete") and string.find(lInput, "startup") then
  25.     term.setTextColor(colors.red)
  26.     print("delete:9: Access Denied.")
  27.     listenToInput()
  28.   else
  29.     shell.run(input)
  30.     listenToInput()
  31.   end
  32. end
  33.  
  34. term.clear()
  35. term.setCursorPos(1, 1)
  36. term.setTextColor(colors.purple)
  37. rednet.open("top")
  38. print("Started RedNet.")
  39. print("Pinging Server... This may take 10 seconds.")
  40. rednet.send(serverId, "RequestStatus")
  41. local id2 = rednet.receive(10)
  42. if id2 == nil then
  43.   term.setTextColor(colors.red)
  44.   print("Could not reach Server. Rebooting.")
  45.   sleep(2)
  46.   os.reboot()
  47. end
  48. term.setTextColor(colors.red)
  49. print(" ")
  50. print("Please Login to use this Computer.")
  51. print("Accounts are saved on the Server.")
  52. print(" ")
  53. term.setTextColor(colors.orange)
  54. write("Username: ")
  55. term.setTextColor(colors.cyan)
  56. local username = read()
  57. term.setTextColor(colors.orange)
  58. write("Password: ")
  59. term.setTextColor(colors.cyan)
  60. local password = read("*")
  61. rednet.send(serverId, username, password)
  62. term.setTextColor(colors.green)
  63. print("Please wait 30 seconds that the Server can respond.")
  64. while true do
  65. id,success = rednet.receive(30)
  66. if success == nil then
  67.   success = false
  68. end
  69. if id == serverId then
  70.   if success == true then
  71.     term.setTextColor(colors.green)
  72.     print("Access Granted.")
  73.     term.setTextColor(colors.yellow)
  74.     print(os.version())
  75.     os.pullEvent = oldPull
  76.     listenToInput()
  77.   else
  78.     term.setTextColor(colors.red)
  79.     print("Access Denied or Server offline. Rebooting Computer.")
  80.     sleep(3)
  81.     os.reboot()
  82.   end
  83. else
  84.   term.setTextColor(colors.red)
  85.   print("Invalid RedNet ID. Rebooting Computer.")
  86.   sleep(3)
  87.   os.reboot()
  88. end
  89. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement