Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local term = require("term")
- local sides = require("sides")
- local rs = component.redstone
- local gpu = component.gpu
- local cursorh = 1
- local w,h = gpu.getResolution()
- function write(str)
- io.write(str,"\n")
- cursorh = cursorh + 1
- if cursorh >= h then
- term.clear()
- cursorh = 1
- end
- end
- ----Config----
- local users = {polis = 1,holm = 2}
- local passwords = {polis = "admin",holm = "admin"}
- local reactorsides = {top = sides.top,right = sides.right} -- defines the states
- local enabledreactors = {top = rs.getInput(reactorsides.top) > 1,right = rs.getInput(reactorsides.right) > 1} -- Gets the enabled reactors and stuff
- function reactortoggle(side)
- if enabledreactors[side] then
- enabledreactors[side] = not enabledreactors[side]
- rs.setOutput(side,0)
- else
- enabledreactors[side] = not enabledreactors[side]
- rs.setOutput(side,15)
- end
- end
- local commands = { -- the commands the user can input
- startreactor = function(level,args)
- if level > 1 then -- checks if user has enought permission
- reactortoggle(args[1])
- else
- write("insufficient permission")
- end
- end,
- logoff = function() login() end,
- exit = function() os.exit() end,
- help = function() for name in pairs(commands) do write(name) end end
- }
- local logeduser
- function login()
- logeduser = nil
- while true do
- term.clear()
- cursorh = 1
- write("BNK-SYSTEM AND PROTECTION SECURITY")
- write("Please enter the username : ")
- term.setCursor(29,cursorh)
- local username=io.read()
- if users[username] then -- if user found ask password
- write("Please enter the password : ")
- term.setCursor(29,cursorh)
- local password=io.read()
- if password == passwords[username] then -- if password matches then break of the loop to go to the next one
- logeduser = username
- write("Logged in succesfully")
- break
- else
- write("Login failed")
- os.sleep(1)
- end
- else
- write("no user found")
- end
- end
- end
- login()
- while true do
- term.clear()
- cursorh = 1
- write("BNK-SYSTEMS REACTOR CONTROL")
- term.setCursor(1,cursorh)
- local command = io.read()
- local commandname = command:match("%w+") -- splits the command into commands and arguments
- local action = commands[commandname] -- caches the command
- if action then -- checks if command exists
- local args = {} -- Split the command into arguments
- for arg in command:gmatch("%s+(%S+)") do
- args[#args] = arg
- end
- action(users[logeduser],args) -- execute the action
- end
- os.sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement