Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ring = peripheral.find("stargate")
- mon = peripheral.find("monitor")
- ringList = {{"Close"}, {"Open"}}
- if fs.exists("ringList") then
- ringFile = fs.open("ringList", "r")
- ringList = textutils.unserialize(ringFile.readAll())
- end
- if ring then else
- print("Stargate not found!")
- error()
- end
- if mon then else
- monP = false
- end
- function checkForUpdates()
- while true do
- webFile = http.get("https://pastebin.com/raw/0ZQxxTxU")
- webFile = webFile.readAll()
- stF = fs.open("startup", "r").readAll()
- if stF ~= webFile then
- stF = fs.open("startup", "w")
- stF.write(webFile)
- stF.close()
- os.reboot()
- end
- sleep(0.001)
- end
- end
- function waitForIris(state)
- while true do
- if ring.irisState() == state then
- break
- end
- sleep(0.001)
- end
- end
- function waitForRing(state)
- while true do
- if ring.stargateState() == state then
- break
- end
- sleep(0.001)
- end
- end
- function dial(adrs)
- dialed = true
- ring.closeIris()
- waitForIris("Closed")
- ring.disconnect()
- waitForRing("Idle")
- ring.dial(adrs)
- waitForRing("Connected")
- ring.openIris()
- end
- function printToMon(t, x, y)
- if monP ~= false then
- mon.setCursorPos(x, y)
- mon.write(tostring(t))
- end
- end
- randAdrs = ""
- function randDial()
- while true do
- for i = string.len(randAdrs), 8 do
- if math.random(1, 2) == 1 then
- randAdrs = randAdrs .. string.char(math.random(48, 57))
- else
- randAdrs = randAdrs .. string.char(math.random(65, 90))
- end
- end
- if string.len(randAdrs) < 9 then
- print("Failed")
- else
- print("Trying "..randAdrs)
- ring.dial(randAdrs)
- randAdrs = ""
- end
- sleep(0.001)
- end
- end
- function monitor()
- if monP ~= false then
- while true do
- x, y = 3, 3
- length = 0
- for i,v in pairs(ringList) do
- printToMon(v[1], x + length, y)
- x = x + 3 + length
- length = string.len(v[1])
- z, t = mon.getSize()
- if x >= z then
- y = y + 2
- x = 3
- length = 0
- end
- end
- sleep(0.001)
- mon.clear()
- end
- end
- end
- dialed = false
- function main()
- while true do
- e, v, k, n = os.pullEvent("monitor_touch")
- l, m = 3, 3
- for i,v in pairs(ringList) do
- if l <= k and string.len(v[1]) + l - 1 >= k and m == n then
- if v[1] == "Close" then
- ring.closeIris()
- ring.disconnect()
- dialed = false
- elseif v[1] == "Open" then
- ring.openIris()
- dialed = false
- else
- dial(v[2])
- end
- end
- len = string.len(v[1])
- l = l + 3 + len
- end
- end
- end
- function saveRingList(file, list)
- ringFile = fs.open(file, "w")
- ringFile.write(textutils.serialize(list))
- ringFile.close()
- end
- function getId()
- while true do
- exists = true
- if dialed ~= true then
- ring.closeIris()
- waitForIris("Closed")
- end
- if ring.stargateState() == "Connected" then
- for i,v in pairs(ringList) do
- if v[2] == ring.remoteAddress() then
- exists = true
- end
- end
- if exists ~= true then
- ringInfo = {math.random(255), ring.remoteAddress()}
- table.insert(ringList, table.getn(ringList) - 1, ringInfo)
- saveRingList("ringList", ringList)
- end
- end
- sleep(0.001)
- end
- end
- parallel.waitForAll(getId, main, monitor, checkForUpdates)--, randDial)
Advertisement
Add Comment
Please, Sign In to add comment