Stary2001

Untitled

Feb 9th, 2013
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. protocols.rdnt = {}
  2.  
  3. print("Loading list of firewolf sites..")
  4. local sites = {}
  5. rednet.broadcast("firewolf.broadcast.dns.list")
  6. while true do
  7. local sid, msg = rednet.receive(0.05)
  8. if sid and msg:sub(1, 14) == "firewolf-site:" then
  9. local surl = msg:sub(15, -1)
  10. table.insert(sites, {id = id, url = surl})
  11. else
  12. break
  13. end
  14. end
  15.  
  16. function getSite(location)
  17. for i=1,#sites do
  18. if location:sub(1,#(t[i].url)) == t[i].url then return t[i].id end
  19. end
  20.  
  21. error("huh")
  22. end
  23.  
  24. function convertToXML(content)
  25. local converted = "<xml>"
  26. local curTextColor
  27. local curBGColor
  28. local curColor=""
  29.  
  30. local t = {}
  31.  
  32. local myWrite =
  33. function (...)
  34. local args={...}
  35. if args[1]=="" then
  36. converted=converted.."<br/>"
  37. else
  38. converted=converted.."<p"..curColor..">" .. table.concat(args," ") .. "</p>"
  39. end
  40. end
  41.  
  42. t["centerPrint"] =
  43. function(...)
  44. converted = converted .. "<p "..curColor.." align=\"center\">" .. table.concat({...},"\t") .. "</p>"
  45. end
  46.  
  47. t["cPrint"]= t["centerPrint"]
  48.  
  49. t["term"] =
  50. {
  51. write = myWrite,
  52. setTextColor =
  53. function(col)
  54. curTextColor = col
  55. curColor = "color=\""..curTextColor.."\""
  56. if curBGColor then
  57. curColor = curColor .. "bgcolor=\""..curBGColor.."\""
  58. end
  59. end,
  60.  
  61. setBackgroundColor = function(col)
  62. curBGColor = col
  63. curColor = "bgcolor=\""..curBGColor.."\""
  64. if curTextColor then
  65. curColor = curColor .. "color=\""..curTextColor.."\""
  66. end
  67. end
  68. }
  69.  
  70. t["io"] = { write = myWrite }
  71.  
  72. t["print"] = myWrite
  73.  
  74. local fakeColors = {}
  75.  
  76. for k,v in pairs(colors) do
  77. fakeColors[k]=k
  78. end
  79. t["colors"] = fakeColors
  80. t["colours"] = fakeColors
  81.  
  82. local f = loadstring(content)
  83. setfenv(f,t)
  84. f()
  85.  
  86. converted=converted.."</xml>"
  87.  
  88. return converted
  89. end
  90.  
  91. function protocols.rdnt.get(location)
  92. rednet.send(getSite(location),location)
  93.  
  94. local timerID = os.startTimer(5)
  95.  
  96. while true do
  97. local _,id,content = os.pullEvent()
  98. if _ == "rednet_message" then
  99. return convertToXML(content)
  100. elseif event=="timer" and id == timerID then
  101. error("Server did not respond in five seconds. Exiting.")
  102. end
  103. end
  104. end
  105.  
  106. function protocols.rdnt.ping(location)
  107. rednet.send(getSite(location),location)
  108.  
  109. while true do
  110. local _,content = rednet.receive(5)
  111.  
  112. if not _ or not content then
  113. return false
  114. elseif _ == getSite(location) then
  115. return true
  116. end
  117. end
  118. end
Advertisement
Add Comment
Please, Sign In to add comment