Advertisement
lego11

CGS Consegna

Sep 11th, 2022 (edited)
969
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.26 KB | None | 0 0
  1. local maxw, maxh = term.getSize()
  2.  
  3. function clear()
  4.     term.clear()
  5.     term.setCursorPos(1, 1)
  6. end
  7.  
  8. function clearRed()
  9.     sfondo(colors.red)
  10.     term.clear()
  11.     term.setCursorPos(1, 1)
  12. end
  13.  
  14. function colore(sfumatura) term.setTextColour(sfumatura) end
  15.  
  16. function sfondo(sfumaturaSfondo) term.setBackgroundColour(sfumaturaSfondo) end
  17.  
  18. function fineColore() term.setTextColour(colours.white) end
  19.  
  20. function fineSfondo() term.setBackgroundColour(colours.black) end
  21.  
  22.  
  23. -- IMPLEMENTAZIONE DEL DRAWFILLEDBOX
  24. local function drawPixelInternal(xPos, yPos)
  25.     term.setCursorPos(xPos, yPos)
  26.     term.write(" ")
  27. end
  28.  
  29. local tColourLookup = {}
  30. for n = 1, 16 do
  31.     tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
  32. end
  33.  
  34. function drawFilledBox(startX, startY, endX, endY, nColour)
  35.     if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~=
  36.         "number" or type(endY) ~= "number" or
  37.         (nColour ~= nil and type(nColour) ~= "number") then
  38.         error("Expected startX, startY, endX, endY, colour", 2)
  39.     end
  40.  
  41.     startX = math.floor(startX)
  42.     startY = math.floor(startY)
  43.     endX = math.floor(endX)
  44.     endY = math.floor(endY)
  45.  
  46.     if nColour then term.setBackgroundColor(nColour) end
  47.     if startX == endX and startY == endY then
  48.         drawPixelInternal(startX, startY)
  49.         return
  50.     end
  51.  
  52.     local minX = math.min(startX, endX)
  53.     if minX == startX then
  54.         minY = startY
  55.         maxX = endX
  56.         maxY = endY
  57.     else
  58.         minY = endY
  59.         maxX = startX
  60.         maxY = startY
  61.     end
  62.  
  63.     for x = minX, maxX do for y = minY, maxY do drawPixelInternal(x, y) end end
  64. end
  65.  
  66.  
  67. function titolo(testo)
  68.     drawFilledBox(1, 1, maxw, 1, colors.yellow)
  69.     term.setCursorPos((maxw - #testo) / 2, 1)
  70.     colore(colors.black)
  71.     term.write(testo)
  72.     term.setBackgroundColor(colors.black)
  73.     colore(colors.white)
  74. end
  75.  
  76. function errore(errore)
  77.     sfondo(colors.red)
  78.     colore(colors.white)
  79.     term.clear()
  80.     term.setCursorPos(1, 1)
  81.     titolo("Errore irreversibile")
  82.     term.setCursorPos(1, 3)
  83.     sfondo(colors.red)
  84.     colore(colors.white)
  85.     print(errore)
  86.     print("\n\n\nAttendere qualche secondo...")
  87.     os.sleep(5)
  88.     os.reboot()
  89. end
  90.  
  91. clear()
  92. titolo("DEEPINATOR 3000")
  93. print("\n\nCGS SpA - Consegna carichi")
  94. print("")
  95. print("Premere un tasto per iniziare l'operazione")
  96. print("")
  97. colore(colors.orange)
  98. print("ATTENZIONE, AVVERTENZA MOLTO IMPORTANTE")
  99. print("NON RIAVVIARE MAI IL COMPUTER DURANTE LA CONSEGNA")
  100. print("In caso contrario, l'ordine verrà distrutto!")
  101. os.pullEvent("key")
  102.  
  103.     sfondo(colours.blue)
  104.     term.clear()
  105.     term.setCursorPos(1, 1)
  106.     titolo("Autenticati con Nebraska Pay")
  107.     sfondo(colours.blue)
  108.     colore(colors.white)
  109.     print(
  110.         "\n\nInserire i propri dati (non verrà effettuato alcun addebito). Premere Enter per confermare i dati inseriti. \nSe i dati sono errati, il programma chiederà di reinserirli nuovamente.")
  111.  
  112.     -- nomeutente
  113.     term.setCursorPos(1, 9)
  114.     term.write("Nome utente:")
  115.     term.setCursorPos(15, 9)
  116.     fineColore()
  117.     utenteAccettato = false
  118.     conteggioErrori = 0
  119.     while utenteAccettato == false do
  120.         utente = read()
  121.         utente = string.gsub(utente, "%s", "")
  122.         checkuser = http.get(
  123.                         "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=no&richiesta=verifica&utente=" ..
  124.                             utente).readAll()
  125.         tabcheckuser = textutils.unserialize(checkuser)
  126.         if tabcheckuser.stato == "OK" then
  127.             term.setCursorPos(15, 9)
  128.             colore(colours.lime)
  129.             term.write(utente)
  130.             fineColore()
  131.             utenteAccettato = true
  132.         else
  133.             term.setCursorPos(15, 9)
  134.             colore(colours.red)
  135.             term.write("Utente errato!          ")
  136.             sleep(2)
  137.             term.setCursorPos(15, 9)
  138.             fineColore()
  139.             term.write("                       ")
  140.             term.setCursorPos(15, 9)
  141.             conteggioErrori = conteggioErrori + 1
  142.             if conteggioErrori > 2 then
  143.                 term.setCursorPos(15, 9)
  144.                 colore(colours.red)
  145.                 errore("Troppi tentativi di immissione errati    ")
  146.             end
  147.         end
  148.     end
  149.     colore(colours.white)
  150.     term.setCursorPos(1, 11)
  151.     term.write("Password:")
  152.     term.setCursorPos(15, 11)
  153.     conteggioErrori = 0
  154.     passAccettata = false
  155.     while passAccettata == false do
  156.         fineColore()
  157.         password = read("#")
  158.         colore(colours.black)
  159.         checkuser = http.get(
  160.                         "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" ..
  161.                             password .. "&richiesta=addebito&valore=0&utente=" ..
  162.                             utente).readAll()
  163.         risposta = textutils.unserialize(checkuser)
  164.         if risposta.stato == "OK" then
  165.             term.setCursorPos(15, 11)
  166.             colore(colours.lime)
  167.             term.write("##############               ")
  168.             fineColore()
  169.             passAccettata = true
  170.         else
  171.             term.setCursorPos(15, 11)
  172.             colore(colours.red)
  173.             term.write("Password errata!            ")
  174.             conteggioErrori = conteggioErrori + 1
  175.             sleep(2)
  176.             term.setCursorPos(15, 11)
  177.             term.write("                               ")
  178.             term.setCursorPos(15, 11)
  179.             if conteggioErrori > 2 then
  180.                 term.setCursorPos(15, 11)
  181.                 colore(colours.red)
  182.                 errore("Troppi tentativi di immissione errati")
  183.             end
  184.         end
  185.     end
  186.    
  187. local ordersRaw = http.get("http://sunfire.a-centauri.com/cgs/check_pending_orders.php").readAll()
  188. orders = textutils.unserialize(ordersRaw)
  189.  
  190. local foundOrder = false
  191. sfondo(colors.black)
  192. clear()
  193. titolo("Verifica ordine in corso...")
  194. print("\n")
  195. for k, v in pairs(orders) do
  196.     if v.user == utente then
  197.         print("Trovato ordine: " .. v.id .. ":" .. v.meta .. " * " .. v.qty .. " - ID: " .. v.uuid)
  198.         foundOrder = true
  199.         print("Richiesto ordine: scaffale " .. v.bundled .. " - posizione " .. v.colore)
  200.         for i=1,v.qty,1 do
  201.             if v.bundled == "1" then
  202.                 rs.setBundledOutput("back", tonumber(v.colore))
  203.             elseif v.bundled == "2" then
  204.                 rs.setBundledOutput("top", tonumber(v.colore))
  205.             end
  206.             sleep(0.5)
  207.             rs.setBundledOutput("back", 0)
  208.                 print("Qtà: " .. i .. " / " .. v.qty)
  209.             rs.setBundledOutput("top", 0)
  210.             sleep(0.5)
  211.         end
  212.         print("Attendere l'erogazione ordine: " .. v.uuid)
  213.         sleep(1)
  214.         local fulfillOrder = http.get("http://sunfire.a-centauri.com/cgs/fulfill_order.php?uuid=" .. v.uuid).readAll()
  215.         print("Ordine consegnato: " .. v.uuid)
  216.     end
  217. end
  218. if foundOrder == false then
  219.     errore("Nessun ordine trovato a nome di " ..utente)
  220. end
  221.  
  222. sfondo(colors.black)
  223. colore(colors.lime)
  224. term.clear()
  225. term.setCursorPos(1, 1)
  226. titolo("Ordini consegnati")
  227. term.setCursorPos(1, 3)
  228. sfondo(colors.black)
  229. colore(colors.lime)
  230. print("\n\n\nAttendere qualche secondo per l'erogazione di tutti gli ordini...")
  231. os.sleep(5)
  232. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement