Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ARC by CFG
- -- Vietato l'abuso o BAN
- version = "3.1"
- response = {}
- local token = ""
- local time = 15
- local pos = nil
- local computer = "0"
- lati = {"left", "right", "back", "top", "bottom", "front"}
- for k,v in pairs(lati) do
- if peripheral.getType(v) == "nuclearReader" then
- lato = v
- break
- end
- end
- pos = lato
- local function error()
- term.clear()
- term.write("ARC non raggiungibile\n\nRiavvio")
- os.sleep(5)
- os.reboot()
- end
- local function check_version()
- ris = http.get("http://192.168.13.101:53054/api/version/lua")
- if ris ~= nil and ris ~= "" then
- a = http.get("http://192.168.13.101:53054/api/version/lua").readAll()
- b = textutils.unserialize(a)
- if b.version ~= version then
- shell.run("rm startup")
- shell.run("pastebin get Bh4svTNe startup")
- shell.run("reboot")
- end
- else
- error()
- end
- ris.close()
- end
- local function first_inst()
- if not fs.exists("token") then
- random = math.random(0, 1000000)
- value = "ARC"..tostring(random)
- os.setComputerLabel(value)
- term.clear()
- term.setCursorPos(1,1)
- print("Benvenuto nel sistema di installazione di ARC v1.0")
- print("\n\n\nInesrisci il token che trovi sul sito: ")
- a = read()
- local g = fs.open("token", fs.exists("token") and "a" or "w")
- g.write(a)
- g.close()
- os.reboot()
- else
- local h = fs.open("token", "r")
- token = h.readAll()
- h.close()
- ris = http.get("http://192.168.13.101:53054/api/get/time?token="..token)
- if ris ~= nil and ris ~= "" then
- a = http.get("http://192.168.13.101:53054/api/get/time?token="..token).readAll()
- b = textutils.unserialize(a)
- time = b["time"]
- else
- error()
- end
- ris.close()
- end
- end
- local function get_response()
- ris = http.get("http://192.168.13.101:53054/api/get/switch?token="..token.."&computer="..computer)
- if ris ~= nil and ris ~= "" then
- a = http.get("http://192.168.13.101:53054/api/get/switch?token="..token.."&computer="..computer).readAll()
- b = textutils.unserialize(a)
- if b.status == "Successo" then
- response["left"] = b.left
- response["right"] = b.right
- response["top"] = b.top
- response["bottom"] = b.bottom
- response["front"] = b.front
- response["back"] = b.back
- redstone.setBundledOutput("left", response["left"])
- redstone.setBundledOutput("right", response["right"])
- redstone.setBundledOutput("top", response["top"])
- redstone.setBundledOutput("bottom", response["bottom"])
- redstone.setBundledOutput("front", response["front"])
- redstone.setBundledOutput("back", response["back"])
- else
- term.clear()
- term.setCursorPos(1,1)
- print("Token errato")
- fs.delete("token")
- os.sleep(2)
- os.reboot()
- end
- else
- error()
- end
- ris.close()
- ris = http.get("http://192.168.13.101:53054/api/get/buttons")
- if ris ~= nil and ris ~= "" then
- a = http.get("http://192.168.13.101:53054/api/get/buttons?token="..token.."&computer="..computer).readAll()
- b = textutils.unserialize(a)
- if b.status == "Successo" then
- response["left"] = b.left
- response["right"] = b.right
- response["top"] = b.top
- response["bottom"] = b.bottom
- response["front"] = b.front
- response["back"] = b.back
- redstone.setBundledOutput("left", response["left"])
- redstone.setBundledOutput("right", response["right"])
- redstone.setBundledOutput("top", response["top"])
- redstone.setBundledOutput("bottom", response["bottom"])
- redstone.setBundledOutput("front", response["front"])
- redstone.setBundledOutput("back", response["back"])
- os.sleep(0.5)
- a = http.get("http://192.168.13.101:53054/api/get/buttons?token="..token.."&computer="..computer).readAll()
- b = textutils.unserialize(a)
- if b.status == "Successo" then
- response["left"] = b.left
- response["right"] = b.right
- response["top"] = b.top
- response["bottom"] = b.bottom
- response["front"] = b.front
- response["back"] = b.back
- redstone.setBundledOutput("left", response["left"])
- redstone.setBundledOutput("right", response["right"])
- redstone.setBundledOutput("top", response["top"])
- redstone.setBundledOutput("bottom", response["bottom"])
- redstone.setBundledOutput("front", response["front"])
- redstone.setBundledOutput("back", response["back"])
- end
- else
- term.clear()
- term.setCursorPos(1,1)
- print("Token errato")
- fs.delete("token")
- os.sleep(2)
- os.reboot()
- end
- else
- error()
- end
- ris.close()
- end
- local function send_api()
- if pos ~= nil then
- m = peripheral.wrap(pos)
- ris = http.get("http://192.168.13.101:53054/api/get/position?token="..token)
- if ris ~= nil and ris ~= "" then
- a = http.get("http://192.168.13.101:53054/api/get/position?token="..token).readAll()
- b = textutils.unserialize(a)
- if peripheral.isPresent(pos) then
- if b.status == "Successo" then
- if b.counter ~= 0 then
- local a,b,c,info = m.get(b.counter)
- if b == "OK" then
- for system, status in pairs(info) do
- status = tostring(status)
- c = http.get("http://192.168.13.101:53054/api/post/data?token="..token.."&tp=counter&value="..status).readAll()
- d = textutils.unserialize(c)
- if d.status ~= "Successo" then
- print("errore api")
- end
- end
- else
- print("errore: nessuna card")
- end
- end
- if b.shunt ~= 0 then
- local a,b,c,info = m.get(b.shunt)
- if b == "OK" then
- for system, status in pairs(info) do
- status = tostring(status)
- c = http.get("http://192.168.13.101:53054/api/post/data?token="..token.."&tp=shunt&value="..status).readAll()
- d = textutils.unserialize(c)
- if d.status ~= "Successo" then
- print("errore api")
- end
- end
- else
- print("errore: nessuna card")
- end
- end
- end
- else
- print("errore non hai nulla "..pos)
- end
- else
- error()
- end
- ris.close()
- end
- for k,v in pairs(lati) do
- ris = http.get("http://192.168.13.101:53054/api/post/value")
- if ris ~= nil and ris ~= "" then
- value = redstone.getBundledInput(v)
- c = http.get("http://192.168.13.101:53054/api/post/value?token="..token.."&side="..v.."&computer="..computer.."&value="..value).readAll()
- d = textutils.unserialize(c)
- if d.status ~= "Successo" then
- print("errore api")
- end
- end
- ris.close()
- end
- end
- term.clear()
- term.write("ARC avviato")
- check_version()
- first_inst()
- os.sleep(2)
- first_inst()
- i = 0
- while true do
- get_response()
- if i == 2 then
- send_api()
- i = 0
- end
- i = i + 1
- os.sleep(time)
- end
Add Comment
Please, Sign In to add comment