Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- lp=peripheral.wrap("back")
- -- makeRequest(double:id dell'item nel network LP, double:quantità item richiesta) --
- -- x.makeRequest(-25188103, n1) -- request del carbone, con n1 variabile scelta dall'utente
- -- x.makeRequest(2097825633, n2) -- request del biofuel
- -- x.makeRequest(-641322352, n3) -- request del creosoto
- local maxw, maxh = term.getSize()
- --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 clear()
- sfondo(colors.lightBlue)
- term.clear()
- term.setCursorPos(1, 1)
- end
- function colore(sfumatura)
- term.setTextColour(sfumatura)
- end
- function sfondo(sfumaturaSfondo)
- term.setBackgroundColour(sfumaturaSfondo)
- 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 disconnetti()
- clear()
- text = "ARRIVEDERCI!"
- colore(colors.white)
- term.setCursorPos((maxw - #text) / 2, math.floor(maxh / 2))
- term.write(text)
- colore(colors.black)
- text2 = "Tra poco saråA0 possibile eseguire"
- text3 = "una nuova operazione..."
- term.setCursorPos((maxw - #text2) / 2, math.floor(maxh / 2) + 2)
- print(text2)
- term.setCursorPos((maxw - #text3) / 2, math.floor(maxh / 2) + 3)
- print(text3)
- os.sleep(0.5)
- end
- 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
- sfondo(colors.lightBlue)
- clear()
- colore(colors.black)
- print(" _ _ ______ _ _ ______ _ ")
- print(" | \\ | | | ____| | | | ____| | ")
- print(" | \\| |______| |__ | | | | |__ | | ")
- print(" | . |______| __| | | | | __| | | ")
- print(" | |\\ | | | | |__| | |____| |____ ")
- print(" |_| \\_| |_| \\____/|______|______| ")
- -- Bottoni login/registrati
- drawFilledBox(14, 10, 38, 12, colors.white)
- term.setCursorPos(23, 11)
- colore(colors.black)
- term.write(" Accesso cliente")
- drawFilledBox(14, 15, 38, 17, colors.white)
- term.setCursorPos(21, 16)
- colore(colors.black)
- term.write("Accesso operatore")
- while true do
- event, key, x, y = os.pullEvent("mouse_click")
- if event == "mouse_click" and x >= 14 and x <= 38 and y >= 15 and y <= 17 then
- -- Registrazione nuovo utente
- clear()
- titolo("Autenticazione operatore N-Fuel")
- term.setCursorPos(1, 3)
- print("Inserisci il codice OP")
- term.setCursorPos(1, 5)
- colore(colors.gray)
- print("Premi ENTER per confermare il codice.\nSe i dati sono corretti, il campo diventeråA0 verde.\nSe sono errati, il programma chiederåA0 di reinserirli nuovamente.")
- --Codice superuser
- colore(colors.black)
- term.setCursorPos(1, 12)
- term.write("Password:")
- term.setCursorPos(11, 12)
- colore(colors.white)
- passAccettata = false
- conteggioErrori = 0
- while passAccettata == false do
- password1 = read("#")
- colore(colors.black)
- term.setCursorPos(1, 13)
- term.write("Verifica:")
- term.setCursorPos(11, 13)
- colore(colors.white)
- if password1 == "96643" then
- term.setCursorPos(11, 12)
- colore(colors.lime)
- term.write("###############")
- term.setCursorPos(11, 13)
- term.write("###############")
- colore(colors.white)
- passAccettata = true
- sfondo(colors.lightBlue)
- clear()
- drawFilledBox(14, 10, 38, 12, colors.white)
- term.setCursorPos(23, 11)
- colore(colors.black)
- term.write("Carbon coke")
- drawFilledBox(14, 15, 38, 17, colors.white)
- term.setCursorPos(21, 16)
- colore(colors.black)
- term.write("Carburanti liquidi")
- while true do
- event, key, x, y = os.pullEvent("mouse_click")
- if event == "mouse_click" and x >= 14 and x <= 38 and y >= 10 and y <= 12 then
- clear()
- titolo("Ritiro Coke")
- term.setCursorPos(1, 3)
- print("Inserisci la quantità di coke che si intende prelevare")
- term.setCursorPos(1, 5)
- colore(colors.gray)
- QTCoke = 0
- QTCoke = read("#")
- colore(colors.black)
- term.setCursorPos(1, 13)
- term.setCursorPos(11, 13)
- colore(colors.white)
- term.write("Distribuzione risorse in corso...")
- qtycoke = tonumber(QTCoke)
- while qtycoke > 0 do
- lp.makeRequest(lp.getItemIdentifierIDFor(7757, 0), 1)
- qtycoke = qtycoke - 1
- end
- sleep(10)
- clear()
- os.reboot()
- elseif event == "mouse_click" and x >= 14 and x <= 38 and y >= 15 and y <= 17 then
- sfondo(colors.lightBlue)
- clear()
- drawFilledBox(14, 10, 38, 12, colors.white)
- term.setCursorPos(23, 11)
- colore(colors.black)
- term.write("Creosoto")
- drawFilledBox(14, 15, 38, 17, colors.white)
- term.setCursorPos(21, 16)
- colore(colors.black)
- term.write("Biofuel")
- else
- sleep()
- end
- while true do
- event, key, x, y = os.pullEvent("mouse_click")
- if event == "mouse_click" and x >= 14 and x <= 38 and y >= 10 and y <= 12 then
- clear()
- titolo("Creosoto")
- term.setCursorPos(1, 3)
- print("Inserisci la quantità di Creosoto (in bucket) che si intende prelevare")
- term.setCursorPos(1, 5)
- colore(colors.gray)
- QTCR = 0
- QTCR = read("#")
- colore(colors.black)
- term.setCursorPos(1, 13)
- term.setCursorPos(11, 13)
- colore(colors.white)
- term.write("Distribuzione risorse in corso...")
- qtycr = tonumber(QTBF)
- while qtycr > 0 do
- lp.makeRequest(lp.getItemIdentifierIDFor(7772, 0), 1)
- qtycr = qtycr - 1
- end
- sleep(10)
- clear()
- os.reboot()
- else
- sleep()
- end
- end
- while true do
- event, key, x, y = os.pullEvent("mouse_click")
- if event == "mouse_click" and x >= 14 and x <= 15 and y >= 10 and y <= 17 then
- clear()
- titolo("Creosoto")
- term.setCursorPos(1, 3)
- print("Inserisci la quantità di Biofuel (in bucket) che si intende prelevare")
- term.setCursorPos(1, 5)
- colore(colors.gray)
- QTBF = 0
- QTBF = read("#")
- colore(colors.black)
- term.setCursorPos(1, 13)
- term.setCursorPos(11, 13)
- colore(colors.white)
- term.write("Distribuzione risorse in corso...")
- qtybf = tonumber(QTBF)
- while qtybf > 0 do
- lp.makeRequest(lp.getItemIdentifierIDFor(30227, 0), 1)
- qtybf = qtybf - 1
- end
- sleep(10)
- clear()
- os.reboot()
- else
- sleep()
- end
- end
- end
- else
- colore(colors.red)
- term.setCursorPos(11, 12)
- term.write("Codce Errato! ")
- term.setCursorPos(1, 13)
- colore(colors.white)
- term.write(" ")
- sleep(1.5)
- term.setCursorPos(11, 12)
- term.write(" ")
- term.setCursorPos(11, 12)
- conteggioErrori = conteggioErrori + 1
- if conteggioErrori > 2 then
- term.setCursorPos(14, 12)
- colore(colors.red)
- term.write("Tre tentativi di immissione errati.")
- sleep(1.5)
- term.setCursorPos(14, 12)
- colore(colors.white)
- term.write(" ")
- term.setCursorPos(14, 12)
- clear()
- os.reboot()
- end
- end
- end
- elseif event == "mouse_click" and x >= 14 and x <= 38 and y >= 10 and y <= 12 then
- clear()
- titolo("Accedi a nPay")
- term.setCursorPos(1, 3)
- colore(colors.black)
- print("Inserire i propri dati.")
- colore(colors.gray)
- print("\nPremere Enter per confermare i dati inseriti.\nSe i dati sono corretti, il campo diventeråA0 verde.\nSe sono errati, il programma chiederåA0 di reinserirli nuovamente.")
- --nomeutente
- term.setCursorPos(1, 10)
- colore(colors.black)
- term.write("Nome utente:")
- term.setCursorPos(15, 10)
- colore(colors.white)
- utenteAccettato = false
- conteggioErrori = 0
- while utenteAccettato == false do
- utente = read()
- 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, 10)
- colore(colors.lime)
- term.write(utente)
- colore(colors.white)
- utenteAccettato = true
- else
- term.setCursorPos(15, 10)
- colore(colors.red)
- term.write("Utente errato! ")
- sleep(2)
- term.setCursorPos(15, 10)
- colore(colors.white)
- term.write(" ")
- term.setCursorPos(15, 10)
- conteggioErrori = conteggioErrori + 1
- if conteggioErrori > 2 then
- term.setCursorPos(15, 10)
- colore(colors.red)
- term.write("Tre tentativi di immissione errati.")
- sleep(2)
- term.setCursorPos(15, 10)
- colore(colors.white)
- term.write(" ")
- term.setCursorPos(15, 10)
- clear()
- os.reboot()
- end
- end
- end
- --password
- colore(colors.black)
- term.setCursorPos(1,12)
- term.write("Password:")
- term.setCursorPos(15, 12)
- conteggioErrori = 0
- passAccettata = false
- while passAccettata == false do
- colore(colors.white)
- password = read("#")
- colore(colors.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, 12)
- colore(colors.lime)
- term.write("############## ")
- colore(colors.white)
- passAccettata = true
- else
- term.setCursorPos(15, 12)
- colore(colors.red)
- term.write("Password errata! ")
- conteggioErrori = conteggioErrori + 1
- sleep(2)
- term.setCursorPos(15, 12)
- term.write(" ")
- term.setCursorPos(15, 12)
- if conteggioErrori > 2 then
- term.setCursorPos(15, 12)
- colore(colors.red)
- term.write("Tre tentativi di immissione errati.")
- sleep(2)
- term.setCursorPos(15, 12)
- term.write(" ")
- term.setCursorPos(15, 12)
- clear()
- os.reboot()
- end
- end
- end
- conteggioErrori = 0
- -- Pagina in cui scegli le operazioni da fare
- while true do
- --Ricontrolla il saldo per gestire l'aggiornamento di piåB9 operazioni
- 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)
- saldo = tonumber(risposta.saldo)
- --Disegna la finestra del pannello utente
- clear()
- titolo("Pannello utente nPay")
- term.setCursorPos(1, 3)
- term.write("Benvenuto, ")
- colore(colors.white)
- term.write(utente)
- colore(colors.black)
- term.write("! Saldo: ")
- colore(colors.white)
- term.write(saldo)
- colore(colors.black)
- term.write(" IC")
- print("\n\nOperazioni disponibili:\n")
- sfondo(colors.white)
- print(" Compra Coke \n") --deprecato carica denaro
- print(" Compra Creosoto \n") --deprecato prelieva denaro
- print(" Compra Biofuel \n") --deprecato trasferisci denaro
- colore(colors.red) -- estratto conto rimosso
- print(" Disconnettiti da nPay \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 --Pulsante coke
- clear()
- titolo("Compra Coke")
- drawCard()
- sfondo(colors.lightBlue)
- colore(colors.black)
- term.setCursorPos(30, 8)
- lp.makeRequest(-25188103, 1)
- elseif event == "mouse_click" and y == 9 and x <= 24 then --Pulsante creosoto
- clear()
- titolo("Compra Creosoto")
- drawCard()
- sfondo(colors.lightBlue)
- colore(colors.black)
- term.setCursorPos(30, 8)
- elseif event == "mouse_click" and y == 11 and x <= 24 then --Pulsante biofuel
- --inizio pagina
- clear()
- titolo("Trasferimento di denaro")
- term.setCursorPos(1, 3)
- term.write("Inserire il nome utente del beneficiario.")
- colore(colors.gray)
- print("\n\nPremere Enter per confermare i dati inseriti.\nSe i dati sono corretti, il campo diventeråA0 verde.\nSe sono errati, il programma chiederåA0 di reinserirli nuovamente.")
- --Mostra saldo
- term.setCursorPos(1, 10)
- colore(colors.gray)
- print("Saldo disponibile: " .. saldo .. " IC")
- colore(colors.black)
- --Verifica Beneficiario
- term.setCursorPos(1, 12)
- term.write("Beneficiario:")
- term.setCursorPos(15, 12)
- colore(colors.white)
- destAccettato = false
- conteggioErrori = 0
- while destAccettato == false do
- beneficiario = read()
- checkuser = http.get("http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=no&richiesta=verifica&utente=" .. beneficiario).readAll()
- tabcheckuser = textutils.unserialize(checkuser)
- if tabcheckuser.stato == "OK" and beneficiario ~= utente then
- term.setCursorPos(15, 12)
- colore(colors.lime)
- term.write(beneficiario)
- colore(colors.white)
- destAccettato = true
- else
- conteggioErrori = conteggioErrori + 1
- term.setCursorPos(15, 12)
- colore(colors.red)
- if beneficiario == utente then
- term.write("Non puoi inserire te stesso.")
- else
- term.write("Utente inesistente! ")
- end
- sleep(2)
- term.setCursorPos(15, 12)
- colore(colors.white)
- term.write(" ")
- term.setCursorPos(15, 12)
- if conteggioErrori > 2 then
- term.setCursorPos(15, 12)
- colore(colors.red)
- term.write("Tre tentativi di immissione errati.")
- sleep(2)
- term.setCursorPos(15, 12)
- colore(colors.white)
- term.write(" ")
- term.setCursorPos(15, 12)
- clear()
- os.reboot()
- end
- end
- end
- colore(colors.black)
- --Verifica valore dell'invio
- term.setCursorPos(1, 14)
- term.write("Importo:")
- term.setCursorPos(15, 14)
- colore(colors.white)
- importoAccettato = false
- conteggioErrori = 0
- while importoAccettato == false do
- importo = tonumber(read())
- if importo == "" or importo == nil or importo <= 0 then
- conteggioErrori = conteggioErrori + 1
- term.setCursorPos(15, 14)
- colore(colors.red)
- term.write("Importo errato! ")
- sleep(2)
- term.setCursorPos(15, 14)
- colore(colors.white)
- term.write(" ")
- term.setCursorPos(15, 14)
- elseif importo <= saldo and importo > 0 then
- term.setCursorPos(15, 14)
- colore(colors.lime)
- term.write(importo .. " IC")
- colore(colors.white)
- importoAccettato = true
- else
- conteggioErrori = conteggioErrori + 1
- term.setCursorPos(15, 14)
- colore(colors.red)
- term.write("Credito insufficiente! ")
- sleep(2)
- term.setCursorPos(15, 14)
- colore(colors.white)
- term.write(" ")
- term.setCursorPos(15, 14)
- if conteggioErrori > 2 then
- term.setCursorPos(15, 14)
- colore(colors.red)
- term.write("Tre tentativi di immissione errati.")
- sleep(2)
- term.setCursorPos(15, 14)
- colore(colors.white)
- term.write(" ")
- term.setCursorPos(15, 14)
- clear()
- os.reboot()
- end
- end
- end
- sleep(0.5)
- clear()
- titolo("Riepilogo del trasferimento")
- text = "Vuoi inviare " .. importo .. " IC a " .. beneficiario .. "?"
- term.setCursorPos((maxw - #text) / 2, 6)
- term.write("Vuoi inviare ")
- colore(colors.white)
- term.write(tostring(importo) .. " IC ")
- colore(colors.black)
- term.write("a ")
- colore(colors.white)
- term.write(beneficiario)
- colore(colors.black)
- term.write("?")
- drawFilledBox(7, 11, 23, 13, colors.white)
- drawFilledBox(29, 11, 45, 13, colors.white)
- term.setCursorPos(8, 12)
- colore(colors.lime)
- term.write("Invia il denaro")
- term.setCursorPos(34, 12)
- colore(colors.red)
- term.write("Annulla")
- inviare = false
- while true do
- event, key, x, y = os.pullEvent()
- if event == "mouse_click" and x >= 7 and x <= 23 and y >= 11 and y <= 13 then
- inviaDenaro = http.get("http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" .. password .. "&utente=" .. utente .. "&richiesta=trasferimento&valore=" .. importo .. "&beneficiario=" .. beneficiario).readAll()
- risultatoInvio = textutils.unserialize(inviaDenaro)
- if risultatoInvio.stato == "OK" then
- text = "Invio del denaro riuscito."
- text2 = "Nuovo saldo: " .. risultatoInvio.credito .. " IC"
- sfondo(colors.lightBlue)
- colore(colors.lime)
- term.setCursorPos((maxw - #text) / 2, 16)
- term.write(text)
- colore(colors.black)
- term.setCursorPos((maxw - #text2) / 2, 18)
- term.write(text2)
- sleep(2)
- clear()
- break
- else
- text = "Errore durante l'invio del denaro."
- text2 = risultatoInvio.errore
- sfondo(colors.lightBlue)
- colore(colors.red)
- term.setCursorPos((maxw - #text) / 2, 16)
- term.write(text)
- colore(colors.black)
- term.setCursorPos((maxw - #text2) / 2, 18)
- term.write(text2)
- sleep(2)
- clear()
- break
- end
- elseif event == "mouse_click" and x >= 29 and x <= 45 and y >= 11 and y <= 13 then
- sfondo(colors.lightBlue)
- colore(colors.red)
- text = "Operazione annullata."
- term.setCursorPos((maxw - #text) / 2, 16)
- term.write(text)
- sleep(1.5)
- clear()
- break
- end
- end
- elseif event == "mouse_click" and y == 13 and x <= 24 then --Pulsante disconnetti da nPay
- disconnetti()
- elseif event == "timer" and key == antitonto then --Butta fuori l'utente se non fa niente
- disconnetti()
- elseif event == "mouse_click" and x == maxw and y == maxh then -- Auto aggiornamento su magic corner (pannello utente)
- update()
- end
- end
- elseif event == "mouse_click" and x == maxw and y == maxh then -- Auto aggiornamento su magic corner (schermata principale)
- update()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement