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 hostname = args[1] or "test.net"
- 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)
- -- The actual coroutines
- parallel.waitForAll(
- function()
- ringnet.connectionHandler(true)
- end,
- ringnet.pingHandler,
- 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 (type(data.type) == "string") then
- local path = fs.combine("/www", fs.combine("", tostring(data.path)):gsub("%.", ""))
- if (data.type == "AMETHYSTGET" and type(data.path) == "string" and fs.exists(path)) then
- local file = fs.open(path, "r")
- local stuff = file.readAll()
- file.close()
- sendData(
- from,
- get_frq(from),
- textutils.serialize(
- {
- type = "AMETHYSTDATA",
- data = stuff
- }
- )
- )
- end
- end
- end
- sleep(0)
- end
- end
- )
Advertisement
Add Comment
Please, Sign In to add comment