SHOW:
|
|
- or go back to the newest paste.
| 1 | -- funzioni helper di base | |
| 2 | local maxw, maxh = term.getSize() | |
| 3 | ||
| 4 | os.loadAPI("json")
| |
| 5 | ||
| 6 | PL = peripheral.wrap("right")
| |
| 7 | SIM = peripheral.wrap("left")
| |
| 8 | ||
| 9 | function tablelength(T) | |
| 10 | local count = 0 | |
| 11 | for _ in pairs(T) do | |
| 12 | count = count + 1 | |
| 13 | end | |
| 14 | return count | |
| 15 | end | |
| 16 | ||
| 17 | function clear() | |
| 18 | term.clear() | |
| 19 | term.setCursorPos(1, 1) | |
| 20 | end | |
| 21 | ||
| 22 | function clearRed() | |
| 23 | sfondo(colors.red) | |
| 24 | term.clear() | |
| 25 | term.setCursorPos(1, 1) | |
| 26 | end | |
| 27 | ||
| 28 | function colore(sfumatura) | |
| 29 | term.setTextColour(sfumatura) | |
| 30 | end | |
| 31 | ||
| 32 | function sfondo(sfumaturaSfondo) | |
| 33 | term.setBackgroundColour(sfumaturaSfondo) | |
| 34 | end | |
| 35 | ||
| 36 | function fineColore() | |
| 37 | term.setTextColour(colours.white) | |
| 38 | end | |
| 39 | ||
| 40 | function fineSfondo() | |
| 41 | term.setBackgroundColour(colours.black) | |
| 42 | end | |
| 43 | ||
| 44 | -- IMPLEMENTAZIONE DEL DRAWFILLEDBOX | |
| 45 | local function drawPixelInternal(xPos, yPos) | |
| 46 | term.setCursorPos(xPos, yPos) | |
| 47 | term.write(" ")
| |
| 48 | end | |
| 49 | ||
| 50 | local tColourLookup = {}
| |
| 51 | for n = 1, 16 do | |
| 52 | tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
| |
| 53 | end | |
| 54 | ||
| 55 | function drawFilledBox(startX, startY, endX, endY, nColour) | |
| 56 | if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~= "number" or type(endY) ~= "number" or | |
| 57 | (nColour ~= nil and type(nColour) ~= "number") then | |
| 58 | error("Expected startX, startY, endX, endY, colour", 2)
| |
| 59 | end | |
| 60 | ||
| 61 | startX = math.floor(startX) | |
| 62 | startY = math.floor(startY) | |
| 63 | endX = math.floor(endX) | |
| 64 | endY = math.floor(endY) | |
| 65 | ||
| 66 | if nColour then | |
| 67 | term.setBackgroundColor(nColour) | |
| 68 | end | |
| 69 | if startX == endX and startY == endY then | |
| 70 | drawPixelInternal(startX, startY) | |
| 71 | return | |
| 72 | end | |
| 73 | ||
| 74 | local minX = math.min(startX, endX) | |
| 75 | if minX == startX then | |
| 76 | minY = startY | |
| 77 | maxX = endX | |
| 78 | maxY = endY | |
| 79 | else | |
| 80 | minY = endY | |
| 81 | maxX = startX | |
| 82 | maxY = startY | |
| 83 | end | |
| 84 | ||
| 85 | for x = minX, maxX do | |
| 86 | for y = minY, maxY do | |
| 87 | drawPixelInternal(x, y) | |
| 88 | end | |
| 89 | end | |
| 90 | end | |
| 91 | ||
| 92 | function titolo(testo, bk, cl) | |
| 93 | drawFilledBox(1, 1, maxw, 1, bk) | |
| 94 | term.setCursorPos((maxw - #testo) / 2, 1) | |
| 95 | colore(cl) | |
| 96 | term.write(testo) | |
| 97 | end | |
| 98 | ||
| 99 | function errore(errore) | |
| 100 | sfondo(colors.red) | |
| 101 | colore(colors.white) | |
| 102 | term.clear() | |
| 103 | term.setCursorPos(1, 1) | |
| 104 | titolo("Errore irreversibile")
| |
| 105 | term.setCursorPos(1, 3) | |
| 106 | sfondo(colors.red) | |
| 107 | colore(colors.white) | |
| 108 | print(errore) | |
| 109 | print("\n\n\nAttendere qualche secondo...")
| |
| 110 | os.sleep(5) | |
| 111 | os.reboot() | |
| 112 | end | |
| 113 | ||
| 114 | ||
| 115 | function askAuthentication() | |
| 116 | sleep(0.1) | |
| 117 | sfondo(colors.magenta) | |
| 118 | clear() | |
| 119 | titolo("Autenticazione con impronta", colors.purple, colors.white)
| |
| 120 | sfondo(colors.magenta) | |
| 121 | term.setCursorPos(3, 6) | |
| 122 | term.write("Per favore, appoggia la tua impronta digitale")
| |
| 123 | term.setCursorPos(3, 7) | |
| 124 | term.write("sul sensore a destra del computer...")
| |
| 125 | while true do | |
| 126 | local ev, PLAYER = os.pullEvent() | |
| 127 | if ev == "player" then | |
| 128 | return PLAYER | |
| 129 | end | |
| 130 | end | |
| 131 | end | |
| 132 | ||
| 133 | ||
| 134 | -- Variabili d'ambiente | |
| 135 | page = "home" | |
| 136 | PLAYER = nil | |
| 137 | ||
| 138 | -- Programma | |
| 139 | while true do | |
| 140 | sfondo(colors.magenta) | |
| 141 | colore(colors.white) | |
| 142 | clear() | |
| 143 | if page == "home" then | |
| 144 | titolo("Highland Mobile", colors.purple, colors.white)
| |
| 145 | sfondo(colors.magenta) | |
| 146 | term.setCursorPos(2, 3) | |
| 147 | - | term.write("Benvenuto in HighlandMobile!")
|
| 147 | + | term.write("Benvenuto in Sodium!")
|
| 148 | term.setCursorPos(2, 5) | |
| 149 | print("Con questo chiosco potrai: ")
| |
| 150 | print("- Registrare una nuova SIM ed un nuovo numero di")
| |
| 151 | print(" telefono")
| |
| 152 | print("- Registrare una nuova SIM ad un numero esistente")
| |
| 153 | print("- Cambiare il piano tariffario")
| |
| 154 | print("- Portare in HighlandMobile un numero di altri")
| |
| 155 | print(" operatori")
| |
| 156 | drawFilledBox(8, 15, 42, 17, colors.purple) | |
| 157 | term.setCursorPos(16, 16) | |
| 158 | term.write("Avvia la procedura")
| |
| 159 | sfondo(colors.purple) | |
| 160 | elseif page == "menu" then | |
| 161 | sfondo(colors.magenta) | |
| 162 | clear() | |
| 163 | titolo("Highland Mobile", colors.purple, colors.white)
| |
| 164 | sfondo(colors.magenta) | |
| 165 | term.setCursorPos(2, 3) | |
| 166 | term.write("Scelta operazione:")
| |
| 167 | term.setCursorPos(2, 5) | |
| 168 | sfondo(colors.purple) | |
| 169 | term.write(" Richiedi nuova SIM e nuovo numero ")
| |
| 170 | term.setCursorPos(2, 7) | |
| 171 | term.write(" Richiedi SIM sostitutiva (duplicata) ")
| |
| 172 | term.setCursorPos(2, 9) | |
| 173 | term.write(" Cambia piano tariffario ")
| |
| 174 | term.setCursorPos(2, 11) | |
| 175 | term.write(" Porta in HighlandMobile un numero ")
| |
| 176 | term.setCursorPos(2, 13) | |
| 177 | term.write(" Annulla e torna indietro ")
| |
| 178 | elseif page == "requestNewSIM" then | |
| 179 | if PLAYER == nil then | |
| 180 | errore("Errore impronta digitale")
| |
| 181 | end | |
| 182 | titolo("Richiedi una SIM Card", colors.purple, colors.white)
| |
| 183 | sfondo(colors.magenta) | |
| 184 | term.setCursorPos(3, 4) | |
| 185 | term.write("Invio richiesta aut. da server g.c. in corso...")
| |
| 186 | - | local h = http.get("https://gsm.rgbcraft.com/?request=registerNewNumber&mnc=1&player=" .. PLAYER)
|
| 186 | + | local h = http.get("https://gsm.rgbcraft.com/?request=registerNewNumber&mnc=8&player=" .. PLAYER)
|
| 187 | if h == nil then | |
| 188 | errore("Endpoint non raggiungibile")
| |
| 189 | end | |
| 190 | response = h.readAll() | |
| 191 | h.close() | |
| 192 | ||
| 193 | if response == nil then | |
| 194 | errore("Endpoint risposta non JSON")
| |
| 195 | end | |
| 196 | ||
| 197 | data = json.json.decode(response) | |
| 198 | number = data.response | |
| 199 | number = "0" .. number | |
| 200 | ||
| 201 | term.setCursorPos(3, 6) | |
| 202 | term.write("Creazione della SIM...")
| |
| 203 | ||
| 204 | SIM.destroySim() | |
| 205 | iccid = SIM.registerSim(false, number, "Highland Mobile Prepaid") | |
| 206 | ||
| 207 | term.setCursorPos(3, 8) | |
| 208 | term.write("Conferma della registrazione...")
| |
| 209 | ||
| 210 | local h = http.get("https://gsm.rgbcraft.com/?request=registerICCID&iccid=" .. iccid .. "&phone_number=" ..
| |
| 211 | number) | |
| 212 | data = h.readAll() | |
| 213 | h.close() | |
| 214 | ||
| 215 | data2 = json.json.decode(data) | |
| 216 | ||
| 217 | if data2.status == 200 then | |
| 218 | term.setCursorPos(3, 10) | |
| 219 | term.write("SIM Registrata con successo!")
| |
| 220 | term.setCursorPos(3, 11) | |
| 221 | term.write("La SIM Card verråA0 erogata a breve...")
| |
| 222 | term.setCursorPos(3, 12) | |
| 223 | print("Inserisci la SIM Card nel telefono per utilizzarla.")
| |
| 224 | sleep(1) | |
| 225 | SIM.ejectSim() | |
| 226 | sleep(3) | |
| 227 | os.reboot() | |
| 228 | else | |
| 229 | errore() | |
| 230 | end | |
| 231 | elseif page == "requestDuplicate" then | |
| 232 | if PLAYER == nil then | |
| 233 | errore("Errore impronta digitale")
| |
| 234 | end | |
| 235 | ||
| 236 | titolo("Richiedi una SIM duplicata", colors.purple, colors.white)
| |
| 237 | sfondo(colors.magenta) | |
| 238 | while true do | |
| 239 | term.setCursorPos(3, 4) | |
| 240 | term.write("Inserire il numero di telefono da duplicare:")
| |
| 241 | term.setCursorPos(3, 6) | |
| 242 | term.write("Numero: ")
| |
| 243 | term.setCursorPos(12, 6) | |
| 244 | number = read() | |
| 245 | if #number == 10 then | |
| 246 | break | |
| 247 | else | |
| 248 | term.setCursorPos(3, 6) | |
| 249 | term.write("Numero non valido ")
| |
| 250 | sleep(1) | |
| 251 | end | |
| 252 | end | |
| 253 | ||
| 254 | term.setCursorPos(3, 6) | |
| 255 | term.write("Creazione della SIM...")
| |
| 256 | ||
| 257 | SIM.destroySim() | |
| 258 | iccid = SIM.registerSim(false, number, "Highland Mobile") | |
| 259 | ||
| 260 | term.setCursorPos(3, 8) | |
| 261 | term.write("Conferma della registrazione...")
| |
| 262 | ||
| 263 | local h = http.get("https://gsm.rgbcraft.com/?request=registerICCID&iccid=" .. iccid .. "&phone_number=" ..
| |
| 264 | number) | |
| 265 | data = h.readAll() | |
| 266 | h.close() | |
| 267 | ||
| 268 | data = json.json.decode(data) | |
| 269 | ||
| 270 | if data.status == 200 then | |
| 271 | term.setCursorPos(3, 10) | |
| 272 | term.write("SIM registrata con successo!")
| |
| 273 | term.setCursorPos(3, 11) | |
| 274 | term.write("La SIM Card verråA0 erogata a breve...")
| |
| 275 | term.setCursorPos(3, 12) | |
| 276 | print("Inserisci la SIM Card nel telefono per utilizzarla.")
| |
| 277 | sleep(1) | |
| 278 | SIM.ejectSim() | |
| 279 | sleep(3) | |
| 280 | os.reboot() | |
| 281 | else | |
| 282 | errore() | |
| 283 | end | |
| 284 | end | |
| 285 | ||
| 286 | local ev, a, b, c = os.pullEvent() | |
| 287 | if page == "home" and ev == "mouse_click" and c >= 15 then | |
| 288 | page = "menu" | |
| 289 | elseif page == "menu" and ev == "mouse_click" then | |
| 290 | if c == 5 then | |
| 291 | PLAYER = askAuthentication() | |
| 292 | page = "requestNewSIM" | |
| 293 | elseif c == 7 then | |
| 294 | PLAYER = askAuthentication() | |
| 295 | page = "requestDuplicate" | |
| 296 | elseif c == 9 then | |
| 297 | --page = "changePlan" | |
| 298 | elseif c == 11 then | |
| 299 | --page = "numberPortability" | |
| 300 | elseif c == 13 then | |
| 301 | page = "home" | |
| 302 | end | |
| 303 | end | |
| 304 | end |