Advertisement
MrDionesalvi

PNRF

Oct 10th, 2021 (edited)
943
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.03 KB | None | 0 0
  1. -- CFG Program Files
  2.  
  3. local maxw, maxh = term.getSize()
  4. local printer = peripheral.wrap("back")
  5.  
  6. os.pullEvent = os.pullEventRaw
  7.  
  8. -- IMPLEMENTAZIONE DEL DRAWFILLEDBOX
  9. local function drawPixelInternal(xPos, yPos)
  10.     term.setCursorPos(xPos, yPos)
  11.     term.write(" ")
  12. end
  13.  
  14. Gplayer = ""
  15.  
  16. local tColourLookup = {}
  17. for n = 1, 16 do
  18.     tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
  19. end
  20.  
  21. function drawFilledBox(startX, startY, endX, endY, nColour)
  22.     if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~=
  23.         "number" or type(endY) ~= "number" or
  24.         (nColour ~= nil and type(nColour) ~= "number") then
  25.         error("Expected startX, startY, endX, endY, colour", 2)
  26.     end
  27.  
  28.     startX = math.floor(startX)
  29.     startY = math.floor(startY)
  30.     endX = math.floor(endX)
  31.     endY = math.floor(endY)
  32.  
  33.     if nColour then term.setBackgroundColor(nColour) end
  34.     if startX == endX and startY == endY then
  35.         drawPixelInternal(startX, startY)
  36.         return
  37.     end
  38.  
  39.     local minX = math.min(startX, endX)
  40.     if minX == startX then
  41.         minY = startY
  42.         maxX = endX
  43.         maxY = endY
  44.     else
  45.         minY = endY
  46.         maxX = startX
  47.         maxY = startY
  48.     end
  49.  
  50.     for x = minX, maxX do for y = minY, maxY do drawPixelInternal(x, y) end end
  51. end
  52.  
  53. function colore(nome) term.setTextColor(nome) end
  54.  
  55. function sfondo(nome) term.setBackgroundColor(nome) end
  56.  
  57. function fineColore() term.setTextColour(colours.white) end
  58.  
  59. function fineSfondo() term.setBackgroundColour(colours.black) end
  60.  
  61. function titolo(testo)
  62.     drawFilledBox(1, 1, maxw, 1, colors.gray)
  63.     term.setCursorPos((maxw - #testo) / 2, 1)
  64.     colore(colors.white)
  65.     term.write(testo)
  66.     term.setCursorPos(1, 2)
  67.     sfondo(colors.white)
  68. end
  69.  
  70. function clear()
  71.     sfondo(colors.white)
  72.     term.clear()
  73.     term.setCursorPos(1, 1)
  74. end
  75.  
  76. function errore(errore)
  77.     sfondo(colors.red)
  78.     colore(colors.white)
  79.     term.clear()
  80.     term.setCursorPos(1, 1)
  81.     titolo("Errore irreversibile")
  82.     term.setCursorPos(1, 3)
  83.     sfondo(colors.red)
  84.     colore(colors.white)
  85.     term.write(errore)
  86.     print("\n\n\nAttendere qualche secondo...")
  87.     os.sleep(6)
  88.     os.reboot()
  89. end
  90.  
  91. function print_Page(message)
  92.  
  93.     if printer.getPaperLevel() == 0 then -- If there is no paper in the printer
  94.       errore("La carta nella stampante è finita!")
  95.     end
  96.    
  97.     if printer.getInkLevel() == 0 then -- If there is no ink in the printer
  98.       error("L'inchiostro nella stampante è finita!")
  99.     end
  100.    
  101.     -- There is paper and ink in the printer, we can now print a page
  102.    
  103.     if printer.newPage() then
  104.       printer.write("Ricevuta PNRF")
  105.      
  106.       printer.setCursorPos(1, 3)
  107.       printer.write("* Frequenza: "..message)
  108.  
  109.      
  110.       printer.setCursorPos(1, 8)
  111.       printer.write("Grazie per usare PNRF")
  112.  
  113.       printer.setPageTitle("PNRF - Ricevuta")
  114.       printer.endPage()
  115.     else
  116.       errore("Stampante inceppata!")
  117.     end
  118. end
  119.  
  120. function make_payment(player, amount)
  121.     clear()
  122.     titolo("PNFR HUB | Pagamento")
  123.     colore(colors.black)
  124.     term.setCursorPos(1,3)
  125.     print("Inserisce le credenziali nPay\nper comprare il pagamento\nPrezzo da pagare: "..amount.." IC")
  126.  
  127.     term.setCursorPos(1,7)
  128.     term.write("Nome utente:")
  129.     term.setCursorPos(1,9)
  130.     term.write("Password:")
  131.  
  132.     term.setCursorPos(14,7)
  133.     username = read()
  134.  
  135.     term.setCursorPos(11,9)
  136.     password = read("*")
  137.  
  138.     a = http.get("https://pnrf.rgbcraft.com/api/do/payments?player="..player.."&username="..username.."&password="..password.."&amount="..amount)
  139.     if a ~= nil and a ~= "" then
  140.         b = a.readAll()
  141.         c = textutils.unserialize(b)
  142.         a.close()
  143.  
  144.         if c['status'] == "OK" then
  145.             clear()
  146.             titolo("PNFR HUB | Pagamento completato")
  147.             sfondo(colors.white)
  148.             colore(colors.black)
  149.             testo = "Frequenza assegnata: "..c['frequency']
  150.             term.setCursorPos((maxw - #testo) / 2, 11)
  151.             term.write(testo)
  152.             print("\n         Stiamo stampando la ricevuta..")
  153.             os.sleep(1)
  154.             print_Page(c['frequency'])
  155.             os.sleep(8)
  156.             os.reboot()
  157.         else
  158.             errore(c['detail'])
  159.         end
  160.     else
  161.         errore("Server non raggiungibile")
  162.     end
  163.    
  164.     os.sleep(5)
  165.  
  166.  
  167. end
  168.  
  169. function new_frequency(player)
  170.     a = http.get("https://pnrf.rgbcraft.com/api/check/newfrequency?player="..player)
  171.     if a ~= nil and a ~= "" then
  172.         b = a.readAll()
  173.         c = textutils.unserialize(b)
  174.         a.close()
  175.  
  176.         if c['status'] == "OK" then
  177.             clear()
  178.             titolo("PNFR HUB | Nuova Frequenza")
  179.             colore(colors.black)
  180.             testo = "Clicca qualsiasi tasto per confermare"
  181.             testo2 = "dovrai pagare: "..c['price']
  182.             testo3 = "Al momento hai ".. c['frequency'].." frequenza/e"
  183.             term.setCursorPos((maxw - #testo) / 2, 10)
  184.             term.write(testo)
  185.             term.setCursorPos((maxw - #testo2) / 2, 11)
  186.             term.write(testo2)
  187.             term.setCursorPos((maxw - #testo3) / 2, 13)
  188.             term.write(testo3)
  189.             os.pullEvent("key")
  190.  
  191.             make_payment(player, c['price'])
  192.  
  193.         elseif c['status'] == "TMF" then
  194.             clear()
  195.             titolo("PNFR HUB | Nuova Frequenza")
  196.             colore(colors.black)
  197.             testo = "Hai troppe frequenze!!, contatatta legoz"
  198.             term.setCursorPos((maxw - #testo) / 2, 11)
  199.             term.write(testo)
  200.             os.sleep(5)
  201.             os.reboot()
  202.         else
  203.             os.reboot()
  204.         end
  205.     else
  206.         errore("Server non raggiungibile")
  207.     end
  208. end
  209.  
  210. function playerCheck(player)
  211.     a = http.get("https://pnrf.rgbcraft.com/api/checkplayer?player="..player)
  212.     if a ~= nil and a ~= "" then
  213.         b = a.readAll()
  214.         c = textutils.unserialize(b)
  215.         a.close()
  216.  
  217.         Gplayer = player
  218.         if c['status'] == "OK" then
  219.             clear()
  220.             titolo("PNFR HUB | Nuova Frequenza")
  221.             colore(colors.black)
  222.             testo = "Sei un nuovo utente!"
  223.             term.setCursorPos((maxw - #testo) / 2, 11)
  224.             term.write(testo)
  225.             os.sleep(1)
  226.             new_frequency(player)
  227.         elseif c['status'] == "NP" then
  228.             clear()
  229.             titolo("PNFR HUB | Nuova Frequenza")
  230.             colore(colors.black)
  231.             testo = "Utente già registrato.. ASPETTA!"
  232.             term.setCursorPos((maxw - #testo) / 2, 11)
  233.             term.write(testo)
  234.             os.sleep(1)
  235.             new_frequency(player)
  236.         else
  237.             os.reboot()
  238.         end
  239.     else
  240.         errore("Server non raggiungibile")
  241.     end
  242. end
  243.  
  244. function new_Frequence()
  245.     clear()
  246.     titolo("PNFR HUB | Nuova Frequenza")
  247.     colore(colors.black)
  248.     testo = "Clicca il sensore posto al lato/sotto"
  249.     term.setCursorPos((maxw - #testo) / 2, 11)
  250.     term.write(testo)
  251.  
  252.     os.startTimer(120)
  253.     local event, player = os.pullEvent()
  254.     if event == "player" then
  255.         playerCheck(player)
  256.     end
  257. end
  258.  
  259. function faq()
  260.     clear()
  261.     titolo("PNFR HUB | F.A.Q")
  262.     colore(colors.black)
  263.     testo = "Work In progress"
  264.     term.setCursorPos((maxw - #testo) / 2, 11)
  265.     term.write(testo)
  266.  
  267.  
  268.     drawFilledBox(43, 16, 48, 18, colors.red) -- FileBox (INFO)
  269.  
  270.     testo = "HOME"
  271.     term.setCursorPos(44, 17)
  272.     term.write(testo)
  273.  
  274.     os.startTimer(120)
  275.     while true do
  276.         local event, par1, par2, par3 = os.pullEventRaw()
  277.         if par2 >= 43 and par2 <= 48 and par3 >= 16 and par3 <= 18 and event == "mouse_click" then -- Home
  278.             os.reboot()
  279.         end
  280.     end
  281.  
  282. end
  283.  
  284.  
  285. function update()
  286.     if not fs.exists(".permaboot") then
  287.         local file fs.open(".permaboot", "w")
  288.         file.writeLine("Permaboooot")
  289.         file.close()
  290.         os.reboot()
  291.     end    
  292.     shell.run("rm startup")
  293.     shell.run("pastebin get sg8epUiQ star")
  294.     shell.run("star")
  295.     shell.run("mv star startup")
  296.  
  297. end
  298.  
  299. update()
  300.  
  301.  
  302. sfondo(colors.white)
  303. term.clear()
  304.  
  305.  
  306.  
  307. titolo("PNRF HUB")
  308.  
  309. -- 51X 19Y
  310. colore(colors.black)
  311. sfondo(colors.white)
  312.  
  313.  
  314. drawFilledBox(15, 11, 35, 13, colors.red) -- FileBox (Consegna Pacco)
  315.  
  316. testo = "Nuova Frequenza"
  317. term.setCursorPos((maxw - #testo) / 2, 12)
  318. term.write(testo)
  319.  
  320. --drawFilledBox(42, 16, 48, 18, colors.red) -- FileBox (FAQ)
  321.  
  322. --testo = "F.A.Q"
  323. --term.setCursorPos(43, 17)
  324. --term.write(testo)
  325.  
  326. colore(colors.black)
  327.  
  328. while true do
  329.     colore(colors.black)
  330.     local event, par1, par2, par3 = os.pullEventRaw()
  331.     if par2 >= 15 and par2 <= 35 and par3 >= 11 and par3 <= 13 and event == "mouse_click" then -- New Return
  332.         new_Frequence()
  333.         os.sleep(3)
  334.         os.reboot()
  335.     --[[
  336.     elseif par2 >= 42 and par2 <= 49 and par3 >= 16 and par3 <= 18 and event == "mouse_click"  then -- FAQ
  337.         faq()
  338.         os.reboot()
  339.     --]]    
  340.     end
  341. end
  342.  
  343. os.sleep(45)
  344. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement