Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protocols.rdnt = {}
- print("Loading list of firewolf sites..")
- local sites = {}
- rednet.broadcast("firewolf.broadcast.dns.list")
- while true do
- local sid, msg = rednet.receive(0.05)
- if sid and msg:sub(1, 14) == "firewolf-site:" then
- local surl = msg:sub(15, -1)
- table.insert(sites, {id = id, url = surl})
- else
- break
- end
- end
- function getSite(location)
- for i=1,#sites do
- if location:sub(1,#(t[i].url)) == t[i].url then return t[i].id end
- end
- error("huh")
- end
- function convertToXML(content)
- local converted = "<xml>"
- local curTextColor
- local curBGColor
- local curColor=""
- local t = {}
- local myWrite =
- function (...)
- local args={...}
- if args[1]=="" then
- converted=converted.."<br/>"
- else
- converted=converted.."<p"..curColor..">" .. table.concat(args," ") .. "</p>"
- end
- end
- t["centerPrint"] =
- function(...)
- converted = converted .. "<p "..curColor.." align=\"center\">" .. table.concat({...},"\t") .. "</p>"
- end
- t["cPrint"]= t["centerPrint"]
- t["term"] =
- {
- write = myWrite,
- setTextColor =
- function(col)
- curTextColor = col
- curColor = "color=\""..curTextColor.."\""
- if curBGColor then
- curColor = curColor .. "bgcolor=\""..curBGColor.."\""
- end
- end,
- setBackgroundColor = function(col)
- curBGColor = col
- curColor = "bgcolor=\""..curBGColor.."\""
- if curTextColor then
- curColor = curColor .. "color=\""..curTextColor.."\""
- end
- end
- }
- t["io"] = { write = myWrite }
- t["print"] = myWrite
- local fakeColors = {}
- for k,v in pairs(colors) do
- fakeColors[k]=k
- end
- t["colors"] = fakeColors
- t["colours"] = fakeColors
- local f = loadstring(content)
- setfenv(f,t)
- f()
- converted=converted.."</xml>"
- return converted
- end
- function protocols.rdnt.get(location)
- rednet.send(getSite(location),location)
- local timerID = os.startTimer(5)
- while true do
- local _,id,content = os.pullEvent()
- if _ == "rednet_message" then
- return convertToXML(content)
- elseif event=="timer" and id == timerID then
- error("Server did not respond in five seconds. Exiting.")
- end
- end
- end
- function protocols.rdnt.ping(location)
- rednet.send(getSite(location),location)
- while true do
- local _,content = rednet.receive(5)
- if not _ or not content then
- return false
- elseif _ == getSite(location) then
- return true
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment