Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- funzioni helper di base
- local maxw, maxh = term.getSize()
- os.loadAPI("json")
- PL = peripheral.wrap("right")
- SIM = peripheral.wrap("left")
- function tablelength(T)
- local count = 0
- for _ in pairs(T) do
- count = count + 1
- end
- return count
- 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, bk, cl)
- drawFilledBox(1, 1, maxw, 1, bk)
- term.setCursorPos((maxw - #testo) / 2, 1)
- colore(cl)
- term.write(testo)
- 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
- function askAuthentication()
- sleep(0.1)
- sfondo(colors.magenta)
- clear()
- titolo("Autenticazione con impronta", colors.purple, colors.white)
- sfondo(colors.magenta)
- term.setCursorPos(3, 6)
- term.write("Per favore, appoggia la tua impronta digitale")
- term.setCursorPos(3, 7)
- term.write("sul sensore a destra del computer...")
- while true do
- local ev, PLAYER = os.pullEvent()
- if ev == "player" then
- return PLAYER
- end
- end
- end
- -- Variabili d'ambiente
- page = "home"
- PLAYER = nil
- -- Programma
- while true do
- sfondo(colors.magenta)
- colore(colors.white)
- clear()
- if page == "home" then
- titolo("Highland Mobile", colors.purple, colors.white)
- sfondo(colors.magenta)
- term.setCursorPos(2, 3)
- term.write("Benvenuto in Sodium!")
- term.setCursorPos(2, 5)
- print("Con questo chiosco potrai: ")
- print("- Registrare una nuova SIM ed un nuovo numero di")
- print(" telefono")
- print("- Registrare una nuova SIM ad un numero esistente")
- print("- Cambiare il piano tariffario")
- print("- Portare in HighlandMobile un numero di altri")
- print(" operatori")
- drawFilledBox(8, 15, 42, 17, colors.purple)
- term.setCursorPos(16, 16)
- term.write("Avvia la procedura")
- sfondo(colors.purple)
- elseif page == "menu" then
- sfondo(colors.magenta)
- clear()
- titolo("Highland Mobile", colors.purple, colors.white)
- sfondo(colors.magenta)
- term.setCursorPos(2, 3)
- term.write("Scelta operazione:")
- term.setCursorPos(2, 5)
- sfondo(colors.purple)
- term.write(" Richiedi nuova SIM e nuovo numero ")
- term.setCursorPos(2, 7)
- term.write(" Richiedi SIM sostitutiva (duplicata) ")
- term.setCursorPos(2, 9)
- term.write(" Cambia piano tariffario ")
- term.setCursorPos(2, 11)
- term.write(" Porta in HighlandMobile un numero ")
- term.setCursorPos(2, 13)
- term.write(" Annulla e torna indietro ")
- elseif page == "requestNewSIM" then
- if PLAYER == nil then
- errore("Errore impronta digitale")
- end
- titolo("Richiedi una SIM Card", colors.purple, colors.white)
- sfondo(colors.magenta)
- term.setCursorPos(3, 4)
- term.write("Invio richiesta aut. da server g.c. in corso...")
- local h = http.get("https://gsm.rgbcraft.com/?request=registerNewNumber&mnc=8&player=" .. PLAYER)
- if h == nil then
- errore("Endpoint non raggiungibile")
- end
- response = h.readAll()
- h.close()
- if response == nil then
- errore("Endpoint risposta non JSON")
- end
- data = json.json.decode(response)
- number = data.response
- number = "0" .. number
- term.setCursorPos(3, 6)
- term.write("Creazione della SIM...")
- SIM.destroySim()
- iccid = SIM.registerSim(false, number, "Highland Mobile Prepaid")
- term.setCursorPos(3, 8)
- term.write("Conferma della registrazione...")
- local h = http.get("https://gsm.rgbcraft.com/?request=registerICCID&iccid=" .. iccid .. "&phone_number=" ..
- number)
- data = h.readAll()
- h.close()
- data2 = json.json.decode(data)
- if data2.status == 200 then
- term.setCursorPos(3, 10)
- term.write("SIM Registrata con successo!")
- term.setCursorPos(3, 11)
- term.write("La SIM Card verråA0 erogata a breve...")
- term.setCursorPos(3, 12)
- print("Inserisci la SIM Card nel telefono per utilizzarla.")
- sleep(1)
- SIM.ejectSim()
- sleep(3)
- os.reboot()
- else
- errore()
- end
- elseif page == "requestDuplicate" then
- if PLAYER == nil then
- errore("Errore impronta digitale")
- end
- titolo("Richiedi una SIM duplicata", colors.purple, colors.white)
- sfondo(colors.magenta)
- while true do
- term.setCursorPos(3, 4)
- term.write("Inserire il numero di telefono da duplicare:")
- term.setCursorPos(3, 6)
- term.write("Numero: ")
- term.setCursorPos(12, 6)
- number = read()
- if #number == 10 then
- break
- else
- term.setCursorPos(3, 6)
- term.write("Numero non valido ")
- sleep(1)
- end
- end
- term.setCursorPos(3, 6)
- term.write("Creazione della SIM...")
- SIM.destroySim()
- iccid = SIM.registerSim(false, number, "Highland Mobile")
- term.setCursorPos(3, 8)
- term.write("Conferma della registrazione...")
- local h = http.get("https://gsm.rgbcraft.com/?request=registerICCID&iccid=" .. iccid .. "&phone_number=" ..
- number)
- data = h.readAll()
- h.close()
- data = json.json.decode(data)
- if data.status == 200 then
- term.setCursorPos(3, 10)
- term.write("SIM registrata con successo!")
- term.setCursorPos(3, 11)
- term.write("La SIM Card verråA0 erogata a breve...")
- term.setCursorPos(3, 12)
- print("Inserisci la SIM Card nel telefono per utilizzarla.")
- sleep(1)
- SIM.ejectSim()
- sleep(3)
- os.reboot()
- else
- errore()
- end
- end
- local ev, a, b, c = os.pullEvent()
- if page == "home" and ev == "mouse_click" and c >= 15 then
- page = "menu"
- elseif page == "menu" and ev == "mouse_click" then
- if c == 5 then
- PLAYER = askAuthentication()
- page = "requestNewSIM"
- elseif c == 7 then
- PLAYER = askAuthentication()
- page = "requestDuplicate"
- elseif c == 9 then
- --page = "changePlan"
- elseif c == 11 then
- --page = "numberPortability"
- elseif c == 13 then
- page = "home"
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment