Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local mn = peripheral.wrap("front")
- local dside = "drive_7"
- local screen = 1
- rednet.open("back")
- os.loadAPI("Base64")
- local card = nil
- local isCard = false
- mn.setBackgroundColor(colors.white)
- mn.clear()
- mn.setCursorPos(1,1)
- mn.write("Vstavte")
- mn.setCursorPos(1,2)
- mn.write("kartu")
- -- funcs
- local function clear()
- mn.clear()
- end
- local function setTextColor(clr)
- mn.setTextColor(clr)
- end
- local function setCursorPos(x,y)
- mn.setCursorPos(x,y)
- end
- local function setBackgroundColor(clr)
- mn.setBackgroundColor(clr)
- end
- local function write(txt)
- mn.write(txt)
- end
- local sx,sy = mn.getSize()
- function drawBT(colorm, txt, line)
- setBackgroundColor(colorm)
- setCursorPos(1,line)
- for i=1,sx do
- setBackgroundColor(colorm)
- for g=line,3 do
- setCursorPos(i,g)
- write(" ")
- end
- end
- setCursorPos(3,line+1)
- write(txt)
- end
- -- loop
- mn.setTextScale(0.5)
- function bank()
- while true do
- local event, side = os.pullEvent()
- local cardfile = fs.open("/disk/card","r")
- if (side == dside) then
- if (cardfile) then
- clear()
- screen = 2
- drawBT(colors.green,"Enter PIN",1)
- setBackgroundColor(colors.red)
- setTextColor(colors.white)
- isCard = true
- setCursorPos(1,sy)
- pin = nil
- write("OtmeHitb")
- card = cardfile.readLine()
- cardfile.close()
- elseif (isCard == true and isCard ~= "ignore") then
- clear()
- setCursorPos(1,2)
- setTextColor(colors.red)
- setBackgroundColor(colors.white)
- write("Dosvidanija!")
- screen = 1
- isCard = false
- disk.eject(dside)
- os.sleep(1)
- setBackgroundColor(colors.white)
- clear()
- setCursorPos(1,1)
- write("Bctabte")
- setCursorPos(1,2)
- write("kartu")
- else if (isCard == "ignore") then
- isCard = false
- else
- clear()
- setCursorPos(1,2)
- setTextColor(colors.red)
- setBackgroundColor(colors.white)
- write("Eto ne karta!")
- screen = 1
- isCard = false
- disk.eject(dside)
- os.sleep(1)
- setBackgroundColor(colors.white)
- clear()
- setCursorPos(1,1)
- write("Bctabte")
- setCursorPos(1,2)
- write("kartu")
- end
- end
- end
- end
- end
- local pin = nil
- --pin
- function drawPinBT(color,textcolor,startX,endX,startY,endY,txt,txtLine)
- setBackgroundColor(color)
- setTextColor(textcolor)
- for i=startX,endX do
- for g=startY,endY do
- setCursorPos(i,g)
- write(" ")
- end
- end
- setCursorPos(startX,txtLine)
- write(txt)
- end
- function removeFromPin()
- setBackgroundColor(colors.white)
- setTextColor(colors.black)
- setCursorPos(1,1)
- if pin then
- for i=1,20 do
- setCursorPos(i,1)
- write(" ")
- end
- setCursorPos(1,1)
- pin = string.sub(pin, 1, -2)
- write(pin)
- end
- end
- function addToPin(value)
- setBackgroundColor(colors.white)
- if (not pin or string.len(pin) < 11) then
- if pin ~= nil then
- setCursorPos(1,1)
- setTextColor(colors.black)
- pin = pin..value
- for i=1,string.len(pin) do
- setCursorPos(i,1)
- write("*")
- end
- setCursorPos(string.len(pin),1)
- write(string.sub(pin,-1))
- else
- pin = value
- setCursorPos(1,1)
- setTextColor(colors.black)
- write(pin)
- end
- end
- end
- function drawPin()
- pin = nil
- drawPinBT(colors.red,colors.white,2,2,2,2,"1",2)
- drawPinBT(colors.orange,colors.white,4,4,2,2,"2",2)
- drawPinBT(colors.red,colors.white,6,6,2,2,"3",2)
- drawPinBT(colors.orange,colors.white,2,2,4,4,"4",4)
- drawPinBT(colors.red,colors.white,4,4,4,4,"5",4)
- drawPinBT(colors.orange,colors.white,6,6,4,4,"6",4)
- drawPinBT(colors.red,colors.white,2,2,6,6,"7",6)
- drawPinBT(colors.orange,colors.white,4,4,6,6,"8",6)
- drawPinBT(colors.red,colors.white,6,6,6,6,"9",6)
- drawPinBT(colors.orange,colors.white,4,4,8,8,"0",8)
- drawPinBT(colors.red,colors.white,6,6,8,8,"C",8)
- drawPinBT(colors.green,colors.white,8,15,8,8,"Confirm",8)
- end
- --
- local nick = nil
- local bal = nil
- --
- function click()
- while true do
- event, side, xPos, yPos = os.pullEvent("monitor_touch")
- if (screen == 2) then
- if (yPos > 0 and yPos < 4 and xPos> 0 and xPos < sx+1) then
- print("PIN")
- screen = 3
- setBackgroundColor(colors.white)
- clear()
- drawPin()
- elseif (yPos == sy and xPos< 10) then
- print("SCREEN 1")
- clear()
- setCursorPos(1,2)
- setTextColor(colors.red)
- setBackgroundColor(colors.white)
- write("Dosvidanija!")
- screen = 1
- disk.eject(dside)
- isCard = "ignore"
- os.sleep(1)
- setBackgroundColor(colors.white)
- clear()
- setCursorPos(1,1)
- write("Vstavte")
- setCursorPos(1,2)
- write("kartu")
- end
- elseif (screen == 3) then
- if (yPos == 2 and xPos == 2) then
- addToPin("1")
- elseif (yPos == 2 and xPos == 4) then
- addToPin("2")
- elseif (yPos == 2 and xPos == 6) then
- addToPin("3")
- elseif (yPos == 4 and xPos == 2) then
- addToPin("4")
- elseif (yPos == 4 and xPos == 4) then
- addToPin("5")
- elseif (yPos == 4 and xPos == 6) then
- addToPin("6")
- elseif (yPos == 6 and xPos == 2) then
- addToPin("7")
- elseif (yPos == 6 and xPos == 4) then
- addToPin("8")
- elseif (yPos == 6 and xPos == 6) then
- addToPin("9")
- elseif (yPos == 8 and xPos == 4) then
- addToPin("0")
- elseif (yPos == 8 and xPos == 6) then
- removeFromPin()
- elseif (yPos == 8 and xPos > 7 and xPos < 16) then
- rednet.send(40,Base64.encode("login "..card.." "..pin),"bank44")
- event, senderId, message, distance = os.pullEvent("rednet_message")
- message = Base64.decode(message)
- local ii = 1
- for word in string.gmatch(message,"%S+") do
- if (ii == 1) then
- nick = word
- elseif (ii == 2) then
- bal = word
- end
- ii = ii +1
- end
- if (message == "error1") then
- print("SCREEN 1")
- clear()
- setCursorPos(1,2)
- setTextColor(colors.red)
- setBackgroundColor(colors.white)
- write("ERROR")
- setCursorPos(1,3)
- write("Takoy karty netu!")
- screen = 1
- isCard = "ignore"
- disk.eject(dside)
- os.sleep(1)
- setBackgroundColor(colors.white)
- clear()
- setCursorPos(1,1)
- write("Vstavte")
- setCursorPos(1,2)
- write("kartu")
- elseif (message == "error2") then
- print("SCREEN 1")
- clear()
- setCursorPos(1,2)
- setTextColor(colors.red)
- setBackgroundColor(colors.white)
- write("ERROR")
- setCursorPos(1,3)
- write("Nevernyi parol!")
- screen = 1
- isCard = "ignore"
- disk.eject(dside)
- os.sleep(1)
- setBackgroundColor(colors.white)
- clear()
- setCursorPos(1,1)
- write("Vstavte")
- setCursorPos(1,2)
- write("kartu")
- else
- setBackgroundColor(colors.white)
- clear()
- screen = 4
- drawPinBT(colors.red,colors.white,1,8,2,2,"Balance",2)
- drawPinBT(colors.red,colors.white,1,16,4,4,"Snyat nalichku",4)
- drawPinBT(colors.red,colors.white,1,16,6,6,"Perevesti dengi",6)
- drawPinBT(colors.green,colors.white,1,6,10,10,"Vyiti",10)
- end
- end
- elseif (screen == 4) then
- if (yPos == 2 and xPos > 0 and xPos < 9) then
- setBackgroundColor(colors.white)
- clear()
- drawPinBT(colors.white,colors.red,1,15,2,2,"Balans: "..bal.."AR",2)
- drawPinBT(colors.red,colors.white,1,7,8,8,"Vyiti",8)
- screen = 5
- elseif (yPos == 4 and xPos < 17) then
- elseif (yPos == 6 and xPos < 17) then
- elseif(yPos == 10 and xPos < 7) then
- print("SCREEN 1")
- clear()
- setCursorPos(1,2)
- setTextColor(colors.red)
- setBackgroundColor(colors.white)
- write("Dosvidanija!")
- screen = 1
- isCard = "ignore"
- disk.eject(dside)
- os.sleep(1)
- setBackgroundColor(colors.white)
- clear()
- setCursorPos(1,1)
- write("Vstavte")
- setCursorPos(1,2)
- write("kartu")
- end
- elseif (screen == 5) then
- if (yPos == 8 and xPos > 0 and xPos < 9) then
- screen = 4
- setBackgroundColor(colors.white)
- drawPinBT(colors.red,colors.white,1,8,2,2,"Balance",2)
- drawPinBT(colors.red,colors.white,1,16,4,4,"Snyat nalichku",4)
- drawPinBT(colors.red,colors.white,1,16,6,6,"Perevesti dengi",6)
- drawPinBT(colors.green,colors.white,1,6,10,10,"Vyiti",10)
- clear()
- end
- end
- end
- end
- parallel.waitForAll(bank,click)
Add Comment
Please, Sign In to add comment