Advertisement
Guest User

Untitled

a guest
May 31st, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. local component = require("component")
  2. local term = require("term")
  3. local sides = require("sides")
  4.  
  5. local rs = component.redstone
  6. local gpu = component.gpu
  7. local cursorh = 1
  8. local w,h = gpu.getResolution()
  9.  
  10. function write(str)
  11. io.write(str,"\n")
  12. cursorh = cursorh + 1
  13. if cursorh >= h then
  14. term.clear()
  15. cursorh = 1
  16. end
  17. end
  18.  
  19. ----Config----
  20.  
  21. local users = {polis = 1,holm = 2}
  22. local passwords = {polis = "admin",holm = "admin"}
  23.  
  24. local reactorsides = {top = sides.top,right = sides.right} -- defines the states
  25. local enabledreactors = {top = rs.getInput(reactorsides.top) > 1,right = rs.getInput(reactorsides.right) > 1} -- Gets the enabled reactors and stuff
  26.  
  27. function reactortoggle(side)
  28. if enabledreactors[side] then
  29. enabledreactors[side] = not enabledreactors[side]
  30. rs.setOutput(side,0)
  31. else
  32. enabledreactors[side] = not enabledreactors[side]
  33. rs.setOutput(side,15)
  34. end
  35. end
  36.  
  37. local commands = { -- the commands the user can input
  38.  
  39. startreactor = function(level,args)
  40. if level > 1 then -- checks if user has enought permission
  41. reactortoggle(args[1])
  42. else
  43. write("insufficient permission")
  44. end
  45. end,
  46.  
  47. logoff = function() login() end,
  48.  
  49. exit = function() os.exit() end
  50. }
  51.  
  52.  
  53. local logeduser
  54. function login()
  55. logeduser = nil
  56. while true do
  57.  
  58. term.clear()
  59. cursorh = 1
  60. write("BNK-SYSTEM AND PROTECTION SECURITY")
  61. write("Please enter the username : ")
  62.  
  63. term.setCursor(29,cursorh)
  64. local username=io.read()
  65.  
  66. if users[username] then -- if user found ask password
  67.  
  68. write("Please enter the password : ")
  69. term.setCursor(29,cursorh)
  70.  
  71. local password=io.read()
  72.  
  73. if password == passwords[username] then -- if password matches then break of the loop to go to the next one
  74. logeduser = username
  75. write("Logged in succesfully")
  76. break
  77. else
  78. write("Login failed")
  79. os.sleep(1)
  80. end
  81. else
  82. write("no user found")
  83. end
  84. end
  85. end
  86.  
  87.  
  88. while true do
  89.  
  90. term.clear()
  91. cursorh = 1
  92. write("BNK-SYSTEMS REACTOR CONTROL")
  93. term.setCursor(1,cursorh)
  94. local command = io.read()
  95.  
  96. local commandname = command:match("%w+") -- splits the command into commands and arguments
  97.  
  98. local action = commands[commandname] -- caches the command
  99.  
  100. if action then -- checks if command exists
  101. local args = {} -- Split the command into arguments
  102. for arg in command:gmatch("%s+(%S+)") do
  103. args[#args] = arg
  104. end
  105. action(users[logeduser],args) -- execute the action
  106. end
  107. os.sleep(1)
  108.  
  109. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement