FoxWorn3365

HLB - Crea Sim

May 11th, 2026 (edited)
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.30 KB | None | 0 0
  1. -- funzioni helper di base
  2. local maxw, maxh = term.getSize()
  3.  
  4. pl = peripheral.wrap("right")
  5. sim = peripheral.wrap("left")
  6.  
  7. function tablelength(T)
  8.     local count = 0
  9.     for _ in pairs(T) do
  10.         count = count + 1
  11.     end
  12.     return count
  13. end
  14.  
  15. function clear()
  16.     term.clear()
  17.     term.setCursorPos(1, 1)
  18. end
  19.  
  20. function clearRed()
  21.     sfondo(colors.red)
  22.     term.clear()
  23.     term.setCursorPos(1, 1)
  24. end
  25.  
  26. function colore(sfumatura)
  27.     term.setTextColour(sfumatura)
  28. end
  29.  
  30. function sfondo(sfumaturaSfondo)
  31.     term.setBackgroundColour(sfumaturaSfondo)
  32. end
  33.  
  34. function fineColore()
  35.     term.setTextColour(colours.white)
  36. end
  37.  
  38. function fineSfondo()
  39.     term.setBackgroundColour(colours.black)
  40. end
  41.  
  42. -- IMPLEMENTAZIONE DEL DRAWFILLEDBOX
  43. local function drawPixelInternal(xPos, yPos)
  44.     term.setCursorPos(xPos, yPos)
  45.     term.write(" ")
  46. end
  47.  
  48. local tColourLookup = {}
  49. for n = 1, 16 do
  50.     tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
  51. end
  52.  
  53. function drawFilledBox(startX, startY, endX, endY, nColour)
  54.     if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~= "number" or type(endY) ~= "number" or
  55.         (nColour ~= nil and type(nColour) ~= "number") then
  56.         error("Expected startX, startY, endX, endY, colour", 2)
  57.     end
  58.  
  59.     startX = math.floor(startX)
  60.     startY = math.floor(startY)
  61.     endX = math.floor(endX)
  62.     endY = math.floor(endY)
  63.  
  64.     if nColour then
  65.         term.setBackgroundColor(nColour)
  66.     end
  67.     if startX == endX and startY == endY then
  68.         drawPixelInternal(startX, startY)
  69.         return
  70.     end
  71.  
  72.     local minX = math.min(startX, endX)
  73.     if minX == startX then
  74.         minY = startY
  75.         maxX = endX
  76.         maxY = endY
  77.     else
  78.         minY = endY
  79.         maxX = startX
  80.         maxY = startY
  81.     end
  82.  
  83.     for x = minX, maxX do
  84.         for y = minY, maxY do
  85.             drawPixelInternal(x, y)
  86.         end
  87.     end
  88. end
  89.  
  90. function titolo(testo, bk, cl)
  91.     drawFilledBox(1, 1, maxw, 1, bk)
  92.     term.setCursorPos((maxw - #testo) / 2, 1)
  93.     colore(cl)
  94.     term.write(testo)
  95. end
  96.  
  97. function errore(errore)
  98.     sfondo(colors.red)
  99.     colore(colors.white)
  100.     term.clear()
  101.     term.setCursorPos(1, 1)
  102.     titolo("Errore irreversibile")
  103.     term.setCursorPos(1, 3)
  104.     sfondo(colors.red)
  105.     colore(colors.white)
  106.     print(errore)
  107.     print("\n\n\nAttendere qualche secondo...")
  108.     os.sleep(5)
  109.     os.reboot()
  110. end
  111.  
  112. -- Variabili d'ambiente
  113. page = 0
  114. player = nil
  115.  
  116. -- Programma
  117. while true do
  118.     sfondo(colors.magenta)
  119.     colore(colors.white)
  120.     clear()
  121.     if page == 0 then
  122.         titolo("Highland Mobile", colors.purple, colors.white)
  123.         sfondo(colors.magenta)
  124.         term.setCursorPos(2, 3)
  125.         term.write("Ciao e benvenuto su RGBCraft!")
  126.         term.setCursorPos(2, 5)
  127.         term.write("Noi siamo la                  , operatore")
  128.         term.setCursorPos(2, 6)
  129.         term.write("statale di telefonia mobile.")
  130.         term.setCursorPos(2, 8)
  131.         term.write("Cliccando sul bottone sottotante potrai")
  132.         term.setCursorPos(2, 9)
  133.         term.write("richiedere la tua nuovissima SIM Card")
  134.         term.setCursorPos(2, 10)
  135.         term.write("con il nostro piano scelto apposta per te!")
  136.         term.setCursorPos(2, 12)
  137.         term.write("Piano personalizzato: Simple20")
  138.         drawFilledBox(8, 15, 42, 17, colors.purple)
  139.         term.setCursorPos(16, 16)
  140.         term.write("Avvia la procedura!")
  141.         sfondo(colors.purple)
  142.         term.setCursorPos(15, 5)
  143.         term.write("Highland MobileTM")
  144.     elseif page == 1 then
  145.         titolo("Richiedi una SIM Card", colors.purple, colors.white)
  146.         sfondo(colors.magenta)
  147.         term.setCursorPos(3, 6)
  148.         term.write("Per favore, appoggia la tua impronta digitale")
  149.         term.setCursorPos(3, 7)
  150.         term.write("nel sensore sulla destra del computer...")
  151.     elseif page == 2 then
  152.         if player == nil then
  153.             errore("Morte e distruzione pt.2")
  154.         end
  155.  
  156.         titolo("Richiedi una SIM Card", colors.purple, colors.white)
  157.         sfondo(colors.magenta)
  158.         term.setCursorPos(3, 4)
  159.         term.write("Invio richiesta aut. da server g.c. in corso...")
  160.         local h = http.get("https://gsm.rgbcraft.com/?request=registerNewNumber&mnc=1&player="..player)
  161.         data = h.readAll()
  162.         h.close()
  163.         data = json.decode(data)
  164.  
  165.         if data == nil or data.status ~= 200 then
  166.             errore("Errore durante la richiesta di registrazione del numero!")
  167.         end
  168.  
  169.         number = data.response
  170.         number = "0"..number
  171.  
  172.         term.setCursorPos(3, 6)
  173.         term.write("Creazione della SIM...")
  174.  
  175.         iccid = sim.registerSim(false, number, "Highland Mobile Prepaid")
  176.  
  177.         term.setCursorPos(3, 8)
  178.         term.write("Conferma della registrazione...")
  179.  
  180.         local h = http.get("https://gsm.rgbcraft.com/?request=registerICCID&iccid="..iccid.."&phone_number="..number)
  181.         data = h.readAll()
  182.         h.close()
  183.  
  184.         data2 = json.decode(data)
  185.  
  186.         if data2 == nil then
  187.             errore("Morte e distruzione!")
  188.         end
  189.  
  190.         if data2.status == 200 then
  191.             term.setCursorPos(3, 10)
  192.             term.write("SIM Registrata con successo!")
  193.             term.setCursorPos(3, 11)
  194.             term.write("La SIM Card verrà erogata a breve...")
  195.             sleep(1)
  196.             sim.ejectSim()
  197.             sleep(3)
  198.             os.reboot()
  199.         else
  200.             errore("Errore nell'associazione dell'ICCID al numero di telefono!")
  201.         end
  202.     end
  203.    
  204.     local ev, a, b, c = os.pullEvent()
  205.     if page == 0 and ev == "mouse_click" and c >= 15 then
  206.         page = 1
  207.     elseif page == 1 and ev == "player" then
  208.         page = 2
  209.         player = a
  210.     end
  211. end
Advertisement
Add Comment
Please, Sign In to add comment