Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local cmp = require('component')
- local event = require('event')
- local serialization = require('serialization')
- local gpu=cmp.gpu
- local filesystem=require('filesystem')
- local term =require('term')
- local computer = require('computer')
- local unicode = require('unicode')
- local draw = require('draw')
- local sides = require("sides")
- local note = require("note")
- local keyboard = require("keyboard")
- ------------
- local A,B=gpu.getResolution()
- local oldBack = gpu.getBackground()
- local oldFore = gpu.getForeground()
- local usersFile = 'users.list'
- ------------
- gpu.setResolution(120,40)
- ------------
- local color={
- back=0xDCDCDC,
- line=0X505050,
- pass_field=0,
- enter_pass=0x898989,
- user_name=123123,
- user_frame=0x505050
- }
- local buttonsUsers={
- {72,11,9,7}, -- Right
- {39,11,9,7}, -- Left
- {45,27,30,3} -- Password Field
- }
- local function saveTbl(tbl, fl)
- file = io.open(fl, 'w')
- file:write(serialization.serialize(tbl))
- file:close()
- end
- local function loadTbl(fl)
- file = io.open(fl, 'r')
- if not file then
- file = io.open(fl, 'w')
- file:write('{}')
- return {} else
- return serialization.unserialize(file:read('*a'))
- end
- file:close()
- end
- function getRawEvent(arr)
- local N = nil
- local key,_,x,y,clickMouse,name=event.pull()
- if key == 'touch' then
- for i=1,#arr do
- if x > arr[i][1]-1 and x < arr[i][1]+arr[i][3] and y > arr[i][2]-1 and y < arr[i][2]+arr[i][4] then
- N=i
- break
- end
- end
- end
- if N == nil then
- N = 0
- end
- return key,N,clickMouse,name
- end
- function enterPassword(userName)
- draw.field(46,28,28,1,' ',color.pass_field,0x505050)
- term.setCursor(47,28)
- local password = users[userName][2]
- local function getKey(s)
- local _, _, _, code, _ = event.pull("key_up")
- return code
- end
- local function enterPass()
- try = ""
- ex=true
- while ex do
- local err, f = pcall(getKey)
- if not err then
- return err, try
- end
- if keyboard.keys[f] == 'grave' then ex=false end
- if f < 60 and f > 0 then
- if keyboard.keys[f] == 'enter' then
- return err, try
- end
- if keyboard.keys[f] == 'back' then
- if unicode.len(try) > 0 then
- try=unicode.sub(try,0,unicode.len(try)-1)
- draw.field(46,28,28,1,' ',color.pass_field,0x505050)
- draw.field(46,28,unicode.len(try),1,'*',color.pass_field,0x505050)
- end
- end
- if unicode.len(keyboard.keys[f]) == 1 and unicode.len(try) < 28 then
- try = try..keyboard.keys[f]
- draw.field(46,28,28,1,' ',color.pass_field,0x505050)
- if try ~= nil then
- try2='' for l=1,unicode.len(try) do try2=try2..'*' end
- end
- draw.text(46,28,28,try2,color.pass_field,color.enter_pass)
- end
- end
- end
- end
- while true do
- err, try = enterPass()
- if not err then
- draw.field(46,28,28,1,' ',color.pass_field,0x505050)
- draw.text(46,28,28,"Самый умный? =)",color.pass_field,color.enter_pass)
- elseif try == password then -- success
- note.play(83, 0.3)
- note.play(90, 0.2)
- draw.field(46,28,28,1,' ',color.pass_field,color.enter_pass)
- draw.text(46,28,28,'Доступ разрешен!',color.pass_field,0x00AA00)
- os.sleep(2.5)
- gpu.setBackground(oldBack)
- gpu.setForeground(oldFore)
- gpu.setResolution(A,B)
- term.clear()
- os.exit()
- elseif try == "power" then -- admin pass
- os.exit()
- elseif try == "cls" then
- -- term.clear()
- else
- draw.field(46,28,28,1,' ',color.pass_field,color.enter_pass)
- draw.text(46,28,28,"В доступе отказано!",color.pass_field,0xAA0000)
- note.play(70, 0.2)
- end
- end
- end
- function drawUsersList()
- selectUser=1
- local function drawUser(selectUser)
- -- <user>
- draw.field(51,10,18,9,' ',color.user_frame,0x505050)
- draw.clound('┌','┐','└','┘','│','─',51,10,18,9,color.user_frame,0xFFFFFF)
- draw.text(52,14,16,users[selectUser][1],color.user_frame,color.user_name)
- -- </user>
- end
- drawUser(selectUser)
- -- <Right>
- draw.field(72,11,4,7,' ',0xFFA400,0x505050)
- draw.field(76,12,2,5,' ',0xFFA400,0x505050)
- draw.field(78,13,2,3,' ',0xFFA400,0x505050)
- draw.field(80,14,1,1,' ',0xFFA400,0x505050)
- -- </Right>
- -- <Left>
- draw.field(44,11,4,7,' ',0xFFA400,0x505050)
- draw.field(42,12,2,5,' ',0xFFA400,0x505050)
- draw.field(40,13,2,3,' ',0xFFA400,0x505050)
- draw.field(39,14,1,1,' ',0xFFA400,0x505050)
- -- </Left>
- -- <line>
- draw.field(20,21,80,1,'─',color.back,color.line)
- draw.field(20,8,80,1,'─',color.back,color.line)
- -- </line>
- -- <Password_Field>
- draw.field(45,27,30,3,' ',color.pass_field,0x505050)
- draw.clound('┌','┐','└','┘','│','─',45,27,30,3,color.pass_field,0xFFFFFF)
- draw.text(47,28,17,'Введите пароль...',color.pass_field,color.enter_pass)
- -- </Password_Field>
- while true do
- key,N,clickMouse,name=getRawEvent(buttonsUsers)
- if N == 1 then
- selectUser = selectUser+1
- if selectUser > #users then
- selectUser = #users
- end
- drawUser(selectUser)
- elseif N == 2 then
- selectUser = selectUser-1
- if selectUser < 1 then
- selectUser = 1
- end
- drawUser(selectUser)
- elseif N == 3 then
- enterPassword(selectUser)
- end
- end
- end
- if filesystem.exists(usersFile) == true then
- term.clear()
- draw.err('Добро пожаловать!',1,2)
- term.clear()
- users=loadTbl(usersFile)
- drawUsersList()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement