Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Beware, horrible code lurks below, waiting to strike a carefree programmer.
- local d = false
- local mod = nil
- for k, v in pairs(peripheral.getNames()) do
- if peripheral.getType(v) == "modem" then
- rednet.open(v)
- mod = peripheral.wrap(v)
- d = true
- end
- end
- if not d or not mod then
- error("A modem is required!")
- end
- -- Some functions
- local dns_channel = 331
- local args = {...}
- local targ = tonumber(args[1]) or 0
- local rids = {}
- local function inTable_V(tab, _v)
- for k, v in pairs(tab) do
- if v == _v then
- return true
- end
- end
- return false
- end
- local function inTable_K(tab, _k)
- for k, v in pairs(tab) do
- if k == _k then
- return true
- end
- end
- return false
- end
- local function download_file(url, target)
- local ht = http.get(url)
- local data = ht.readAll()
- ht.close()
- local file = fs.open(target, "w")
- file.write(data)
- file.close()
- end
- local function read_file(target)
- local file = fs.open(target, "r")
- local data = file.readAll()
- file.close()
- return data
- end
- -- API Loading
- local function getAPI(name, url)
- local apiloc = "/" .. name
- if (not fs.exists(apiloc)) then
- local newapiloc = shell and shell.resolveProgram(name) or nil
- if type(newapiloc) ~= "string" then
- download_file(url, "/" .. name)
- else
- apiloc = newapiloc
- end
- end
- os.loadAPI(apiloc)
- if not _G[name] then
- error(name .. " failed to load!", 0)
- return
- end
- end
- getAPI("ringnet", "https://pastebin.com/raw/bnDHMbNx")
- ringnet.openChannel(32031)
- parallel.waitForAll(
- function()
- ringnet.connectionHandler(true)
- end,
- function()
- while true do
- local ev, from, data, dist = os.pullEvent("secure_receive")
- if (ev ~= nil) then
- if (type(data) ~= "table") then
- data = textutils.unserialize(tostring(data))
- end
- if not data then
- return
- end
- if data.type == "AMETHYSTDATA" then
- print(data.stuff)
- end
- end
- sleep(0)
- end
- end,
- function()
- ringnet.openTunnel(targ, 32031)
- local e, id = os.pullEventRaw("tunnel_finish")
- sleep(3)
- ringnet.sendData(
- id,
- textutils.serialize(
- {
- type = "AMETHYSTGET",
- path = "index"
- }
- )
- )
- end
- )
Advertisement
Add Comment
Please, Sign In to add comment