lego11

Versamento V3

Oct 3rd, 2025 (edited)
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.61 KB | None | 0 0
  1. -- Bancomat versamento
  2. -- Variabili config
  3. local uri = "http://luanet.rgbcraft.com/servlets/bancomat/"
  4.  
  5. local maxw, maxh = term.getSize()
  6.  
  7. ben = peripheral.wrap("back")
  8.  
  9. function drawCard()
  10. drawFilledBox(6, 7, 24, 7, colors.blue)
  11. drawFilledBox(6, 15, 24, 15, colors.blue)
  12. drawFilledBox(5, 8, 25, 14, colors.blue)
  13.  
  14. drawFilledBox(7, 9, 23, 9, colors.lightGray)
  15. drawFilledBox(7, 12, 23, 13, colors.black)
  16. end
  17.  
  18. mag = peripheral.wrap("right")
  19.  
  20. -- funzioni helper di base
  21.  
  22. function tablelength(T)
  23. local count = 0
  24. for _ in pairs(T) do
  25. count = count + 1
  26. end
  27. return count
  28. end
  29.  
  30. function update()
  31. term.setCursorPos(1, 21)
  32. shell.run("pastebin get mfTb10RP startup2")
  33. if fs.exists("startup2") then
  34. shell.run("rm startup")
  35. shell.run("mv startup2 startup")
  36. end
  37. os.reboot()
  38. end
  39.  
  40. function clear()
  41. term.clear()
  42. term.setCursorPos(1, 1)
  43. end
  44.  
  45. function clearRed()
  46. sfondo(colors.red)
  47. term.clear()
  48. term.setCursorPos(1, 1)
  49. end
  50.  
  51. function colore(sfumatura)
  52. term.setTextColour(sfumatura)
  53. end
  54.  
  55. function sfondo(sfumaturaSfondo)
  56. term.setBackgroundColour(sfumaturaSfondo)
  57. end
  58.  
  59. function fineColore()
  60. term.setTextColour(colours.white)
  61. end
  62.  
  63. function fineSfondo()
  64. term.setBackgroundColour(colours.black)
  65. end
  66.  
  67. -- IMPLEMENTAZIONE DEL DRAWFILLEDBOX
  68. local function drawPixelInternal(xPos, yPos)
  69. term.setCursorPos(xPos, yPos)
  70. term.write(" ")
  71. end
  72.  
  73. local tColourLookup = {}
  74. for n = 1, 16 do
  75. tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
  76. end
  77.  
  78. function drawFilledBox(startX, startY, endX, endY, nColour)
  79. if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~= "number" or type(endY) ~= "number" or
  80. (nColour ~= nil and type(nColour) ~= "number") then
  81. error("Expected startX, startY, endX, endY, colour", 2)
  82. end
  83.  
  84. startX = math.floor(startX)
  85. startY = math.floor(startY)
  86. endX = math.floor(endX)
  87. endY = math.floor(endY)
  88.  
  89. if nColour then
  90. term.setBackgroundColor(nColour)
  91. end
  92. if startX == endX and startY == endY then
  93. drawPixelInternal(startX, startY)
  94. return
  95. end
  96.  
  97. local minX = math.min(startX, endX)
  98. if minX == startX then
  99. minY = startY
  100. maxX = endX
  101. maxY = endY
  102. else
  103. minY = endY
  104. maxX = startX
  105. maxY = startY
  106. end
  107.  
  108. for x = minX, maxX do
  109. for y = minY, maxY do
  110. drawPixelInternal(x, y)
  111. end
  112. end
  113. end
  114.  
  115. function titolo(testo)
  116. drawFilledBox(1, 1, maxw, 1, colors.yellow)
  117. term.setCursorPos((maxw - #testo) / 2, 1)
  118. colore(colors.black)
  119. term.write(testo)
  120. sfondo(colors.lightBlue)
  121. end
  122.  
  123. function errore(errore)
  124. sfondo(colors.red)
  125. colore(colors.white)
  126. term.clear()
  127. term.setCursorPos(1, 1)
  128. titolo("Errore irreversibile")
  129. term.setCursorPos(1, 3)
  130. sfondo(colors.red)
  131. colore(colors.white)
  132. print(errore)
  133. print("\n\n\nAttendere qualche secondo...")
  134. os.sleep(5)
  135. os.reboot()
  136. end
  137.  
  138. -- verifica servizi online e recupero prezzario
  139.  
  140. prezzario_raw = http.get(uri .. "/?richiesta=prezzario_lua").readAll()
  141. prezzario = textutils.unserialize(prezzario_raw)
  142.  
  143. if type(prezzario) ~= "table" then
  144. errore("Impossibile comunicare con il server interbancario")
  145. end
  146.  
  147. -- variabili quantità
  148.  
  149. counted_items = {}
  150. id_items = {}
  151.  
  152. -- enumerazione prezzario
  153.  
  154. for k, v in pairs(prezzario) do
  155. id_items[ben.getItemIdentifierIDFor(v.id, v.meta)] = k
  156. end
  157.  
  158. -- vuota il bancomat
  159. ben.getAvailableItems()
  160. i, j = os.pullEvent("available_items_return")
  161.  
  162. for k, v in pairs(j) do
  163. counted_items[id_items[v[1]]] = v[2]
  164. ben.makeRequest(v[1], v[2])
  165. sleep(0.1)
  166. end
  167.  
  168. -- resetta counted_items e controlla se è vuoto
  169.  
  170. counted_items = {}
  171.  
  172. ben.getAvailableItems()
  173. i, j = os.pullEvent("available_items_return")
  174. for k, v in pairs(j) do
  175. counted_items[id_items[v[1]]] = v[2]
  176. sleep(0.1)
  177. end
  178.  
  179. if tablelength(counted_items) ~= 0 then
  180. sfondo(colors.red)
  181. colore(colors.white)
  182. term.clear()
  183. term.setCursorPos(1, 1)
  184. titolo("Errore irreversibile")
  185. term.setCursorPos(1, 3)
  186. sfondo(colors.red)
  187. colore(colors.white)
  188. print("Svuotamento non possibile, sportello fuori servizio")
  189. print("\n\n\nContattare il Banco di Nebraska")
  190. os.sleep(60)
  191. os.reboot()
  192. end
  193.  
  194. sfondo(colors.lightBlue)
  195. clear()
  196. titolo("Banco di Nebraska - Versamento Denaro")
  197. sfondo(colors.lightBlue)
  198. print("\n\n")
  199. print(
  200. "Questo sportello accetta tutte le monete.\n\nE' possibile versare monete su una carta di debito oppure su un conto nPay")
  201.  
  202. drawFilledBox(16, 11, 33, 13, colors.white)
  203. term.setCursorPos(17, 12)
  204. term.write("Versare su carta")
  205.  
  206. -- Versamento su nPay
  207. drawFilledBox(16, 15, 33, 17, colors.white)
  208. term.setCursorPos(17, 16)
  209. term.write("Versare su nPay")
  210.  
  211. while true do
  212. event, key, x, y = os.pullEvent("mouse_click")
  213. -- pulsante carta
  214. if event == "mouse_click" and x >= 16 and x <= 33 and y >= 11 and y <= 13 then
  215. sfondo(colors.lightBlue)
  216. clear()
  217. titolo("Versamento su carta di debito")
  218. colore(colors.black)
  219. drawCard()
  220. sfondo(colors.lightBlue)
  221. term.setCursorPos(30, 8)
  222. print("INSERIRE LA CARTA")
  223. term.setCursorPos(29, 10)
  224. print("NEL LETTORE A DESTRA")
  225. drawFilledBox(34, 14, 42, 14, colors.white)
  226. term.setCursorPos(35, 14)
  227. term.write("Annulla")
  228. mag.setInsertCardLight(true)
  229. finalBreakC = false
  230. while true do
  231. event, arg1, arg2, arg3 = os.pullEventRaw()
  232. if event == "mouse_click" and arg3 == 14 and arg2 >= 34 and arg2 <= 42 then -- arg2 = x | arg3 = y
  233. mag.setInsertCardLight(false)
  234. os.reboot()
  235. elseif event == "mag_swipe" then
  236. mag.setInsertCardLight(false)
  237. tabel = textutils.unserialize(arg1)
  238. if tabel == "" or tabel == nil then
  239. errore("Carta smagnetizzata")
  240. elseif tabel.t == "cc" then
  241. errore("Carta NON SICURA, convertire prima la carta allo sportello di conversione situato in:\n\nBanco di Nebraska - P.zza Affari 3, New Radeon")
  242. elseif tabel.t ~= "cd" or tabel.e ~= "BN" then
  243. errore("Carta non valida o corrotta")
  244. else
  245. modoPagamento = "carta"
  246. utente = "CARTA_" .. string.sub(tostring(tabel.v), -4)
  247. break
  248. end
  249. end
  250. end
  251. break
  252. -- pulsante NPay
  253. elseif event == "mouse_click" and x >= 16 and x <= 33 and y >= 15 and y <= 17 then
  254. sfondo(colours.lightBlue)
  255. term.clear()
  256. term.setCursorPos(1, 1)
  257. titolo("Accredita su Nebraska Pay")
  258. sfondo(colours.lightBlue)
  259.  
  260. term.setCursorPos(1, 3)
  261. print("Inserire i propri dati.")
  262. colore(colors.gray)
  263. print(
  264. "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.")
  265.  
  266. -- nomeutente
  267. colore(colors.black)
  268. term.setCursorPos(1, 9)
  269. term.write("Nome utente:")
  270. term.setCursorPos(15, 9)
  271. fineColore()
  272. utenteAccettato = false
  273. conteggioErrori = 0
  274. while utenteAccettato == false do
  275. utente = read()
  276. utente = string.gsub(utente, "%s", "")
  277. checkuser = http.get(
  278. "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=no&richiesta=verifica&utente=" ..
  279. utente).readAll()
  280. tabcheckuser = textutils.unserialize(checkuser)
  281. if tabcheckuser.stato == "OK" then
  282. term.setCursorPos(15, 9)
  283. colore(colours.lime)
  284. term.write(utente)
  285. fineColore()
  286. utenteAccettato = true
  287. else
  288. term.setCursorPos(15, 9)
  289. colore(colours.red)
  290. term.write("Utente errato! ")
  291. sleep(2)
  292. term.setCursorPos(15, 9)
  293. fineColore()
  294. term.write(" ")
  295. term.setCursorPos(15, 9)
  296. conteggioErrori = conteggioErrori + 1
  297. if conteggioErrori > 2 then
  298. term.setCursorPos(15, 9)
  299. colore(colours.red)
  300. errore("Troppi tentativi di immissione errati ")
  301. end
  302. end
  303. end
  304. colore(colours.black)
  305. term.setCursorPos(1, 11)
  306. term.write("Password:")
  307. term.setCursorPos(15, 11)
  308. conteggioErrori = 0
  309. passAccettata = false
  310. while passAccettata == false do
  311. fineColore()
  312. password = read("#")
  313. colore(colours.black)
  314. checkuser = http.get("http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" .. password ..
  315. "&richiesta=addebito&valore=0&utente=" .. utente).readAll()
  316. risposta = textutils.unserialize(checkuser)
  317. if risposta.stato == "OK" then
  318. term.setCursorPos(15, 11)
  319. colore(colours.lime)
  320. term.write("############## ")
  321. fineColore()
  322. passAccettata = true
  323. else
  324. term.setCursorPos(15, 11)
  325. colore(colours.red)
  326. term.write("Password errata! ")
  327. conteggioErrori = conteggioErrori + 1
  328. sleep(2)
  329. term.setCursorPos(15, 11)
  330. term.write(" ")
  331. term.setCursorPos(15, 11)
  332. if conteggioErrori > 2 then
  333. term.setCursorPos(15, 11)
  334. colore(colours.red)
  335. errore("Troppi tentativi di immissione errati")
  336. end
  337. end
  338. end
  339.  
  340. credito = tonumber(risposta.saldo)
  341. modoPagamento = "npay"
  342. break
  343. elseif event == "mouse_click" and x == maxw and y == maxh then -- Auto aggiornamento su magic corner (schermata principale)
  344. update()
  345. end
  346. end
  347.  
  348. sfondo(colors.lightBlue)
  349. clear()
  350.  
  351. while true do
  352.  
  353. if modoPagamento == "carta" then
  354. sibRaw = http.get("http://luanet.rgbcraft.com/servlets/carte_debito.php?richiesta=verifica&uuid=" ..
  355. tabel.v).readAll()
  356. sib = textutils.unserialize(sibRaw)
  357. if type(sib) ~= "table" then
  358. errore("Impossibile comunicare con il server interbancario")
  359. end
  360. if sib.stato ~= "OK" then
  361. errore("La carta non risulta nel sistema interbancario, potrebbe essere stata disabilitata per uso fraudolento")
  362. end
  363. saldo = sib.saldo
  364. else
  365. saldo = risposta.saldo
  366. end
  367.  
  368. titolo("Sistema versamento")
  369. term.setCursorPos(1, 3)
  370. term.write("Benvenuto, ")
  371. colore(colors.gray)
  372. term.write(utente)
  373. colore(colors.black)
  374. term.write("! Saldo: ")
  375. colore(colors.gray)
  376. term.write(saldo)
  377. colore(colors.black)
  378. term.write(" IC")
  379. print("\n\nOperazioni disponibili:\n")
  380. sfondo(colors.white)
  381. print(" Versa denaro contante \n")
  382. colore(colors.red)
  383. print(" Annulla operazione \n")
  384. colore(colors.black)
  385.  
  386. antitonto = os.startTimer(60)
  387.  
  388. event, key, x, y = os.pullEventRaw()
  389. if event == "mouse_click" and y == 7 and x <= 24 then
  390. sfondo(colors.lightBlue)
  391. clear()
  392. titolo("Operazione di versamento - Passo 1")
  393.  
  394. redstone.setOutput("left", true)
  395. print(
  396. "\n\nInserire gli oggetti nello sportello a destra oppure collocare il Deep Storage di fronte al cubo rosso.")
  397. print("")
  398. print("Eventuali oggetti non accettati non verranno ritirati dal meccanismo.\n")
  399.  
  400. sfondo(colors.red)
  401. print("ATTENZIONE: NON RIAVVIARE IL COMPUTER O SI PERDERA' IL VERSAMENTO")
  402. sfondo(colors.lightBlue)
  403.  
  404. print("")
  405. print("Quando si è pronti per continuare, premere un tasto qualsiasi.")
  406. os.pullEvent("key")
  407.  
  408. clear()
  409.  
  410. redstone.setOutput("left", false)
  411. titolo("Operazione di versamento - Passo 2")
  412.  
  413. print("\n\nConteggio contanti inseriti in corso...")
  414.  
  415. term.setCursorPos(3, 6)
  416. term.write("*---")
  417. sleep(0.5)
  418. term.setCursorPos(3, 6)
  419. term.write("-*--")
  420. sleep(0.5)
  421. term.setCursorPos(3, 6)
  422. term.write("--*-")
  423. sleep(0.5)
  424. term.setCursorPos(3, 6)
  425. term.write("---*")
  426. sleep(0.5)
  427. term.setCursorPos(3, 6)
  428. term.write("--*-")
  429. sleep(0.5)
  430. term.setCursorPos(3, 6)
  431. term.write("-*--")
  432. sleep(0.5)
  433. term.setCursorPos(3, 6)
  434. term.write("*---")
  435. sleep(0.5)
  436.  
  437. ben = peripheral.wrap("back")
  438. ben.getAvailableItems()
  439. i, j = os.pullEvent("available_items_return")
  440.  
  441. clear()
  442.  
  443. -- vuota il bancomat
  444. ben.getAvailableItems()
  445. i, j = os.pullEvent("available_items_return")
  446.  
  447. for k, v in pairs(j) do
  448. counted_items[id_items[v[1]]] = v[2]
  449. ben.makeRequest(v[1], v[2])
  450. sleep(0.1)
  451. end
  452.  
  453. if tablelength(counted_items) == 0 then
  454. errore("Nessun contante risulta essere stato introdotto")
  455. end
  456.  
  457. titolo("Operazione di versamento - Passo 3")
  458. print(
  459. "\n\nI contanti sono stati conteggiati correttamente.\nComunicazione con i servizi interbancari in corso...")
  460. print("")
  461. items_uri = ""
  462.  
  463. for k, v in pairs(counted_items) do
  464. items_uri = items_uri .. "&" .. k .. "=" .. v
  465. end
  466.  
  467. if modoPagamento == "carta" then
  468. inviaDenaro = http.get(uri .. "/?richiesta=versamento_carta&uuid=" .. tabel.v ..
  469. items_uri).readAll()
  470. else
  471. inviaDenaro = http.get(uri .. "/?richiesta=versamento_npay&auth=" .. password .. "&utente=" .. utente ..
  472. items_uri).readAll()
  473. end
  474. risultatoInvio = textutils.unserialize(inviaDenaro)
  475. if risultatoInvio.stato == "OK" then
  476. colore(colors.white)
  477. else
  478. clear()
  479. errore("Errore durante il pagamento")
  480. sleep(5)
  481. os.reboot()
  482. end
  483. sleep(1)
  484. print("Comunicazione con i servizi fiscali in corso...")
  485. sleep(1)
  486. clear()
  487. titolo("Operazione di versamento conclusa")
  488. print("\n\nDenaro versato: " .. math.abs(tonumber(risultatoInvio.credito) - tonumber(risultatoInvio.saldo)) ..
  489. " IC")
  490. print("")
  491. print("")
  492. print("Grazie!")
  493. print("")
  494. print("Tra poco sarà possibile eseguire una nuova operazione.")
  495. sleep(10)
  496. term.setTextColor(colors.lightBlue)
  497. update()
  498. elseif event == "mouse_click" and y == 9 and x <= 24 then -- Pulsante disconnetti da nPay
  499. clear()
  500. break
  501. elseif event == "timer" and key == antitonto then -- Butta fuori l'utente se non fa niente
  502. disconnetti()
  503. break
  504. end
  505. end
  506. sfondo(colors.lightBlue)
  507. clear()
  508. print("Attendere")
  509. term.setTextColor(colors.lightBlue)
  510. sfondo(colors.lightBlue)
  511. update()
  512. os.reboot()
  513.  
Advertisement
Add Comment
Please, Sign In to add comment