Wiiplay123

Infiniwolf

Aug 5th, 2013
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.33 KB | None | 0 0
  1. --Infiniwolf
  2. --Made by Wiiplay123
  3. debug = false
  4. function table_count(tt, item)
  5.   local count
  6.   count = 0
  7.   for ii,xx in pairs(tt) do
  8.     if item == xx then count = count + 1 end
  9.   end
  10.   return count
  11. end
  12. function table_unique(tt)
  13.   local newtable
  14.   newtable = {}
  15.   for ii,xx in ipairs(tt) do
  16.     if(table_count(newtable, xx) == 0) then
  17.       newtable[#newtable+1] = xx
  18.     end
  19.   end
  20.   return newtable
  21. end
  22. function printCenter(txt,line)
  23. term.setCursorPos(term.getSize()/2 - #txt/2,line)
  24. write(txt)
  25. end
  26. for i, v in pairs(peripheral.getNames()) do
  27. if (peripheral.getType(v) == "modem" and peripheral.call(v,"isWireless") == true) then
  28. _G.rednetside = v
  29. _G.modem = peripheral.wrap(v)
  30. rednet.open(v)
  31. break
  32. end
  33. end
  34. function updatesites()
  35. _G.sites = {}
  36. _G.servers = {}
  37. drives = 0
  38. for i, v in pairs(table_unique(peripheral.getNames())) do
  39. if peripheral.getType(v) == "drive" then
  40. drives = drives + 1
  41. if peripheral.call(v,"getMountPath") ~= nil then
  42. if fs.exists(peripheral.call(v,"getMountPath").."/servers") == true then
  43. table.insert(servers,peripheral.call(v,"getMountPath").."/servers")
  44. end
  45. end
  46. end
  47. end
  48. _G.sitepaths = {}
  49. _G.siteids = {}
  50. for i = 1, #servers do
  51. for b, o in pairs(fs.list(servers[i])) do
  52. table.insert(sites,o)
  53. table.insert(sitepaths,servers[i].."/"..o)
  54. table.insert(siteids,os.getComputerID() + (i - 1))
  55. end
  56. end
  57. term.clear()
  58. local x, y = term.getSize()
  59. if (debug == false) then
  60. if term.isColor() then
  61. term.setTextColor(colors.lime)
  62. end
  63. printCenter("Infiniwolf",1)
  64. if term.isColor() then
  65. term.setTextColor(colors.white)
  66. end
  67. printCenter("Hosting "..#sites.." sites.",y/2 - 1)
  68. printCenter("Using "..drives.." drives.",y/2 + 1)
  69. end
  70. end
  71. function checksites(site)
  72. updatesites()
  73. for i = 1, #sites do
  74. if string.find(site,sites[i]) then
  75. return sites[i], sitepaths[i], i
  76. end
  77. end
  78. return nil
  79. end
  80. function serve()
  81. updatesites()
  82. while true do
  83. id, msg = rednet.receive()
  84. thing, thing2, thing3 = checksites(msg)
  85. if msg == "firewolf.broadcast.dns.list" then
  86. updatesites()
  87. for i = 1, #sites do
  88. rednet.send(id,"firewolf-site:"..sites[i])
  89. end
  90. elseif thing ~= nil then
  91. if thing then
  92. if msg == thing then
  93. msg = msg.."/home"
  94. end
  95. local path = string.gsub(msg,thing,thing2)
  96. local page = fs.open(path,"r")
  97. if page ~= nil then
  98. rednet.send(id,page.readAll())
  99. page.close()
  100. end
  101. end
  102. end
  103. end
  104. end
  105. serve()
Advertisement
Add Comment
Please, Sign In to add comment