lego11

Nebraska Pay Chiosco

Jan 30th, 2019 (edited)
4,991
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 45.22 KB | None | 0 0
  1. local maxw, maxh = term.getSize()
  2.  
  3. -- IMPLEMENTAZIONE DEL DRAWFILLEDBOX
  4. local function drawPixelInternal(xPos, yPos)
  5.     term.setCursorPos(xPos, yPos)
  6.     term.write(" ")
  7. end
  8.  
  9. local tColourLookup = {}
  10. for n = 1, 16 do
  11.     tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
  12. end
  13.  
  14. function drawFilledBox(startX, startY, endX, endY, nColour)
  15.     if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~= "number" or type(endY) ~= "number" or
  16.         (nColour ~= nil and type(nColour) ~= "number") then
  17.         error("Expected startX, startY, endX, endY, colour", 2)
  18.     end
  19.  
  20.     startX = math.floor(startX)
  21.     startY = math.floor(startY)
  22.     endX = math.floor(endX)
  23.     endY = math.floor(endY)
  24.  
  25.     if nColour then
  26.         term.setBackgroundColor(nColour)
  27.     end
  28.     if startX == endX and startY == endY then
  29.         drawPixelInternal(startX, startY)
  30.         return
  31.     end
  32.  
  33.     local minX = math.min(startX, endX)
  34.     if minX == startX then
  35.         minY = startY
  36.         maxX = endX
  37.         maxY = endY
  38.     else
  39.         minY = endY
  40.         maxX = startX
  41.         maxY = startY
  42.     end
  43.  
  44.     for x = minX, maxX do
  45.         for y = minY, maxY do
  46.             drawPixelInternal(x, y)
  47.         end
  48.     end
  49. end
  50.  
  51. function clear()
  52.     sfondo(colors.lightBlue)
  53.     term.clear()
  54.     term.setCursorPos(1, 1)
  55. end
  56.  
  57. function colore(sfumatura)
  58.     term.setTextColour(sfumatura)
  59. end
  60.  
  61. function sfondo(sfumaturaSfondo)
  62.     term.setBackgroundColour(sfumaturaSfondo)
  63. end
  64.  
  65. function titolo(testo)
  66.     drawFilledBox(1, 1, maxw, 1, colors.yellow)
  67.     term.setCursorPos((maxw - #testo) / 2, 1)
  68.     colore(colors.black)
  69.     term.write(testo)
  70.     sfondo(colors.lightBlue)
  71. end
  72.  
  73. function update()
  74.     term.setCursorPos(1, 21)
  75.     shell.run("pastebin get y1AP0iNY startup2") -- Inserire paste di nPay
  76.     if fs.exists("startup2") then
  77.         shell.run("rm startup")
  78.         shell.run("mv startup2 startup")
  79.     end
  80.     os.reboot()
  81. end
  82.  
  83. function disconnetti()
  84.     clear()
  85.     text = "ARRIVEDERCI!"
  86.     colore(colors.white)
  87.     term.setCursorPos((maxw - #text) / 2, math.floor(maxh / 2))
  88.     term.write(text)
  89.     colore(colors.black)
  90.     text2 = "Tra poco sarà possibile eseguire"
  91.     text3 = "una nuova operazione..."
  92.     term.setCursorPos((maxw - #text2) / 2, math.floor(maxh / 2) + 2)
  93.     print(text2)
  94.     term.setCursorPos((maxw - #text3) / 2, math.floor(maxh / 2) + 3)
  95.     print(text3)
  96.     os.sleep(0.5)
  97.     update()
  98. end
  99.  
  100. function drawCard()
  101.     drawFilledBox(6, 7, 24, 7, colors.blue)
  102.     drawFilledBox(6, 15, 24, 15, colors.blue)
  103.     drawFilledBox(5, 8, 25, 14, colors.blue)
  104.  
  105.     drawFilledBox(7, 9, 23, 9, colors.lightGray)
  106.     drawFilledBox(7, 12, 23, 13, colors.black)
  107. end
  108.  
  109. mag = peripheral.wrap("bottom")
  110. bl = "BN Credit"
  111.  
  112. sfondo(colors.lightBlue)
  113. clear()
  114.  
  115. colore(colors.white)
  116. print(" ")
  117. print("                      ___            ")
  118. print("              _ __   / _ \\__ _ _   _ ")
  119. print("             | '_ \\ / /_)/ _  | | | |")
  120. print("             | | | / ___/ (_| | |_| |")
  121. print("             |_| |_\\/    \\__,_|\\__, |")
  122. print("                                |___/ ")
  123.  
  124. -- Bottoni login/registrati
  125.  
  126. drawFilledBox(14, 10, 38, 12, colors.white)
  127. term.setCursorPos(23, 11)
  128. colore(colors.black)
  129. term.write("Accedi")
  130.  
  131. drawFilledBox(14, 15, 38, 17, colors.white)
  132. term.setCursorPos(21, 16)
  133. colore(colors.black)
  134. term.write("Sei nuovo?")
  135.  
  136. while true do
  137.     event, key, x, y = os.pullEvent("mouse_click")
  138.     if event == "mouse_click" and x >= 14 and x <= 38 and y >= 15 and y <= 17 then
  139.         -- Registrazione nuovo utente
  140.         clear()
  141.         titolo("Registrati a nPay")
  142.         term.setCursorPos(1, 3)
  143.         print("Inserisci un nome utente e una password sicura.")
  144.         term.setCursorPos(1, 5)
  145.         colore(colors.gray)
  146.         print(
  147.             "Premi ENTER per confermare i dati inseriti.\nSe i dati sono corretti, il campo diventerà verde.\nSe sono errati, il programma chiederà di reinserirli nuovamente.")
  148.  
  149.         -- Nome Utente
  150.         term.setCursorPos(1, 10)
  151.         colore(colors.black)
  152.         term.write("Nome utente:")
  153.         term.setCursorPos(14, 10)
  154.         colore(colors.white)
  155.         utenteAccettato = false
  156.         conteggioErrori = 0
  157.         while utenteAccettato == false do
  158.             utente = read()
  159.             utente = string.gsub(utente, "%s", "")
  160.             checkuser = http.get(
  161.                             "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=no&richiesta=verifica&utente=" ..
  162.                                 utente).readAll()
  163.             tabcheckuser = textutils.unserialize(checkuser)
  164.             if tabcheckuser.stato == "NO" then
  165.                 term.setCursorPos(14, 10)
  166.                 colore(colors.lime)
  167.                 term.write(utente)
  168.                 colore(colors.white)
  169.                 utenteAccettato = true
  170.             else
  171.                 term.setCursorPos(14, 10)
  172.                 colore(colors.red)
  173.                 term.write("Utente già esistente!")
  174.                 sleep(2)
  175.                 term.setCursorPos(14, 10)
  176.                 colore(colors.white)
  177.                 term.write("                       ")
  178.                 term.setCursorPos(14, 10)
  179.                 conteggioErrori = conteggioErrori + 1
  180.                 if conteggioErrori > 2 then
  181.                     term.setCursorPos(14, 10)
  182.                     colore(colors.red)
  183.                     term.write("Tre tentativi di immissione errati.")
  184.                     sleep(2)
  185.                     term.setCursorPos(14, 10)
  186.                     colore(colors.white)
  187.                     term.write("                       ")
  188.                     term.setCursorPos(14, 10)
  189.                     clear()
  190.                     os.reboot()
  191.                 end
  192.             end
  193.         end
  194.  
  195.         -- password
  196.         colore(colors.black)
  197.         term.setCursorPos(1, 12)
  198.         term.write("Password:")
  199.         term.setCursorPos(11, 12)
  200.         colore(colors.white)
  201.  
  202.         passAccettata = false
  203.         conteggioErrori = 0
  204.         while passAccettata == false do
  205.             password1 = read("#")
  206.             colore(colors.black)
  207.             term.setCursorPos(1, 13)
  208.             term.write("Verifica:")
  209.             term.setCursorPos(11, 13)
  210.             colore(colors.white)
  211.             local password2 = read("#")
  212.             if password1 == password2 then
  213.                 term.setCursorPos(11, 12)
  214.                 colore(colors.lime)
  215.                 term.write("###############")
  216.                 term.setCursorPos(11, 13)
  217.                 term.write("###############")
  218.                 colore(colors.white)
  219.                 passAccettata = true
  220.             else
  221.                 colore(colors.red)
  222.                 term.setCursorPos(11, 12)
  223.                 term.write("Le password non corrispondono!    ")
  224.                 term.setCursorPos(1, 13)
  225.                 colore(colors.white)
  226.                 term.write("                               ")
  227.                 sleep(1.5)
  228.                 term.setCursorPos(11, 12)
  229.                 term.write("                               ")
  230.                 term.setCursorPos(11, 12)
  231.                 conteggioErrori = conteggioErrori + 1
  232.                 if conteggioErrori > 2 then
  233.                     term.setCursorPos(14, 12)
  234.                     colore(colors.red)
  235.                     term.write("Tre tentativi di immissione errati.")
  236.                     sleep(1.5)
  237.                     term.setCursorPos(14, 12)
  238.                     colore(colors.white)
  239.                     term.write("                       ")
  240.                     term.setCursorPos(14, 12)
  241.                     clear()
  242.                     os.reboot()
  243.                 end
  244.             end
  245.         end
  246.  
  247.         -- crea l'account
  248.  
  249.         term.setCursorPos(1, 17)
  250.         creaAccount = http.get(
  251.                           "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" .. password1 .. "&utente=" ..
  252.                               utente .. "&richiesta=crea&valore=0").readAll()
  253.         tabCreaAccount = textutils.unserialize(creaAccount)
  254.         if tabCreaAccount.stato == "OA" then
  255.             colore(colors.lime)
  256.             print("Conto creato con successo.")
  257.             sleep(1.5)
  258.             clear()
  259.             os.reboot()
  260.         else
  261.             colore(colors.red)
  262.             print("Errore durante la creazione del conto.")
  263.             sleep(1.5)
  264.             clear()
  265.             os.reboot()
  266.         end
  267.  
  268.     elseif event == "mouse_click" and x >= 14 and x <= 38 and y >= 10 and y <= 12 then
  269.         clear()
  270.         titolo("Accedi a nPay")
  271.         term.setCursorPos(1, 3)
  272.         colore(colors.black)
  273.         print("Inserire i propri dati.")
  274.         colore(colors.gray)
  275.         print(
  276.             "\nPremere Enter per confermare i dati inseriti.\nSe i dati sono corretti, il campo diventerà verde.\nSe sono errati, il programma chiederà di reinserirli nuovamente.")
  277.  
  278.         -- nomeutente
  279.         term.setCursorPos(1, 10)
  280.         colore(colors.black)
  281.         term.write("Nome utente:")
  282.         term.setCursorPos(15, 10)
  283.         colore(colors.white)
  284.         utenteAccettato = false
  285.         conteggioErrori = 0
  286.         while utenteAccettato == false do
  287.             utente = read()
  288.             utente = string.gsub(utente, "%s", "")
  289.             checkuser = http.get(
  290.                             "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=no&richiesta=verifica&utente=" ..
  291.                                 utente).readAll()
  292.             tabcheckuser = textutils.unserialize(checkuser)
  293.             if tabcheckuser.stato == "OK" then
  294.                 term.setCursorPos(15, 10)
  295.                 colore(colors.lime)
  296.                 term.write(utente)
  297.                 colore(colors.white)
  298.                 utenteAccettato = true
  299.             else
  300.                 term.setCursorPos(15, 10)
  301.                 colore(colors.red)
  302.                 term.write("Utente errato!          ")
  303.                 sleep(2)
  304.                 term.setCursorPos(15, 10)
  305.                 colore(colors.white)
  306.                 term.write("                       ")
  307.                 term.setCursorPos(15, 10)
  308.                 conteggioErrori = conteggioErrori + 1
  309.                 if conteggioErrori > 2 then
  310.                     term.setCursorPos(15, 10)
  311.                     colore(colors.red)
  312.                     term.write("Tre tentativi di immissione errati.")
  313.                     sleep(2)
  314.                     term.setCursorPos(15, 10)
  315.                     colore(colors.white)
  316.                     term.write("                       ")
  317.                     term.setCursorPos(15, 10)
  318.                     clear()
  319.                     os.reboot()
  320.                 end
  321.             end
  322.         end
  323.  
  324.         -- password
  325.         colore(colors.black)
  326.         term.setCursorPos(1, 12)
  327.         term.write("Password:")
  328.         term.setCursorPos(15, 12)
  329.  
  330.         conteggioErrori = 0
  331.         passAccettata = false
  332.         while passAccettata == false do
  333.             colore(colors.white)
  334.             password = read("#")
  335.             password = string.gsub(password, "%s", "")
  336.             colore(colors.black)
  337.             checkuser = http.get("http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" .. password ..
  338.                                      "&richiesta=addebito&valore=0&utente=" .. utente).readAll()
  339.             risposta = textutils.unserialize(checkuser)
  340.             if risposta.stato == "OK" then
  341.                 term.setCursorPos(15, 12)
  342.                 colore(colors.lime)
  343.                 term.write("##############               ")
  344.                 colore(colors.white)
  345.                 passAccettata = true
  346.             else
  347.                 term.setCursorPos(15, 12)
  348.                 colore(colors.red)
  349.                 term.write("Password errata!            ")
  350.                 conteggioErrori = conteggioErrori + 1
  351.                 sleep(2)
  352.                 term.setCursorPos(15, 12)
  353.                 term.write("                               ")
  354.                 term.setCursorPos(15, 12)
  355.                 if conteggioErrori > 2 then
  356.                     term.setCursorPos(15, 12)
  357.                     colore(colors.red)
  358.                     term.write("Tre tentativi di immissione errati.")
  359.                     sleep(2)
  360.                     term.setCursorPos(15, 12)
  361.                     term.write("                               ")
  362.                     term.setCursorPos(15, 12)
  363.                     clear()
  364.                     os.reboot()
  365.                 end
  366.             end
  367.         end
  368.  
  369.         conteggioErrori = 0
  370.         -- Pagina in cui scegli le operazioni da fare
  371.  
  372.         while true do
  373.             -- Ricontrolla il saldo per gestire l'aggiornamento di più operazioni
  374.             checkuser = http.get("http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" .. password ..
  375.                                      "&richiesta=addebito&valore=0&utente=" .. utente).readAll()
  376.             risposta = textutils.unserialize(checkuser)
  377.             saldo = tonumber(risposta.saldo)
  378.             -- Disegna la finestra del pannello utente
  379.             clear()
  380.             titolo("Pannello utente nPay")
  381.             term.setCursorPos(1, 3)
  382.             term.write("Benvenuto, ")
  383.             colore(colors.white)
  384.             term.write(utente)
  385.             colore(colors.black)
  386.             term.write("!         Saldo: ")
  387.             colore(colors.white)
  388.             term.write(saldo)
  389.             colore(colors.black)
  390.             term.write(" IC")
  391.             print("\n\nOperazioni disponibili:\n")
  392.             sfondo(colors.white)
  393.             print(" Carica denaro su nPay  \n")
  394.             print(" Preleva denaro da nPay \n")
  395.             print(" Trasferisci denaro     \n")
  396.             print(" Estratto conto         \n")
  397.             colore(colors.red)
  398.             print(" Disconnettiti da nPay  \n")
  399.             colore(colors.black)
  400.  
  401.             antitonto = os.startTimer(60)
  402.  
  403.             event, key, x, y = os.pullEventRaw()
  404.             if event == "mouse_click" and y == 7 and x <= 24 then -- Pulsante carica denaro su nPay
  405.                 clear()
  406.                 titolo("Caricamento denaro su nPay")
  407.  
  408.                 drawCard()
  409.  
  410.                 sfondo(colors.lightBlue)
  411.                 colore(colors.black)
  412.                 term.setCursorPos(30, 8)
  413.                 print("INSERIRE LA CARTA")
  414.                 term.setCursorPos(29, 10)
  415.                 print("NEL LETTORE IN BASSO")
  416.                 drawFilledBox(34, 14, 42, 14, colors.white)
  417.                 term.setCursorPos(35, 14)
  418.                 term.write("Annulla")
  419.  
  420.                 mag.setInsertCardLight(true)
  421.                 finalBreakC = false
  422.                 while true do
  423.                     event, arg1, arg2, arg3 = os.pullEventRaw()
  424.                     if event == "mouse_click" and arg3 == 14 and arg2 >= 34 and arg2 <= 42 then -- arg2 = x | arg3 = y
  425.                         mag.setInsertCardLight(false)
  426.                         clear()
  427.                         term.setCursorPos(1, 1)
  428.                         break
  429.                     elseif event == "mag_swipe" then
  430.                         mag.setInsertCardLight(false)
  431.                         tabel = textutils.unserialize(arg1)
  432.                         if tabel == "" or tabel == nil then
  433.                             clear()
  434.                             titolo("Caricamento denaro da nPay")
  435.  
  436.                             drawCard()
  437.  
  438.                             sfondo(colors.lightBlue)
  439.                             term.setCursorPos(36, 10)
  440.                             colore(colors.red)
  441.                             term.write("ERRORE!")
  442.                             term.setCursorPos(30, 12)
  443.                             colore(colors.black)
  444.                             term.write("Carta smagnetizzata!")
  445.                             os.sleep(3)
  446.                             break
  447.                         elseif tabel.t == "cc" then
  448.                             clear()
  449.                             titolo("Caricamento denaro da nPay")
  450.  
  451.                             drawCard()
  452.  
  453.                             sfondo(colors.lightBlue)
  454.                             term.setCursorPos(36, 10)
  455.                             colore(colors.red)
  456.                             term.write("ERRORE!")
  457.                             term.setCursorPos(31, 12)
  458.                             colore(colors.black)
  459.                             term.write("Carta NON SICURA!")
  460.                             term.setCursorPos(31, 13)
  461.                             term.write("Convertire la carta")
  462.                             term.setCursorPos(31, 14)
  463.                             term.write("presso gli sportelli")
  464.                             term.setCursorPos(31, 15)
  465.                             term.write("in banca")
  466.                             os.sleep(3)
  467.                             break
  468.  
  469.                         elseif tabel.t ~= "cd" or tabel.e ~= "BN" then
  470.                             clear()
  471.                             titolo("Caricamento denaro da nPay")
  472.  
  473.                             drawCard()
  474.  
  475.                             sfondo(colors.lightBlue)
  476.                             term.setCursorPos(36, 10)
  477.                             colore(colors.red)
  478.                             term.write("ERRORE!")
  479.                             term.setCursorPos(31, 12)
  480.                             colore(colors.black)
  481.                             term.write("Carta non valida o corrotta!")
  482.                             os.sleep(3)
  483.                             break
  484.                         else
  485.                             while true do
  486.                                 clear()
  487.                                 titolo("Caricamento denaro su nPay")
  488.                                 colore(colors.gray)
  489.                                 sibRaw = http.get(
  490.                                              "http://luanet.rgbcraft.com/servlets/carte_debito.php?richiesta=verifica&uuid=" ..
  491.                                                  tabel.v).readAll()
  492.                                 sib = textutils.unserialize(sibRaw)
  493.  
  494.                                 if type(sib) ~= "table" then
  495.                                     print("\n\n\nImpossibile comunicare con il server interbancario")
  496.                                     sleep(5)
  497.                                     os.reboot()
  498.                                 end
  499.                                 if sib.stato ~= "OK" then
  500.                                     print("\n\n\nLa carta non risulta nel sistema interbancario, potrebbe essere stata disabilitata per uso fraudolento")
  501.                                     sleep(5)
  502.                                     os.reboot()
  503.                                 end
  504.  
  505.                                 print("\n\nDisponibilità su carta:  " .. sib.saldo .. " IC")
  506.                                 colore(colors.red)
  507.                                 term.setCursorPos(1, 14)
  508.                                 term.write("ATTENZIONE:")
  509.                                 colore(colors.black)
  510.                                 term.setCursorPos(1, 15)
  511.                                 term.write("Grazie al Ministero dell'Abbondanza,")
  512.                                 -- term.write("Per le operazioni inferiori a 50 000 IC,")
  513.                                 term.setCursorPos(1, 16)
  514.                                 print("le operazioni su nPay sono GRATUITE!")
  515.                                 -- print("si applica una commissione del 0.15%.")
  516.                                 -- print("Oltre 50 000 IC la commissione è del 0.05%.")
  517.                                 term.setCursorPos(1, 5)
  518.                                 term.write("Importo da caricare: ")
  519.                                 colore(colors.white)
  520.                                 credito = tonumber(tabel.v)
  521.                                 credit = read()
  522.                                 if tonumber(credit) == "" or tonumber(credit) == nil or tonumber(credit) <= 0 then
  523.                                     colore(colors.red)
  524.                                     term.setCursorPos(22, 5)
  525.                                     term.write("Importo errato!                    ")
  526.                                     colore(colors.black)
  527.                                     sleep(1.5)
  528.                                     clear()
  529.                                 else
  530.                                     if tonumber(credit) >= 50000 then
  531.                                         -- commissioni = tonumber(credit) * 0.005
  532.                                         commissioni = tonumber(credit) * 0
  533.                                     else
  534.                                         -- commissioni = tonumber(credit) * 0.015
  535.                                         commissioni = tonumber(credit) * 0
  536.                                     end
  537.                                     crediton = credit + commissioni
  538.  
  539.                                     sibRaw = http.get(
  540.                                                  "http://luanet.rgbcraft.com/servlets/carte_debito.php?richiesta=addebito&valore=" ..
  541.                                                      crediton .. "&uuid=" .. tabel.v).readAll()
  542.                                     sib = textutils.unserialize(sibRaw)
  543.  
  544.                                     if type(sib) ~= "table" then
  545.                                         print("\n\n\nImpossibile comunicare con il server interbancario")
  546.                                         sleep(5)
  547.                                         os.reboot()
  548.                                     end
  549.                                     if sib.stato ~= "OK" then
  550.                                         print("\n\n\nLa carta non risulta nel sistema interbancario, potrebbe essere stata disabilitata per uso fraudolento")
  551.                                         sleep(5)
  552.                                         os.reboot()
  553.                                     end
  554.    
  555.  
  556.                                     if sib.stato == "OK" then
  557.                                         tab = http.get("http://172.16.20.220/luanet/servlets/nebraskapay.php?utente=" ..
  558.                                                            utente .. "&auth=" .. password ..
  559.                                                            "&richiesta=accredito&valore=" .. credit).readAll()
  560.                                         tabella = textutils.unserialize(tab)
  561.  
  562.                                         clear()
  563.                                         titolo("Caricamento denaro su nPay")
  564.  
  565.                                         colore(colors.lime)
  566.                                         term.setCursorPos(1, 3)
  567.                                         print("Operazione completata!")
  568.                                         colore(colors.black)
  569.                                         term.setCursorPos(1, 5)
  570.                                         print("Denaro accreditato: " .. credit .. " IC")
  571.                                         print("Commissioni:        " .. commissioni .. " IC")
  572.                                         term.setCursorPos(1, 8)
  573.                                         print("Saldo sul conto:    " .. tabella.credito .. " IC")
  574.                                         print("Saldo sulla carta:  " .. sib.credito .. " IC")
  575.                                         sfondo(colors.white)
  576.                                         term.setCursorPos(1, 12)
  577.                                         term.write(" Torna alla pagina principale ")
  578.                                         sfondo(colors.lightBlue)
  579.  
  580.                                         antiTonto2 = os.startTimer(15)
  581.                                         while true do
  582.                                             local event, arg1, arg2, arg3 = os.pullEventRaw()
  583.                                             if event == "mouse_click" and arg3 == 12 and arg2 <= 30 or event == "timer" and
  584.                                                 arg1 == antiTonto2 then -- arg2 = x | arg3 = y
  585.                                                 finalBreakC = true
  586.                                                 break
  587.                                             end
  588.                                         end
  589.                                         break
  590.                                     else
  591.                                         colore(colors.red)
  592.                                         term.setCursorPos(22, 5)
  593.                                         term.write("Credito su carta insufficente.")
  594.                                         colore(colors.black)
  595.                                         sleep(1.5)
  596.                                         clear()
  597.                                     end
  598.                                 end
  599.                             end
  600.                             if finalBreakC then
  601.                                 break
  602.                             end
  603.                         end
  604.                     end
  605.                 end
  606.  
  607.             elseif event == "mouse_click" and y == 9 and x <= 24 then -- Pulsante preleva denaro da nPay
  608.                 clear()
  609.                 titolo("Prelievo denaro da nPay")
  610.  
  611.                 drawCard()
  612.  
  613.                 sfondo(colors.lightBlue)
  614.                 colore(colors.black)
  615.                 term.setCursorPos(30, 8)
  616.                 print("INSERIRE LA CARTA")
  617.                 term.setCursorPos(29, 10)
  618.                 print("NEL LETTORE IN BASSO")
  619.                 drawFilledBox(34, 14, 42, 14, colors.white)
  620.                 term.setCursorPos(35, 14)
  621.                 term.write("Annulla")
  622.  
  623.                 mag.setInsertCardLight(true)
  624.                 finalBreakP = false
  625.                 while true do
  626.                     event, arg1, arg2, arg3 = os.pullEventRaw()
  627.                     if event == "mouse_click" and arg3 == 14 and arg2 >= 34 and arg2 <= 42 then -- arg2 = x | arg3 = y
  628.                         mag.setInsertCardLight(false)
  629.                         clear()
  630.                         term.setCursorPos(1, 1)
  631.                         break
  632.                     elseif event == "mag_swipe" then
  633.                         mag.setInsertCardLight(false)
  634.                         sfondo(colors.lightBlue)
  635.                         clear()
  636.                         tabel = textutils.unserialize(arg1)
  637.                         if tabel == "" or tabel == nil then
  638.                             clear()
  639.                             titolo("Prelievo denaro da nPay")
  640.  
  641.                             drawCard()
  642.  
  643.                             sfondo(colors.lightBlue)
  644.                             term.setCursorPos(36, 10)
  645.                             colore(colors.red)
  646.                             term.write("ERRORE!")
  647.                             term.setCursorPos(30, 12)
  648.                             colore(colors.black)
  649.                             term.write("Carta smagnetizzata!")
  650.                             os.sleep(3)
  651.                             break
  652.                         elseif tabel.t == "cc" then
  653.                             clear()
  654.                             titolo("Caricamento denaro da nPay")
  655.  
  656.                             drawCard()
  657.  
  658.                             sfondo(colors.lightBlue)
  659.                             term.setCursorPos(36, 10)
  660.                             colore(colors.red)
  661.                             term.write("ERRORE!")
  662.                             term.setCursorPos(31, 12)
  663.                             colore(colors.black)
  664.                             term.write("Carta NON SICURA!")
  665.                             term.setCursorPos(31, 13)
  666.                             term.write("Convertire la carta")
  667.                             term.setCursorPos(31, 14)
  668.                             term.write("presso gli sportelli")
  669.                             term.setCursorPos(31, 15)
  670.                             term.write("in banca")
  671.                             os.sleep(3)
  672.                             break
  673.  
  674.                         elseif tabel.t ~= "cd" or tabel.e ~= "BN" then
  675.                             clear()
  676.                             titolo("Prelievo denaro da nPay")
  677.  
  678.                             drawCard()
  679.  
  680.                             sfondo(colors.lightBlue)
  681.                             term.setCursorPos(36, 10)
  682.                             colore(colors.red)
  683.                             term.write("ERRORE!")
  684.                             term.setCursorPos(31, 12)
  685.                             colore(colors.black)
  686.                             term.write("Carta non valida!")
  687.                             os.sleep(3)
  688.                             break
  689.                         else
  690.                             while true do
  691.                                 tab1 = http.get(
  692.                                            "http://172.16.20.220/luanet/servlets/nebraskapay.php?utente=" .. utente ..
  693.                                                "&auth=" .. password .. "&richiesta=accredito&valore=0").readAll()
  694.                                 tab3 = textutils.unserialize(tab1)
  695.                                 clear()
  696.                                 titolo("Prelievo denaro da nPay")
  697.                                 colore(colors.gray)
  698.                                 print("\n\nDisponibilità su conto:  " .. saldo .. " IC")
  699.                                 colore(colors.black)
  700.                                 term.setCursorPos(1, 5)
  701.                                 term.write("Importo da ritirare: ")
  702.                                 colore(colors.white)
  703.                                 credito = tonumber(tabel.v)
  704.                                 credit = read()
  705.                                 if tonumber(credit) == "" or tonumber(credit) == nil or tonumber(credit) <= 0 then
  706.                                     colore(colors.red)
  707.                                     term.setCursorPos(22, 5)
  708.                                     term.write("Importo errato!                    ")
  709.                                     colore(colors.black)
  710.                                     sleep(1.5)
  711.                                     clear()
  712.                                 else
  713.                                     tab = http.get("http://172.16.20.220/luanet/servlets/nebraskapay.php?utente=" ..
  714.                                                        utente .. "&auth=" .. password .. "&richiesta=addebito&valore=" ..
  715.                                                        credit).readAll()
  716.                                     tabella = textutils.unserialize(tab)
  717.                                     if tabella.stato == "DI" then
  718.                                         colore(colors.red)
  719.                                         term.setCursorPos(22, 5)
  720.                                         term.write("Credito insufficente.")
  721.                                         colore(colors.black)
  722.                                         sleep(1.5)
  723.                                         clear()
  724.                                     else
  725.                                         clear()
  726.                                         titolo("Prelievo denaro da nPay")
  727.  
  728.                                         sibRaw = http.get(
  729.                                                      "http://luanet.rgbcraft.com/servlets/carte_debito.php?richiesta=accredito&valore=" ..
  730.                                                          credit .. "&uuid=" .. tabel.v).readAll()
  731.                                         sib = textutils.unserialize(sibRaw)
  732.  
  733.                                         if type(sib) ~= "table" then
  734.                                             print("\n\n\nImpossibile comunicare con il server interbancario")
  735.                                             sleep(5)
  736.                                             os.reboot()
  737.                                         end
  738.                                         if sib.stato ~= "OK" then
  739.                                             print("\n\n\nLa carta non risulta nel sistema interbancario, potrebbe essere stata disabilitata per uso fraudolento")
  740.                                             sleep(5)
  741.                                             os.reboot()
  742.                                         end
  743.        
  744.  
  745.                                         if sib.stato == "OK" then
  746.  
  747.                                             clear()
  748.                                             titolo("Prelievo denaro da nPay")
  749.  
  750.                                             colore(colors.lime)
  751.                                             term.setCursorPos(1, 3)
  752.                                             print("Operazione completata!")
  753.                                             colore(colors.black)
  754.                                             term.setCursorPos(1, 5)
  755.                                             print("Denaro prelevato:  " .. credit .. " IC")
  756.                                             term.setCursorPos(1, 7)
  757.                                             print("Saldo sul conto:   " .. tabella.credito .. " IC")
  758.                                             print("Saldo sulla carta: " .. sib.credito .. " IC")
  759.                                             sfondo(colors.white)
  760.                                             term.setCursorPos(1, 11)
  761.                                             term.write(" Torna alla pagina principale ")
  762.                                             sfondo(colors.lightBlue)
  763.  
  764.                                             antiTonto2 = os.startTimer(15)
  765.                                             while true do
  766.                                                 local event, arg1, arg2, arg3 = os.pullEventRaw()
  767.                                                 if event == "mouse_click" and arg3 == 11 and arg2 <= 30 or event ==
  768.                                                     "timer" and arg1 == antiTonto2 then -- arg2 = x | arg3 = y
  769.                                                     finalBreakP = true
  770.                                                     break
  771.                                                 end
  772.                                             end
  773.                                             break
  774.                                         end
  775.                                     end
  776.                                 end
  777.                                 if finalBreakP then
  778.                                     break
  779.                                 end
  780.                             end
  781.                         end
  782.                     end
  783.                 end
  784.             elseif event == "mouse_click" and y == 11 and x <= 24 then -- Pulsante trasferisci denaro
  785.                 -- Trasferisci denaro
  786.                 -- inizio pagina
  787.                 clear()
  788.                 titolo("Trasferimento di denaro")
  789.                 term.setCursorPos(1, 3)
  790.                 term.write("Inserire il nome utente del beneficiario.")
  791.                 colore(colors.gray)
  792.                 print(
  793.                     "\n\nPremere Enter per confermare i dati inseriti.\nSe i dati sono corretti, il campo diventerà verde.\nSe sono errati, il programma chiederà di reinserirli nuovamente.")
  794.  
  795.                 -- Mostra saldo
  796.                 term.setCursorPos(1, 10)
  797.                 colore(colors.gray)
  798.                 print("Saldo disponibile: " .. saldo .. " IC")
  799.                 colore(colors.black)
  800.  
  801.                 -- Verifica Beneficiario
  802.                 term.setCursorPos(1, 12)
  803.                 term.write("Beneficiario:")
  804.                 term.setCursorPos(15, 12)
  805.                 colore(colors.white)
  806.                 destAccettato = false
  807.                 conteggioErrori = 0
  808.                 while destAccettato == false do
  809.                     beneficiario = read()
  810.                     checkuser = http.get(
  811.                                     "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=no&richiesta=verifica&utente=" ..
  812.                                         beneficiario).readAll()
  813.                     tabcheckuser = textutils.unserialize(checkuser)
  814.                     if tabcheckuser.stato == "OK" and beneficiario ~= utente then
  815.                         term.setCursorPos(15, 12)
  816.                         colore(colors.lime)
  817.                         term.write(beneficiario)
  818.                         colore(colors.white)
  819.                         destAccettato = true
  820.                     else
  821.                         conteggioErrori = conteggioErrori + 1
  822.                         term.setCursorPos(15, 12)
  823.                         colore(colors.red)
  824.                         if beneficiario == utente then
  825.                             term.write("Non puoi inserire te stesso.")
  826.                         else
  827.                             term.write("Utente inesistente!         ")
  828.                         end
  829.                         sleep(2)
  830.                         term.setCursorPos(15, 12)
  831.                         colore(colors.white)
  832.                         term.write("                                      ")
  833.                         term.setCursorPos(15, 12)
  834.                         if conteggioErrori > 2 then
  835.                             term.setCursorPos(15, 12)
  836.                             colore(colors.red)
  837.                             term.write("Tre tentativi di immissione errati.")
  838.                             sleep(2)
  839.                             term.setCursorPos(15, 12)
  840.                             colore(colors.white)
  841.                             term.write("                                   ")
  842.                             term.setCursorPos(15, 12)
  843.                             clear()
  844.                             os.reboot()
  845.                         end
  846.                     end
  847.                 end
  848.  
  849.                 colore(colors.black)
  850.                 -- Verifica valore dell'invio
  851.                 term.setCursorPos(1, 14)
  852.                 term.write("Importo:")
  853.                 term.setCursorPos(15, 14)
  854.                 colore(colors.white)
  855.                 importoAccettato = false
  856.                 conteggioErrori = 0
  857.                 while importoAccettato == false do
  858.                     importo = tonumber(read())
  859.                     if importo == "" or importo == nil or importo <= 0 then
  860.                         conteggioErrori = conteggioErrori + 1
  861.                         term.setCursorPos(15, 14)
  862.                         colore(colors.red)
  863.                         term.write("Importo errato!                    ")
  864.                         sleep(2)
  865.                         term.setCursorPos(15, 14)
  866.                         colore(colors.white)
  867.                         term.write("                                   ")
  868.                         term.setCursorPos(15, 14)
  869.                     elseif importo <= saldo and importo > 0 then
  870.                         term.setCursorPos(15, 14)
  871.                         colore(colors.lime)
  872.                         term.write(importo .. " IC")
  873.                         colore(colors.white)
  874.                         importoAccettato = true
  875.                     else
  876.                         conteggioErrori = conteggioErrori + 1
  877.                         term.setCursorPos(15, 14)
  878.                         colore(colors.red)
  879.                         term.write("Credito insufficiente!          ")
  880.                         sleep(2)
  881.                         term.setCursorPos(15, 14)
  882.                         colore(colors.white)
  883.                         term.write("                                   ")
  884.                         term.setCursorPos(15, 14)
  885.                         if conteggioErrori > 2 then
  886.                             term.setCursorPos(15, 14)
  887.                             colore(colors.red)
  888.                             term.write("Tre tentativi di immissione errati.")
  889.                             sleep(2)
  890.                             term.setCursorPos(15, 14)
  891.                             colore(colors.white)
  892.                             term.write("                                   ")
  893.                             term.setCursorPos(15, 14)
  894.                             clear()
  895.                             os.reboot()
  896.                         end
  897.                     end
  898.                 end
  899.  
  900.                 sleep(0.5)
  901.                 clear()
  902.                 titolo("Riepilogo del trasferimento")
  903.  
  904.                 text = "Vuoi inviare " .. importo .. " IC a " .. beneficiario .. "?"
  905.                 term.setCursorPos((maxw - #text) / 2, 6)
  906.                 term.write("Vuoi inviare ")
  907.                 colore(colors.white)
  908.                 term.write(tostring(importo) .. " IC ")
  909.                 colore(colors.black)
  910.                 term.write("a ")
  911.                 colore(colors.white)
  912.                 term.write(beneficiario)
  913.                 colore(colors.black)
  914.                 term.write("?")
  915.  
  916.                 drawFilledBox(7, 11, 23, 13, colors.white)
  917.                 drawFilledBox(29, 11, 45, 13, colors.white)
  918.  
  919.                 term.setCursorPos(8, 12)
  920.                 colore(colors.lime)
  921.                 term.write("Invia il denaro")
  922.  
  923.                 term.setCursorPos(34, 12)
  924.                 colore(colors.red)
  925.                 term.write("Annulla")
  926.  
  927.                 inviare = false
  928.                 while true do
  929.                     event, key, x, y = os.pullEvent()
  930.                     if event == "mouse_click" and x >= 7 and x <= 23 and y >= 11 and y <= 13 then
  931.                         inviaDenaro = http.get(
  932.                                           "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" .. password ..
  933.                                               "&utente=" .. utente .. "&richiesta=trasferimento&valore=" .. importo ..
  934.                                               "&beneficiario=" .. beneficiario).readAll()
  935.                         risultatoInvio = textutils.unserialize(inviaDenaro)
  936.                         if risultatoInvio.stato == "OK" then
  937.                             text = "Invio del denaro riuscito."
  938.                             text2 = "Nuovo saldo: " .. risultatoInvio.credito .. " IC"
  939.                             sfondo(colors.lightBlue)
  940.                             colore(colors.lime)
  941.                             term.setCursorPos((maxw - #text) / 2, 16)
  942.                             term.write(text)
  943.                             colore(colors.black)
  944.                             term.setCursorPos((maxw - #text2) / 2, 18)
  945.                             term.write(text2)
  946.                             sleep(2)
  947.                             clear()
  948.                             break
  949.                         else
  950.                             text = "Errore durante l'invio del denaro."
  951.                             text2 = risultatoInvio.errore
  952.                             sfondo(colors.lightBlue)
  953.                             colore(colors.red)
  954.                             term.setCursorPos((maxw - #text) / 2, 16)
  955.                             term.write(text)
  956.                             colore(colors.black)
  957.                             term.setCursorPos((maxw - #text2) / 2, 18)
  958.                             term.write(text2)
  959.                             sleep(2)
  960.                             clear()
  961.                             break
  962.                         end
  963.                     elseif event == "mouse_click" and x >= 29 and x <= 45 and y >= 11 and y <= 13 then
  964.                         sfondo(colors.lightBlue)
  965.                         colore(colors.red)
  966.                         text = "Operazione annullata."
  967.                         term.setCursorPos((maxw - #text) / 2, 16)
  968.                         term.write(text)
  969.                         sleep(1.5)
  970.                         clear()
  971.                         break
  972.                     end
  973.                 end
  974.  
  975.             elseif event == "mouse_click" and y == 13 and x <= 24 then -- Pulsante estratto conto
  976.                 -- Estratto Conto (inizio pagina)
  977.                 clear()
  978.                 titolo("Estratto conto")
  979.  
  980.                 estratto = http.get("http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" .. password ..
  981.                                         "&utente=" .. utente .. "&richiesta=estratto").readAll()
  982.                 ec = textutils.unserialize(estratto)
  983.                 term.setCursorPos(1, 3)
  984.                 print("Entrate:")
  985.                 colore(colors.lime)
  986.                 print(ec.entrata1)
  987.                 print(ec.entrata2)
  988.                 print(ec.entrata3)
  989.                 print(ec.entrata4)
  990.                 colore(colors.black)
  991.                 print("\nUscite:")
  992.                 colore(colors.red)
  993.                 print(ec.uscita1)
  994.                 print(ec.uscita2)
  995.                 print(ec.uscita3)
  996.                 print(ec.uscita4)
  997.                 term.setCursorPos(1, 18)
  998.                 sfondo(colors.white)
  999.                 colore(colors.black)
  1000.                 term.write(" Torna al menù principale ")
  1001.                 while true do
  1002.                     event, key, x, y = os.pullEventRaw()
  1003.                     if event == "mouse_click" and x <= 26 and y == 18 then
  1004.                         break
  1005.                     end
  1006.                 end
  1007.  
  1008.             elseif event == "mouse_click" and y == 15 and x <= 24 then -- Pulsante disconnetti da nPay
  1009.                 disconnetti()
  1010.  
  1011.             elseif event == "timer" and key == antitonto then -- Butta fuori l'utente se non fa niente
  1012.                 disconnetti()
  1013.  
  1014.             elseif event == "mouse_click" and x == maxw and y == maxh then -- Auto aggiornamento su magic corner (pannello utente)
  1015.                 update()
  1016.             end
  1017.         end
  1018.  
  1019.     elseif event == "mouse_click" and x == maxw and y == maxh then -- Auto aggiornamento su magic corner (schermata principale)
  1020.         update()
  1021.     end
  1022. end
  1023.  
Advertisement
Add Comment
Please, Sign In to add comment