Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local bios = true
- --change this to true if using this as an OS lock.
- os.pullEvent = os.pullEventRaw
- local tX, tY = term.getSize()
- --check if PIN exists
- if not fs.exists(".PIN") then
- local PIN = {"0","0","0","0"}
- local writeFile = fs.open(".PIN", "w")
- writeFile.write(textutils.serialize(PIN))
- writeFile.close()
- end
- --gui functions
- local scannerFrame = {
- '+-+-+-+-+-+-+-+-+-+-+',
- '| |',
- '+ +',
- '| |',
- '+ +',
- '| |',
- '+ +',
- '| |',
- '+ +',
- '| |',
- '+ +',
- '| |',
- '+-+-+-+-+-+-+-+-+-+-+'
- }
- local scanner = {
- ' | | | | | | | | | ',
- '-+-+-+-+-+-+-+-+-+-',
- ' | | | | | | | | | ',
- '-+-+-+-+-+-+-+-+-+-',
- ' | | | | | | | | | ',
- '-+-+-+-+-+-+-+-+-+-',
- ' | | | | | | | | | ',
- '-+-+-+-+-+-+-+-+-+-',
- ' | | | | | | | | | ',
- '-+-+-+-+-+-+-+-+-+-',
- ' | | | | | | | | | '
- }
- -- lay out the button labels
- local labels = {
- ' 1 ', ' 2 ', ' 3 ',
- ' 4 ', ' 5 ', ' 6 ',
- ' 7 ', ' 8 ', ' 9 ',
- 'CLR', ' 0 ', 'ENT'
- }
- -- generate the objects
- local objects = {}
- for i=1, #labels do
- table.insert(objects, {
- x = (((i - 1)%3 + 1)*5) - 2;
- y = (math.ceil(i/3) * 3) + 3;
- label = labels[i];
- -- make CLR red and ENT green
- color = i==10 and colors.red or i==12 and colors.green or colors.lightGray;
- })
- end
- local function draw()
- term.setBackgroundColor(colors.black)
- term.clear()
- for i=1, #objects do
- local obj = objects[i]
- term.setTextColor(colors.gray)
- for num, line in pairs{'+---+','| |','+---+'} do
- term.setCursorPos(obj.x, obj.y + num - 1)
- write(line)
- end
- term.setCursorPos(obj.x+1, obj.y+1)
- term.setTextColor(obj.color)
- write(obj.label)
- end
- end
- local function gui()
- term.setTextColor(colors.red)
- term.setCursorPos(1,1)
- write("."..string.rep("-", tX-2)..".")
- for i = 2, tY - 1 do
- term.setCursorPos(1,i)
- write("|")
- term.setCursorPos(tX,i)
- write("|")
- end
- term.setCursorPos(1,tY)
- write("'"..string.rep("-", tX-2).."'")
- term.setTextColor(colors.yellow)
- end
- local function display(scan)
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.lightGray)
- for i = 3, 5 do
- term.setCursorPos(3,i)
- write(string.rep(" ", 15))
- end
- term.setTextColor(colors.gray)
- term.setBackgroundColor(colors.black)
- for i = 1, #scannerFrame do
- term.setCursorPos(24,i + 4)
- write(scannerFrame[i])
- end
- term.setTextColor(scan and colors.gray or colors.lightGray)
- term.setBackgroundColor(scan and colors.lime or colors.green)
- for i = 1, #scanner do
- term.setCursorPos(25,i + 5)
- write(scanner[i])
- end
- end
- --PIN functions
- --retrieve PIN from file
- local function retrieve()
- local readFile = fs.open(".PIN", "r")
- local pinText = readFile.readAll()
- readFile.close()
- local pinTab = textutils.unserialize(pinText)
- return pinTab
- end
- --create new PIN
- local function saveNew(pin)
- if fs.exists(".PIN") then
- fs.delete(".PIN")
- end
- local newFile = fs.open(".PIN", "w")
- newFile.write(textutils.serialize(pin))
- newFile.close()
- end
- local function takeNumbers()
- local verPin = {}
- while true do
- local events = {os.pullEvent()}
- if events[1] == "mouse_click" and events[2] == 1 then
- if events[3] >= 3 and events[3] <= 7 and events[4] >= 6 and events[4] <= 8 then
- table.insert(verPin, 1)
- elseif events[3] >= 8 and events[3] <= 12 and events[4] >= 6 and events[4] <= 8 then
- table.insert(verPin, 2)
- elseif events[3] >= 13 and events[3] <= 17 and events[4] >= 6 and events[4] <= 8 then
- table.insert(verPin, 3)
- elseif events[3] >= 3 and events[3] <= 7 and events[4] >= 9 and events[4] <= 11 then
- table.insert(verPin, 4)
- elseif events[3] >= 8 and events[3] <= 12 and events[4] >= 9 and events[4] <= 11 then
- table.insert(verPin, 5)
- elseif events[3] >= 13 and events[3] <= 17 and events[4] >= 9 and events[4] <= 11 then
- table.insert(verPin, 6)
- elseif events[3] >= 3 and events[3] <= 7 and events[4] >= 12 and events[4] <= 14 then
- table.insert(verPin, 7)
- elseif events[3] >= 8 and events[3] <= 12 and events[4] >= 12 and events[4] <= 14 then
- table.insert(verPin, 8)
- elseif events[3] >= 13 and events[3] <= 17 and events[4] >= 12 and events[4] <= 14 then
- table.insert(verPin, 9)
- elseif events[3] >= 3 and events[3] <= 7 and events[4] >= 15 and events[4] <= 17 then
- verPin = {}
- elseif events[3] >= 8 and events[3] <= 12 and events[4] >= 15 and events[4] <= 17 then
- table.insert(verPin, 0)
- elseif events[3] >= 13 and events[3] <= 17 and events[4] >= 15 and events[4] <= 17 then
- if #verPin == 4 then break end
- end
- if # verPin >= 5 then table.remove(verPin, #verPin) end
- display()
- for i = 1, #verPin do
- term.setTextColor(colors.red)
- term.setBackgroundColor(colors.lightGray)
- term.setCursorPos(i == 1 and 3 or i== 2 and 7 or i == 3 and 11 or i == 4 and 15 ,3)
- write("\\|/")
- term.setCursorPos(i == 1 and 3 or i== 2 and 7 or i == 3 and 11 or i == 4 and 15 ,4)
- write("-+-")
- term.setCursorPos(i == 1 and 3 or i== 2 and 7 or i == 3 and 11 or i == 4 and 15 ,5)
- write("/|\\")
- end
- end
- end
- return verPin
- end
- --verification
- local function verify()
- local curPin = retrieve()
- if tonumber(curPin[1]) == 0 and tonumber(curPin[2]) == 0 and tonumber(curPin[3]) == 0 and tonumber(curPin[4]) == 0 then
- term.setCursorPos(5,4)
- term.setTextColor(colors.yellow)
- term.setBackgroundColor(colors.lightGray)
- write("Create PIN")
- local newPin = takeNumbers()
- saveNew(newPin)
- return "NEW"
- else
- term.setCursorPos(5,4)
- term.setTextColor(colors.yellow)
- term.setBackgroundColor(colors.lightGray)
- write("Enter PIN")
- local checkPin = takeNumbers()
- if tonumber(checkPin[1]) == tonumber(curPin[1]) and tonumber(checkPin[2]) == tonumber(curPin[2]) and tonumber(checkPin[3]) == tonumber(curPin[3]) and tonumber(checkPin[4]) == tonumber(curPin[4]) then
- return true
- else
- return false
- end
- end
- end
- --operation loop
- if door and bios then
- print("Error occured in configuration.")
- print(shell.getRunningProgram().." cannot be used as a door lock as well as an OS protection")
- print("Please check config options and try again")
- return
- end
- while true do
- draw()
- gui()
- display(false)
- local state = verify()
- if door and state == true then
- display(true)
- term.setCursorPos(5,3)
- term.setTextColor(colors.yellow)
- term.setBackgroundColor(colors.lightGray)
- write("Place hand")
- term.setCursorPos(5,5)
- write("on scanner")
- while true do
- local events = {os.pullEvent()}
- if events[1] == "mouse_click" and events[2] == 1 then
- if events[3] >= 25 and events[3] <= 43 then
- if events[4] >= 6 and events[4] <= 16 then
- for i = 1, #scanner do
- term.setTextColor(colors.gray)
- term.setCursorPos(25,i + 5)
- term.setBackgroundColor(colors.yellow)
- write(scanner[i])
- sleep(.1)
- term.setCursorPos(25, i + 5)
- term.setBackgroundColor(colors.lime)
- write(scanner[i])
- end
- for i = #scanner, 1, -1 do
- term.setTextColor(colors.gray)
- term.setCursorPos(25,i + 5)
- term.setBackgroundColor(colors.yellow)
- write(scanner[i])
- sleep(.1)
- term.setCursorPos(25, i + 5)
- term.setBackgroundColor(colors.lime)
- write(scanner[i])
- end
- break
- end
- end
- end
- end
- rs.setOutput(doorSide, true)
- sleep(3)
- rs.setOutput(doorSide, false)
- elseif bios and state == true then
- display(true)
- term.setCursorPos(5,3)
- term.setTextColor(colors.yellow)
- term.setBackgroundColor(colors.lightGray)
- write("Place hand")
- term.setCursorPos(5,5)
- write("on scanner")
- while true do
- local events = {os.pullEvent()}
- if events[1] == "mouse_click" and events[2] == 1 then
- if events[3] >= 25 and events[3] <= 43 then
- if events[4] >= 6 and events[4] <= 16 then
- for i = 1, #scanner do
- term.setTextColor(colors.gray)
- term.setCursorPos(25,i + 5)
- term.setBackgroundColor(colors.yellow)
- write(scanner[i])
- sleep(.1)
- term.setCursorPos(25, i + 5)
- term.setBackgroundColor(colors.lime)
- write(scanner[i])
- end
- for i = #scanner, 1, -1 do
- term.setTextColor(colors.gray)
- term.setCursorPos(25,i + 5)
- term.setBackgroundColor(colors.yellow)
- write(scanner[i])
- sleep(.1)
- term.setCursorPos(25, i + 5)
- term.setBackgroundColor(colors.lime)
- write(scanner[i])
- end
- break
- end
- end
- end
- end
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- break
- elseif not state == true then
- display(false)
- term.setCursorPos(6,4)
- term.setTextColor(colors.yellow)
- term.setBackgroundColor(colors.lightGray)
- write("Incorrect")
- sleep(2)
- end
- end
- shell.run(".MicroData/Data/boot")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement