Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Bancomat versamento
- -- Variabili config
- local uri = "http://luanet.rgbcraft.com/servlets/bancomat/"
- local maxw, maxh = term.getSize()
- ben = peripheral.wrap("back")
- function drawCard()
- drawFilledBox(6, 7, 24, 7, colors.blue)
- drawFilledBox(6, 15, 24, 15, colors.blue)
- drawFilledBox(5, 8, 25, 14, colors.blue)
- drawFilledBox(7, 9, 23, 9, colors.lightGray)
- drawFilledBox(7, 12, 23, 13, colors.black)
- end
- mag = peripheral.wrap("right")
- -- funzioni helper di base
- function tablelength(T)
- local count = 0
- for _ in pairs(T) do
- count = count + 1
- end
- return count
- end
- function update()
- term.setCursorPos(1, 21)
- shell.run("pastebin get mfTb10RP startup2")
- if fs.exists("startup2") then
- shell.run("rm startup")
- shell.run("mv startup2 startup")
- end
- os.reboot()
- end
- function clear()
- term.clear()
- term.setCursorPos(1, 1)
- end
- function clearRed()
- sfondo(colors.red)
- term.clear()
- term.setCursorPos(1, 1)
- end
- function colore(sfumatura)
- term.setTextColour(sfumatura)
- end
- function sfondo(sfumaturaSfondo)
- term.setBackgroundColour(sfumaturaSfondo)
- end
- function fineColore()
- term.setTextColour(colours.white)
- end
- function fineSfondo()
- term.setBackgroundColour(colours.black)
- end
- -- IMPLEMENTAZIONE DEL DRAWFILLEDBOX
- local function drawPixelInternal(xPos, yPos)
- term.setCursorPos(xPos, yPos)
- term.write(" ")
- end
- local tColourLookup = {}
- for n = 1, 16 do
- tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
- end
- function drawFilledBox(startX, startY, endX, endY, nColour)
- if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~= "number" or type(endY) ~= "number" or
- (nColour ~= nil and type(nColour) ~= "number") then
- error("Expected startX, startY, endX, endY, colour", 2)
- end
- startX = math.floor(startX)
- startY = math.floor(startY)
- endX = math.floor(endX)
- endY = math.floor(endY)
- if nColour then
- term.setBackgroundColor(nColour)
- end
- if startX == endX and startY == endY then
- drawPixelInternal(startX, startY)
- return
- end
- local minX = math.min(startX, endX)
- if minX == startX then
- minY = startY
- maxX = endX
- maxY = endY
- else
- minY = endY
- maxX = startX
- maxY = startY
- end
- for x = minX, maxX do
- for y = minY, maxY do
- drawPixelInternal(x, y)
- end
- end
- end
- function titolo(testo)
- drawFilledBox(1, 1, maxw, 1, colors.yellow)
- term.setCursorPos((maxw - #testo) / 2, 1)
- colore(colors.black)
- term.write(testo)
- sfondo(colors.lightBlue)
- end
- function errore(errore)
- sfondo(colors.red)
- colore(colors.white)
- term.clear()
- term.setCursorPos(1, 1)
- titolo("Errore irreversibile")
- term.setCursorPos(1, 3)
- sfondo(colors.red)
- colore(colors.white)
- print(errore)
- print("\n\n\nAttendere qualche secondo...")
- os.sleep(5)
- os.reboot()
- end
- -- verifica servizi online e recupero prezzario
- prezzario_raw = http.get(uri .. "/?richiesta=prezzario_lua").readAll()
- prezzario = textutils.unserialize(prezzario_raw)
- if type(prezzario) ~= "table" then
- errore("Impossibile comunicare con il server interbancario")
- end
- -- variabili quantità
- counted_items = {}
- id_items = {}
- -- enumerazione prezzario
- for k, v in pairs(prezzario) do
- id_items[ben.getItemIdentifierIDFor(v.id, v.meta)] = k
- end
- -- vuota il bancomat
- ben.getAvailableItems()
- i, j = os.pullEvent("available_items_return")
- for k, v in pairs(j) do
- counted_items[id_items[v[1]]] = v[2]
- ben.makeRequest(v[1], v[2])
- sleep(0.1)
- end
- -- resetta counted_items e controlla se è vuoto
- counted_items = {}
- ben.getAvailableItems()
- i, j = os.pullEvent("available_items_return")
- for k, v in pairs(j) do
- counted_items[id_items[v[1]]] = v[2]
- sleep(0.1)
- end
- if tablelength(counted_items) ~= 0 then
- sfondo(colors.red)
- colore(colors.white)
- term.clear()
- term.setCursorPos(1, 1)
- titolo("Errore irreversibile")
- term.setCursorPos(1, 3)
- sfondo(colors.red)
- colore(colors.white)
- print("Svuotamento non possibile, sportello fuori servizio")
- print("\n\n\nContattare il Banco di Nebraska")
- os.sleep(60)
- os.reboot()
- end
- sfondo(colors.lightBlue)
- clear()
- titolo("Banco di Nebraska - Versamento Denaro")
- sfondo(colors.lightBlue)
- print("\n\n")
- print(
- "Questo sportello accetta tutte le monete.\n\nE' possibile versare monete su una carta di debito oppure su un conto nPay")
- drawFilledBox(16, 11, 33, 13, colors.white)
- term.setCursorPos(17, 12)
- term.write("Versare su carta")
- -- Versamento su nPay
- drawFilledBox(16, 15, 33, 17, colors.white)
- term.setCursorPos(17, 16)
- term.write("Versare su nPay")
- while true do
- event, key, x, y = os.pullEvent("mouse_click")
- -- pulsante carta
- if event == "mouse_click" and x >= 16 and x <= 33 and y >= 11 and y <= 13 then
- sfondo(colors.lightBlue)
- clear()
- titolo("Versamento su carta di debito")
- colore(colors.black)
- drawCard()
- sfondo(colors.lightBlue)
- term.setCursorPos(30, 8)
- print("INSERIRE LA CARTA")
- term.setCursorPos(29, 10)
- print("NEL LETTORE A DESTRA")
- drawFilledBox(34, 14, 42, 14, colors.white)
- term.setCursorPos(35, 14)
- term.write("Annulla")
- mag.setInsertCardLight(true)
- finalBreakC = false
- while true do
- event, arg1, arg2, arg3 = os.pullEventRaw()
- if event == "mouse_click" and arg3 == 14 and arg2 >= 34 and arg2 <= 42 then -- arg2 = x | arg3 = y
- mag.setInsertCardLight(false)
- os.reboot()
- elseif event == "mag_swipe" then
- mag.setInsertCardLight(false)
- tabel = textutils.unserialize(arg1)
- if tabel == "" or tabel == nil then
- errore("Carta smagnetizzata")
- elseif tabel.t == "cc" then
- errore("Carta NON SICURA, convertire prima la carta allo sportello di conversione situato in:\n\nBanco di Nebraska - P.zza Affari 3, New Radeon")
- elseif tabel.t ~= "cd" or tabel.e ~= "BN" then
- errore("Carta non valida o corrotta")
- else
- modoPagamento = "carta"
- utente = "CARTA_" .. string.sub(tostring(tabel.v), -4)
- break
- end
- end
- end
- break
- -- pulsante NPay
- elseif event == "mouse_click" and x >= 16 and x <= 33 and y >= 15 and y <= 17 then
- sfondo(colours.lightBlue)
- term.clear()
- term.setCursorPos(1, 1)
- titolo("Accredita su Nebraska Pay")
- sfondo(colours.lightBlue)
- term.setCursorPos(1, 3)
- print("Inserire i propri dati.")
- colore(colors.gray)
- print(
- "Premere Enter per confermare i dati inseriti.\nSe i dati sono corretti, il campo diventerà verde.\nSe sono errati, il programma chiederà di reinserirli nuovamente.")
- -- nomeutente
- colore(colors.black)
- term.setCursorPos(1, 9)
- term.write("Nome utente:")
- term.setCursorPos(15, 9)
- fineColore()
- utenteAccettato = false
- conteggioErrori = 0
- while utenteAccettato == false do
- utente = read()
- utente = string.gsub(utente, "%s", "")
- checkuser = http.get(
- "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=no&richiesta=verifica&utente=" ..
- utente).readAll()
- tabcheckuser = textutils.unserialize(checkuser)
- if tabcheckuser.stato == "OK" then
- term.setCursorPos(15, 9)
- colore(colours.lime)
- term.write(utente)
- fineColore()
- utenteAccettato = true
- else
- term.setCursorPos(15, 9)
- colore(colours.red)
- term.write("Utente errato! ")
- sleep(2)
- term.setCursorPos(15, 9)
- fineColore()
- term.write(" ")
- term.setCursorPos(15, 9)
- conteggioErrori = conteggioErrori + 1
- if conteggioErrori > 2 then
- term.setCursorPos(15, 9)
- colore(colours.red)
- errore("Troppi tentativi di immissione errati ")
- end
- end
- end
- colore(colours.black)
- term.setCursorPos(1, 11)
- term.write("Password:")
- term.setCursorPos(15, 11)
- conteggioErrori = 0
- passAccettata = false
- while passAccettata == false do
- fineColore()
- password = read("#")
- colore(colours.black)
- checkuser = http.get("http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" .. password ..
- "&richiesta=addebito&valore=0&utente=" .. utente).readAll()
- risposta = textutils.unserialize(checkuser)
- if risposta.stato == "OK" then
- term.setCursorPos(15, 11)
- colore(colours.lime)
- term.write("############## ")
- fineColore()
- passAccettata = true
- else
- term.setCursorPos(15, 11)
- colore(colours.red)
- term.write("Password errata! ")
- conteggioErrori = conteggioErrori + 1
- sleep(2)
- term.setCursorPos(15, 11)
- term.write(" ")
- term.setCursorPos(15, 11)
- if conteggioErrori > 2 then
- term.setCursorPos(15, 11)
- colore(colours.red)
- errore("Troppi tentativi di immissione errati")
- end
- end
- end
- credito = tonumber(risposta.saldo)
- modoPagamento = "npay"
- break
- elseif event == "mouse_click" and x == maxw and y == maxh then -- Auto aggiornamento su magic corner (schermata principale)
- update()
- end
- end
- sfondo(colors.lightBlue)
- clear()
- while true do
- if modoPagamento == "carta" then
- sibRaw = http.get("http://luanet.rgbcraft.com/servlets/carte_debito.php?richiesta=verifica&uuid=" ..
- tabel.v).readAll()
- sib = textutils.unserialize(sibRaw)
- if type(sib) ~= "table" then
- errore("Impossibile comunicare con il server interbancario")
- end
- if sib.stato ~= "OK" then
- errore("La carta non risulta nel sistema interbancario, potrebbe essere stata disabilitata per uso fraudolento")
- end
- saldo = sib.saldo
- else
- saldo = risposta.saldo
- end
- titolo("Sistema versamento")
- term.setCursorPos(1, 3)
- term.write("Benvenuto, ")
- colore(colors.gray)
- term.write(utente)
- colore(colors.black)
- term.write("! Saldo: ")
- colore(colors.gray)
- term.write(saldo)
- colore(colors.black)
- term.write(" IC")
- print("\n\nOperazioni disponibili:\n")
- sfondo(colors.white)
- print(" Versa denaro contante \n")
- colore(colors.red)
- print(" Annulla operazione \n")
- colore(colors.black)
- antitonto = os.startTimer(60)
- event, key, x, y = os.pullEventRaw()
- if event == "mouse_click" and y == 7 and x <= 24 then
- sfondo(colors.lightBlue)
- clear()
- titolo("Operazione di versamento - Passo 1")
- redstone.setOutput("left", true)
- print(
- "\n\nInserire gli oggetti nello sportello a destra oppure collocare il Deep Storage di fronte al cubo rosso.")
- print("")
- print("Eventuali oggetti non accettati non verranno ritirati dal meccanismo.\n")
- sfondo(colors.red)
- print("ATTENZIONE: NON RIAVVIARE IL COMPUTER O SI PERDERA' IL VERSAMENTO")
- sfondo(colors.lightBlue)
- print("")
- print("Quando si è pronti per continuare, premere un tasto qualsiasi.")
- os.pullEvent("key")
- clear()
- redstone.setOutput("left", false)
- titolo("Operazione di versamento - Passo 2")
- print("\n\nConteggio contanti inseriti in corso...")
- term.setCursorPos(3, 6)
- term.write("*---")
- sleep(0.5)
- term.setCursorPos(3, 6)
- term.write("-*--")
- sleep(0.5)
- term.setCursorPos(3, 6)
- term.write("--*-")
- sleep(0.5)
- term.setCursorPos(3, 6)
- term.write("---*")
- sleep(0.5)
- term.setCursorPos(3, 6)
- term.write("--*-")
- sleep(0.5)
- term.setCursorPos(3, 6)
- term.write("-*--")
- sleep(0.5)
- term.setCursorPos(3, 6)
- term.write("*---")
- sleep(0.5)
- ben = peripheral.wrap("back")
- ben.getAvailableItems()
- i, j = os.pullEvent("available_items_return")
- clear()
- -- vuota il bancomat
- ben.getAvailableItems()
- i, j = os.pullEvent("available_items_return")
- for k, v in pairs(j) do
- counted_items[id_items[v[1]]] = v[2]
- ben.makeRequest(v[1], v[2])
- sleep(0.1)
- end
- if tablelength(counted_items) == 0 then
- errore("Nessun contante risulta essere stato introdotto")
- end
- titolo("Operazione di versamento - Passo 3")
- print(
- "\n\nI contanti sono stati conteggiati correttamente.\nComunicazione con i servizi interbancari in corso...")
- print("")
- items_uri = ""
- for k, v in pairs(counted_items) do
- items_uri = items_uri .. "&" .. k .. "=" .. v
- end
- if modoPagamento == "carta" then
- inviaDenaro = http.get(uri .. "/?richiesta=versamento_carta&uuid=" .. tabel.v ..
- items_uri).readAll()
- else
- inviaDenaro = http.get(uri .. "/?richiesta=versamento_npay&auth=" .. password .. "&utente=" .. utente ..
- items_uri).readAll()
- end
- risultatoInvio = textutils.unserialize(inviaDenaro)
- if risultatoInvio.stato == "OK" then
- colore(colors.white)
- else
- clear()
- errore("Errore durante il pagamento")
- sleep(5)
- os.reboot()
- end
- sleep(1)
- print("Comunicazione con i servizi fiscali in corso...")
- sleep(1)
- clear()
- titolo("Operazione di versamento conclusa")
- print("\n\nDenaro versato: " .. math.abs(tonumber(risultatoInvio.credito) - tonumber(risultatoInvio.saldo)) ..
- " IC")
- print("")
- print("")
- print("Grazie!")
- print("")
- print("Tra poco sarà possibile eseguire una nuova operazione.")
- sleep(10)
- term.setTextColor(colors.lightBlue)
- update()
- elseif event == "mouse_click" and y == 9 and x <= 24 then -- Pulsante disconnetti da nPay
- clear()
- break
- elseif event == "timer" and key == antitonto then -- Butta fuori l'utente se non fa niente
- disconnetti()
- break
- end
- end
- sfondo(colors.lightBlue)
- clear()
- print("Attendere")
- term.setTextColor(colors.lightBlue)
- sfondo(colors.lightBlue)
- update()
- os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment