Advertisement
Guest User

Untitled

a guest
May 31st, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 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. help = function() for name in pairs(commands) do write(name) end end
  52. }
  53.  
  54.  
  55. local logeduser
  56. function login()
  57. logeduser = nil
  58. while true do
  59.  
  60. term.clear()
  61. cursorh = 1
  62. write("BNK-SYSTEM AND PROTECTION SECURITY")
  63. write("Please enter the username : ")
  64.  
  65. term.setCursor(29,cursorh)
  66. local username=io.read()
  67.  
  68. if users[username] then -- if user found ask password
  69.  
  70. write("Please enter the password : ")
  71. term.setCursor(29,cursorh)
  72.  
  73. local password=io.read()
  74.  
  75. if password == passwords[username] then -- if password matches then break of the loop to go to the next one
  76. logeduser = username
  77. write("Logged in succesfully")
  78. break
  79. else
  80. write("Login failed")
  81. os.sleep(1)
  82. end
  83. else
  84. write("no user found")
  85. end
  86. end
  87. end
  88. login()
  89.  
  90. while true do
  91.  
  92. term.clear()
  93. cursorh = 1
  94. write("BNK-SYSTEMS REACTOR CONTROL")
  95. term.setCursor(1,cursorh)
  96. local command = io.read()
  97.  
  98. local commandname = command:match("%w+") -- splits the command into commands and arguments
  99.  
  100. local action = commands[commandname] -- caches the command
  101.  
  102. if action then -- checks if command exists
  103. local args = {} -- Split the command into arguments
  104. for arg in command:gmatch("%s+(%S+)") do
  105. args[#args] = arg
  106. end
  107. action(users[logeduser],args) -- execute the action
  108. end
  109. os.sleep(1)
  110.  
  111. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement