SHOW:
|
|
- or go back to the newest paste.
| 1 | - | -- Versamenti FRACASSO |
| 1 | + | -- Versamenti Frigor Gelati |
| 2 | -- Variabili config | |
| 3 | - | local uri = "http://172.16.20.220/luanet/servlets/vendite/cannery" |
| 3 | + | local uri = "http://172.16.20.220/luanet/servlets/vendite/gelati" |
| 4 | - | local pb = "5t0sDU8W" |
| 4 | + | local pb = "3PJZLWUd" |
| 5 | ||
| 6 | local maxw, maxh = term.getSize() | |
| 7 | ||
| 8 | ben = peripheral.wrap("back")
| |
| 9 | ||
| 10 | -- funzioni helper di base | |
| 11 | ||
| 12 | function tablelength(T) | |
| 13 | local count = 0 | |
| 14 | for _ in pairs(T) do | |
| 15 | count = count + 1 | |
| 16 | end | |
| 17 | return count | |
| 18 | end | |
| 19 | ||
| 20 | function clear() | |
| 21 | term.clear() | |
| 22 | term.setCursorPos(1, 1) | |
| 23 | end | |
| 24 | ||
| 25 | function clearRed() | |
| 26 | sfondo(colors.red) | |
| 27 | term.clear() | |
| 28 | term.setCursorPos(1, 1) | |
| 29 | end | |
| 30 | ||
| 31 | function colore(sfumatura) | |
| 32 | term.setTextColour(sfumatura) | |
| 33 | end | |
| 34 | ||
| 35 | function sfondo(sfumaturaSfondo) | |
| 36 | term.setBackgroundColour(sfumaturaSfondo) | |
| 37 | end | |
| 38 | ||
| 39 | function fineColore() | |
| 40 | term.setTextColour(colours.white) | |
| 41 | end | |
| 42 | ||
| 43 | function fineSfondo() | |
| 44 | term.setBackgroundColour(colours.black) | |
| 45 | end | |
| 46 | ||
| 47 | -- IMPLEMENTAZIONE DEL DRAWFILLEDBOX | |
| 48 | local function drawPixelInternal(xPos, yPos) | |
| 49 | term.setCursorPos(xPos, yPos) | |
| 50 | term.write(" ")
| |
| 51 | end | |
| 52 | ||
| 53 | local tColourLookup = {}
| |
| 54 | for n = 1, 16 do | |
| 55 | tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
| |
| 56 | end | |
| 57 | ||
| 58 | function drawFilledBox(startX, startY, endX, endY, nColour) | |
| 59 | if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~= "number" or type(endY) ~= "number" or | |
| 60 | (nColour ~= nil and type(nColour) ~= "number") then | |
| 61 | error("Expected startX, startY, endX, endY, colour", 2)
| |
| 62 | end | |
| 63 | ||
| 64 | startX = math.floor(startX) | |
| 65 | startY = math.floor(startY) | |
| 66 | endX = math.floor(endX) | |
| 67 | endY = math.floor(endY) | |
| 68 | ||
| 69 | if nColour then | |
| 70 | term.setBackgroundColor(nColour) | |
| 71 | end | |
| 72 | if startX == endX and startY == endY then | |
| 73 | drawPixelInternal(startX, startY) | |
| 74 | return | |
| 75 | end | |
| 76 | ||
| 77 | local minX = math.min(startX, endX) | |
| 78 | if minX == startX then | |
| 79 | minY = startY | |
| 80 | maxX = endX | |
| 81 | maxY = endY | |
| 82 | else | |
| 83 | minY = endY | |
| 84 | maxX = startX | |
| 85 | maxY = startY | |
| 86 | end | |
| 87 | ||
| 88 | for x = minX, maxX do | |
| 89 | for y = minY, maxY do | |
| 90 | drawPixelInternal(x, y) | |
| 91 | end | |
| 92 | end | |
| 93 | end | |
| 94 | ||
| 95 | function titolo(testo) | |
| 96 | drawFilledBox(1, 1, maxw, 1, colors.yellow) | |
| 97 | term.setCursorPos((maxw - #testo) / 2, 1) | |
| 98 | colore(colors.black) | |
| 99 | term.write(testo) | |
| 100 | sfondo(colors.lightBlue) | |
| 101 | end | |
| 102 | ||
| 103 | function errore(errore) | |
| 104 | sfondo(colors.red) | |
| 105 | colore(colors.white) | |
| 106 | term.clear() | |
| 107 | term.setCursorPos(1, 1) | |
| 108 | titolo("Errore irreversibile")
| |
| 109 | term.setCursorPos(1, 3) | |
| 110 | sfondo(colors.red) | |
| 111 | colore(colors.white) | |
| 112 | print(errore) | |
| 113 | print("\n\n\nAttendere qualche secondo...")
| |
| 114 | os.sleep(5) | |
| 115 | os.reboot() | |
| 116 | end | |
| 117 | ||
| 118 | -- verifica servizi online e recupero prezzario | |
| 119 | ||
| 120 | prezzario_raw = http.get(uri .. "/?richiesta=prezzario_lua").readAll() | |
| 121 | prezzario = textutils.unserialize(prezzario_raw) | |
| 122 | ||
| 123 | if type(prezzario) ~= "table" then | |
| 124 | errore("Impossibile comunicare con il server interbancario")
| |
| 125 | end | |
| 126 | ||
| 127 | -- variabili quantità | |
| 128 | ||
| 129 | counted_items = {}
| |
| 130 | id_items = {}
| |
| 131 | ||
| 132 | -- enumerazione prezzario | |
| 133 | ||
| 134 | acceptedItems = "" | |
| 135 | ||
| 136 | for k, v in pairs(prezzario) do | |
| 137 | id_items[ben.getItemIdentifierIDFor(v.id, v.meta)] = k | |
| 138 | acceptedItems = acceptedItems .. v.nome .. ", " | |
| 139 | end | |
| 140 | ||
| 141 | -- PER DOPO print("Item: " .. id_items[v[1]] .. " qty: " .. v[2] .. " price: " .. prezzario[id_items[v[1]]]["prezzo"])
| |
| 142 | ||
| 143 | -- vuota il bancomat | |
| 144 | ben.getAvailableItems() | |
| 145 | i, j = os.pullEvent("available_items_return")
| |
| 146 | ||
| 147 | for k, v in pairs(j) do | |
| 148 | counted_items[id_items[v[1]]] = v[2] | |
| 149 | ben.makeRequest(v[1], v[2]) | |
| 150 | sleep(0.1) | |
| 151 | end | |
| 152 | ||
| 153 | -- resetta counted_items e controlla se è vuoto | |
| 154 | ||
| 155 | counted_items = {}
| |
| 156 | ||
| 157 | ben.getAvailableItems() | |
| 158 | i, j = os.pullEvent("available_items_return")
| |
| 159 | for k, v in pairs(j) do | |
| 160 | counted_items[id_items[v[1]]] = v[2] | |
| 161 | sleep(0.1) | |
| 162 | end | |
| 163 | ||
| 164 | if tablelength(counted_items) ~= 0 then | |
| 165 | sfondo(colors.red) | |
| 166 | colore(colors.white) | |
| 167 | term.clear() | |
| 168 | term.setCursorPos(1, 1) | |
| 169 | titolo("Errore irreversibile")
| |
| 170 | term.setCursorPos(1, 3) | |
| 171 | sfondo(colors.red) | |
| 172 | colore(colors.white) | |
| 173 | print("Svuotamento non possibile, sportello fuori servizio")
| |
| 174 | print("\n\n\nContattare il Banco di Nebraska")
| |
| 175 | os.sleep(60) | |
| 176 | os.reboot() | |
| 177 | end | |
| 178 | ||
| 179 | sfondo(colors.lightBlue) | |
| 180 | clear() | |
| 181 | titolo("Banco di Nebraska - Sistema sportelli vendite")
| |
| 182 | sfondo(colors.lightBlue) | |
| 183 | print("\n\n")
| |
| 184 | print("Questo sportello accetta: " .. acceptedItems:sub(1, -3))
| |
| 185 | ||
| 186 | -- pulsante vendi | |
| 187 | drawFilledBox(16, 15, 33, 17, colors.white) | |
| 188 | term.setCursorPos(17, 16) | |
| 189 | term.write("Inizia a vendere")
| |
| 190 | ||
| 191 | event = os.pullEvent() | |
| 192 | ||
| 193 | sfondo(colours.lightBlue) | |
| 194 | term.clear() | |
| 195 | term.setCursorPos(1, 1) | |
| 196 | titolo("Accredita su Nebraska Pay")
| |
| 197 | sfondo(colours.lightBlue) | |
| 198 | ||
| 199 | term.setCursorPos(1, 3) | |
| 200 | print("Inserire i propri dati.")
| |
| 201 | colore(colors.gray) | |
| 202 | print( | |
| 203 | "Premere Enter per confermare i dati inseriti.\nSe i dati sono corretti, il campo diventerà verde.\nSe sono errati, il programma chiederà di reinserirli nuovamente.") | |
| 204 | ||
| 205 | -- nomeutente | |
| 206 | colore(colors.black) | |
| 207 | term.setCursorPos(1, 9) | |
| 208 | term.write("Nome utente:")
| |
| 209 | term.setCursorPos(15, 9) | |
| 210 | fineColore() | |
| 211 | utenteAccettato = false | |
| 212 | conteggioErrori = 0 | |
| 213 | while utenteAccettato == false do | |
| 214 | utente = read() | |
| 215 | utente = string.gsub(utente, "%s", "") | |
| 216 | checkuser = http.get("http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=no&richiesta=verifica&utente=" ..
| |
| 217 | utente).readAll() | |
| 218 | tabcheckuser = textutils.unserialize(checkuser) | |
| 219 | if tabcheckuser.stato == "OK" then | |
| 220 | term.setCursorPos(15, 9) | |
| 221 | colore(colours.lime) | |
| 222 | term.write(utente) | |
| 223 | fineColore() | |
| 224 | utenteAccettato = true | |
| 225 | else | |
| 226 | term.setCursorPos(15, 9) | |
| 227 | colore(colours.red) | |
| 228 | term.write("Utente errato! ")
| |
| 229 | sleep(2) | |
| 230 | term.setCursorPos(15, 9) | |
| 231 | fineColore() | |
| 232 | term.write(" ")
| |
| 233 | term.setCursorPos(15, 9) | |
| 234 | conteggioErrori = conteggioErrori + 1 | |
| 235 | if conteggioErrori > 2 then | |
| 236 | term.setCursorPos(15, 9) | |
| 237 | colore(colours.red) | |
| 238 | errore("Troppi tentativi di immissione errati ")
| |
| 239 | end | |
| 240 | end | |
| 241 | end | |
| 242 | colore(colours.black) | |
| 243 | term.setCursorPos(1, 11) | |
| 244 | term.write("Password:")
| |
| 245 | term.setCursorPos(15, 11) | |
| 246 | conteggioErrori = 0 | |
| 247 | passAccettata = false | |
| 248 | while passAccettata == false do | |
| 249 | fineColore() | |
| 250 | password = read("#")
| |
| 251 | colore(colours.black) | |
| 252 | checkuser = http.get("http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" .. password ..
| |
| 253 | "&richiesta=addebito&valore=0&utente=" .. utente).readAll() | |
| 254 | risposta = textutils.unserialize(checkuser) | |
| 255 | if risposta.stato == "OK" then | |
| 256 | term.setCursorPos(15, 11) | |
| 257 | colore(colours.lime) | |
| 258 | term.write("############## ")
| |
| 259 | fineColore() | |
| 260 | passAccettata = true | |
| 261 | else | |
| 262 | term.setCursorPos(15, 11) | |
| 263 | colore(colours.red) | |
| 264 | term.write("Password errata! ")
| |
| 265 | conteggioErrori = conteggioErrori + 1 | |
| 266 | sleep(2) | |
| 267 | term.setCursorPos(15, 11) | |
| 268 | term.write(" ")
| |
| 269 | term.setCursorPos(15, 11) | |
| 270 | if conteggioErrori > 2 then | |
| 271 | term.setCursorPos(15, 11) | |
| 272 | colore(colours.red) | |
| 273 | errore("Troppi tentativi di immissione errati")
| |
| 274 | end | |
| 275 | end | |
| 276 | end | |
| 277 | ||
| 278 | credito = tonumber(risposta.saldo) | |
| 279 | clear() | |
| 280 | ||
| 281 | while true do | |
| 282 | ||
| 283 | titolo("Pannello utente nPay")
| |
| 284 | term.setCursorPos(1, 3) | |
| 285 | term.write("Benvenuto, ")
| |
| 286 | colore(colors.white) | |
| 287 | term.write(utente) | |
| 288 | colore(colors.black) | |
| 289 | term.write("! Saldo: ")
| |
| 290 | colore(colors.white) | |
| 291 | term.write(risposta.saldo) | |
| 292 | colore(colors.black) | |
| 293 | term.write(" IC")
| |
| 294 | print("\n\nOperazioni disponibili:\n")
| |
| 295 | sfondo(colors.white) | |
| 296 | print(" Vendi oggetti \n")
| |
| 297 | colore(colors.red) | |
| 298 | print(" Annulla operazione \n")
| |
| 299 | colore(colors.black) | |
| 300 | ||
| 301 | antitonto = os.startTimer(60) | |
| 302 | ||
| 303 | event, key, x, y = os.pullEventRaw() | |
| 304 | if event == "mouse_click" and y == 7 and x <= 24 then | |
| 305 | sfondo(colors.lightBlue) | |
| 306 | clear() | |
| 307 | titolo("Operazione di vendita - Passo 1")
| |
| 308 | ||
| 309 | redstone.setOutput("left", true)
| |
| 310 | print("\n\nInserire gli oggetti nello sportello a destra oppure collocare il Deep Storage di fronte al cubo rosso.")
| |
| 311 | print("")
| |
| 312 | print("Eventuali oggetti non accettati non verranno ritirati dal meccanismo.\n")
| |
| 313 | ||
| 314 | sfondo(colors.red) | |
| 315 | print("ATTENZIONE: NON RIAVVIARE IL COMPUTER O SI PERDERA' IL VERSAMENTO")
| |
| 316 | sfondo(colors.lightBlue) | |
| 317 | ||
| 318 | print("")
| |
| 319 | print("Quando si è pronti per continuare, premere un tasto qualsiasi.")
| |
| 320 | os.pullEvent("key")
| |
| 321 | ||
| 322 | clear() | |
| 323 | ||
| 324 | redstone.setOutput("left", false)
| |
| 325 | titolo("Operazione di vendita - Passo 2")
| |
| 326 | ||
| 327 | print("\n\nConteggio oggetti venduti in corso...")
| |
| 328 | ||
| 329 | term.setCursorPos(3, 6) | |
| 330 | term.write("*---")
| |
| 331 | sleep(0.5) | |
| 332 | term.setCursorPos(3, 6) | |
| 333 | term.write("-*--")
| |
| 334 | sleep(0.5) | |
| 335 | term.setCursorPos(3, 6) | |
| 336 | term.write("--*-")
| |
| 337 | sleep(0.5) | |
| 338 | term.setCursorPos(3, 6) | |
| 339 | term.write("---*")
| |
| 340 | sleep(0.5) | |
| 341 | term.setCursorPos(3, 6) | |
| 342 | term.write("--*-")
| |
| 343 | sleep(0.5) | |
| 344 | term.setCursorPos(3, 6) | |
| 345 | term.write("-*--")
| |
| 346 | sleep(0.5) | |
| 347 | term.setCursorPos(3, 6) | |
| 348 | term.write("*---")
| |
| 349 | sleep(0.5) | |
| 350 | ||
| 351 | ben = peripheral.wrap("back")
| |
| 352 | ben.getAvailableItems() | |
| 353 | i, j = os.pullEvent("available_items_return")
| |
| 354 | ||
| 355 | clear() | |
| 356 | ||
| 357 | -- vuota il bancomat | |
| 358 | ben.getAvailableItems() | |
| 359 | i, j = os.pullEvent("available_items_return")
| |
| 360 | ||
| 361 | for k, v in pairs(j) do | |
| 362 | counted_items[id_items[v[1]]] = v[2] | |
| 363 | ben.makeRequest(v[1], v[2]) | |
| 364 | sleep(0.1) | |
| 365 | end | |
| 366 | ||
| 367 | if tablelength(counted_items) == 0 then | |
| 368 | errore("Nessun oggetto risulta essere stato introdotto")
| |
| 369 | end | |
| 370 | ||
| 371 | titolo("Operazione di vendita - Passo 3")
| |
| 372 | print("\n\nGli oggetti sono stati conteggiati correttamente.\nComunicazione con i servizi interbancari in corso...")
| |
| 373 | print("")
| |
| 374 | items_uri = "" | |
| 375 | ||
| 376 | for k, v in pairs(counted_items) do | |
| 377 | items_uri = items_uri .. "&" .. k .. "=" .. v | |
| 378 | end | |
| 379 | ||
| 380 | inviaDenaro = http.get(uri .. "/?richiesta=vendita&auth=" .. password .. "&utente=" .. utente .. | |
| 381 | "&richiesta=vendita" .. items_uri).readAll() | |
| 382 | risultatoInvio = textutils.unserialize(inviaDenaro) | |
| 383 | if risultatoInvio.stato == "OK" then | |
| 384 | colore(colors.white) | |
| 385 | else | |
| 386 | clear() | |
| 387 | errore("Errore durante il pagamento")
| |
| 388 | sleep(5) | |
| 389 | os.reboot() | |
| 390 | end | |
| 391 | sleep(1) | |
| 392 | print("Comunicazione con i servizi fiscali in corso...")
| |
| 393 | sleep(1) | |
| 394 | clear() | |
| 395 | titolo("Operazione di vendita conclusa")
| |
| 396 | print("\n\nDenaro versato: " .. math.abs(tonumber(risultatoInvio.credito) - tonumber(risultatoInvio.saldo)) .. " IC")
| |
| 397 | print("")
| |
| 398 | print("Il totale è stato comunicato all'Agenzia dei Tributi e comparirà nel proprio cassetto fiscale")
| |
| 399 | print("")
| |
| 400 | print("Grazie!")
| |
| 401 | print("")
| |
| 402 | print("Tra poco sarà possibile eseguire una nuova operazione.")
| |
| 403 | sleep(10) | |
| 404 | term.setTextColor(colors.lightBlue) | |
| 405 | shell.run("pastebin get " .. pb .. " startup2")
| |
| 406 | if fs.exists("startup2") then
| |
| 407 | shell.run("rm startup")
| |
| 408 | shell.run("mv startup2 startup")
| |
| 409 | end | |
| 410 | os.reboot() | |
| 411 | elseif event == "mouse_click" and y == 9 and x <= 24 then -- Pulsante disconnetti da nPay | |
| 412 | clear() | |
| 413 | break | |
| 414 | elseif event == "timer" and key == antitonto then -- Butta fuori l'utente se non fa niente | |
| 415 | disconnetti() | |
| 416 | break | |
| 417 | end | |
| 418 | end | |
| 419 | sfondo(colors.lightBlue) | |
| 420 | clear() | |
| 421 | print("Attendere")
| |
| 422 | term.setTextColor(colors.lightBlue) | |
| 423 | sfondo(colors.lightBlue) | |
| 424 | shell.run("pastebin get " .. pb .. " startup2")
| |
| 425 | if fs.exists("startup2") then
| |
| 426 | shell.run("rm startup")
| |
| 427 | shell.run("mv startup2 startup")
| |
| 428 | end | |
| 429 | os.reboot() | |
| 430 |