MrDionesalvi

ARC

May 15th, 2021 (edited)
1,011
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.25 KB | None | 0 0
  1. -- ARC by CFG
  2. -- Vietato l'abuso o BAN
  3.  
  4.  
  5. version = "3.1"
  6. response = {}
  7. local token = ""
  8. local time = 15
  9. local pos = nil
  10. local computer = "0"
  11.  
  12. lati = {"left", "right", "back", "top", "bottom", "front"}
  13.  
  14. for k,v in pairs(lati) do
  15.   if peripheral.getType(v) == "nuclearReader" then
  16.     lato = v
  17.     break
  18.   end
  19. end
  20.  
  21. pos = lato
  22.  
  23.  
  24. local function error()
  25.     term.clear()
  26.     term.write("ARC non raggiungibile\n\nRiavvio")
  27.     os.sleep(5)
  28.     os.reboot()
  29. end
  30.  
  31. local function check_version()
  32.     ris = http.get("http://192.168.13.101:53054/api/version/lua")
  33.     if ris ~= nil and ris ~= "" then
  34.         a = http.get("http://192.168.13.101:53054/api/version/lua").readAll()
  35.         b = textutils.unserialize(a)
  36.  
  37.         if b.version ~= version then
  38.             shell.run("rm startup")
  39.             shell.run("pastebin get Bh4svTNe startup")
  40.             shell.run("reboot")
  41.         end
  42.     else
  43.         error()
  44.     end
  45.     ris.close()
  46. end
  47.  
  48. local function first_inst()
  49.     if not fs.exists("token") then
  50.         random = math.random(0, 1000000)
  51.         value = "ARC"..tostring(random)
  52.         os.setComputerLabel(value)
  53.         term.clear()
  54.         term.setCursorPos(1,1)
  55.         print("Benvenuto nel sistema di installazione di ARC v1.0")
  56.         print("\n\n\nInesrisci il token che trovi sul sito: ")
  57.         a = read()
  58.  
  59.         local g = fs.open("token", fs.exists("token") and "a" or "w")
  60.         g.write(a)
  61.         g.close()
  62.         os.reboot()
  63.     else
  64.         local h = fs.open("token", "r")
  65.         token = h.readAll()
  66.         h.close()
  67.  
  68.         ris = http.get("http://192.168.13.101:53054/api/get/time?token="..token)
  69.         if ris ~= nil and ris ~= "" then
  70.             a = http.get("http://192.168.13.101:53054/api/get/time?token="..token).readAll()
  71.             b = textutils.unserialize(a)
  72.        
  73.             time = b["time"]
  74.         else
  75.             error()
  76.         end
  77.         ris.close()
  78.     end
  79. end
  80.  
  81. local function get_response()
  82.     ris = http.get("http://192.168.13.101:53054/api/get/switch?token="..token.."&computer="..computer)
  83.     if ris ~= nil and ris ~= "" then
  84.         a = http.get("http://192.168.13.101:53054/api/get/switch?token="..token.."&computer="..computer).readAll()
  85.         b = textutils.unserialize(a)
  86.  
  87.         if b.status == "Successo" then
  88.             response["left"] = b.left
  89.             response["right"] = b.right
  90.             response["top"] = b.top
  91.             response["bottom"] = b.bottom
  92.             response["front"] = b.front
  93.             response["back"] = b.back
  94.             redstone.setBundledOutput("left", response["left"])
  95.             redstone.setBundledOutput("right", response["right"])
  96.             redstone.setBundledOutput("top", response["top"])
  97.             redstone.setBundledOutput("bottom", response["bottom"])
  98.             redstone.setBundledOutput("front", response["front"])
  99.             redstone.setBundledOutput("back", response["back"])
  100.         else
  101.             term.clear()
  102.             term.setCursorPos(1,1)
  103.             print("Token errato")
  104.             fs.delete("token")
  105.             os.sleep(2)
  106.             os.reboot()
  107.         end
  108.     else
  109.         error()
  110.     end
  111.     ris.close()
  112.  
  113.     ris = http.get("http://192.168.13.101:53054/api/get/buttons")
  114.     if ris ~= nil and ris ~= "" then
  115.         a = http.get("http://192.168.13.101:53054/api/get/buttons?token="..token.."&computer="..computer).readAll()
  116.         b = textutils.unserialize(a)
  117.  
  118.        
  119.         if b.status == "Successo" then
  120.             response["left"] = b.left
  121.             response["right"] = b.right
  122.             response["top"] = b.top
  123.             response["bottom"] = b.bottom
  124.             response["front"] = b.front
  125.             response["back"] = b.back
  126.             redstone.setBundledOutput("left", response["left"])
  127.             redstone.setBundledOutput("right", response["right"])
  128.             redstone.setBundledOutput("top", response["top"])
  129.             redstone.setBundledOutput("bottom", response["bottom"])
  130.             redstone.setBundledOutput("front", response["front"])
  131.             redstone.setBundledOutput("back", response["back"])
  132.             os.sleep(0.5)
  133.             a = http.get("http://192.168.13.101:53054/api/get/buttons?token="..token.."&computer="..computer).readAll()
  134.             b = textutils.unserialize(a)
  135.             if b.status == "Successo" then
  136.                 response["left"] = b.left
  137.                 response["right"] = b.right
  138.                 response["top"] = b.top
  139.                 response["bottom"] = b.bottom
  140.                 response["front"] = b.front
  141.                 response["back"] = b.back
  142.                 redstone.setBundledOutput("left", response["left"])
  143.                 redstone.setBundledOutput("right", response["right"])
  144.                 redstone.setBundledOutput("top", response["top"])
  145.                 redstone.setBundledOutput("bottom", response["bottom"])
  146.                 redstone.setBundledOutput("front", response["front"])
  147.                 redstone.setBundledOutput("back", response["back"])
  148.             end
  149.         else
  150.             term.clear()
  151.             term.setCursorPos(1,1)
  152.             print("Token errato")
  153.             fs.delete("token")
  154.             os.sleep(2)
  155.             os.reboot()
  156.         end
  157.     else
  158.         error()
  159.     end
  160.     ris.close()
  161. end
  162.  
  163. local function send_api()
  164.     if pos ~= nil then
  165.         m = peripheral.wrap(pos)
  166.  
  167.         ris = http.get("http://192.168.13.101:53054/api/get/position?token="..token)
  168.         if ris ~= nil and ris ~= "" then
  169.             a = http.get("http://192.168.13.101:53054/api/get/position?token="..token).readAll()
  170.             b = textutils.unserialize(a)
  171.  
  172.             if peripheral.isPresent(pos) then
  173.                 if b.status == "Successo" then
  174.                     if b.counter ~= 0 then
  175.                         local a,b,c,info = m.get(b.counter)
  176.                         if b == "OK" then
  177.                             for system, status in pairs(info) do
  178.                                 status = tostring(status)
  179.                                 c = http.get("http://192.168.13.101:53054/api/post/data?token="..token.."&tp=counter&value="..status).readAll()
  180.                                 d = textutils.unserialize(c)
  181.                                 if d.status ~= "Successo" then
  182.                                     print("errore api")
  183.                                 end
  184.                             end
  185.                         else
  186.                             print("errore: nessuna card")
  187.                         end
  188.                     end
  189.  
  190.                     if b.shunt ~= 0 then
  191.                         local a,b,c,info = m.get(b.shunt)
  192.                         if b == "OK" then
  193.                             for system, status in pairs(info) do
  194.                                 status = tostring(status)
  195.                                 c = http.get("http://192.168.13.101:53054/api/post/data?token="..token.."&tp=shunt&value="..status).readAll()
  196.                                 d = textutils.unserialize(c)
  197.  
  198.                                 if d.status ~= "Successo" then
  199.                                     print("errore api")
  200.                                 end
  201.                             end
  202.                         else
  203.                             print("errore: nessuna card")
  204.                         end
  205.                     end
  206.                 end
  207.             else
  208.                 print("errore non hai nulla "..pos)
  209.             end
  210.         else
  211.             error()
  212.         end
  213.         ris.close()
  214.     end
  215.  
  216.     for k,v in pairs(lati) do
  217.         ris = http.get("http://192.168.13.101:53054/api/post/value")
  218.         if ris ~= nil and ris ~= "" then
  219.             value = redstone.getBundledInput(v)
  220.             c = http.get("http://192.168.13.101:53054/api/post/value?token="..token.."&side="..v.."&computer="..computer.."&value="..value).readAll()
  221.             d = textutils.unserialize(c)
  222.  
  223.             if d.status ~= "Successo" then
  224.                 print("errore api")
  225.             end
  226.         end
  227.         ris.close()
  228.     end
  229.      
  230. end
  231.  
  232. term.clear()
  233. term.write("ARC avviato")
  234.  
  235. check_version()
  236.  
  237. first_inst()
  238.  
  239. os.sleep(2)
  240.  
  241. first_inst()
  242.  
  243. i = 0
  244. while true do
  245.  
  246.     get_response()
  247.  
  248.  
  249.     if i == 2 then
  250.         send_api()
  251.         i = 0
  252.     end
  253.     i = i + 1
  254.  
  255.     os.sleep(time)
  256. end
Add Comment
Please, Sign In to add comment