Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Infiniwolf
- --Made by Wiiplay123
- debug = false
- function table_count(tt, item)
- local count
- count = 0
- for ii,xx in pairs(tt) do
- if item == xx then count = count + 1 end
- end
- return count
- end
- function table_unique(tt)
- local newtable
- newtable = {}
- for ii,xx in ipairs(tt) do
- if(table_count(newtable, xx) == 0) then
- newtable[#newtable+1] = xx
- end
- end
- return newtable
- end
- function printCenter(txt,line)
- term.setCursorPos(term.getSize()/2 - #txt/2,line)
- write(txt)
- end
- for i, v in pairs(peripheral.getNames()) do
- if (peripheral.getType(v) == "modem" and peripheral.call(v,"isWireless") == true) then
- _G.rednetside = v
- _G.modem = peripheral.wrap(v)
- rednet.open(v)
- break
- end
- end
- function updatesites()
- _G.sites = {}
- _G.servers = {}
- drives = 0
- for i, v in pairs(table_unique(peripheral.getNames())) do
- if peripheral.getType(v) == "drive" then
- drives = drives + 1
- if peripheral.call(v,"getMountPath") ~= nil then
- if fs.exists(peripheral.call(v,"getMountPath").."/servers") == true then
- table.insert(servers,peripheral.call(v,"getMountPath").."/servers")
- end
- end
- end
- end
- _G.sitepaths = {}
- _G.siteids = {}
- for i = 1, #servers do
- for b, o in pairs(fs.list(servers[i])) do
- table.insert(sites,o)
- table.insert(sitepaths,servers[i].."/"..o)
- table.insert(siteids,os.getComputerID() + (i - 1))
- end
- end
- term.clear()
- local x, y = term.getSize()
- if (debug == false) then
- if term.isColor() then
- term.setTextColor(colors.lime)
- end
- printCenter("Infiniwolf",1)
- if term.isColor() then
- term.setTextColor(colors.white)
- end
- printCenter("Hosting "..#sites.." sites.",y/2 - 1)
- printCenter("Using "..drives.." drives.",y/2 + 1)
- end
- end
- function checksites(site)
- updatesites()
- for i = 1, #sites do
- if string.find(site,sites[i]) then
- return sites[i], sitepaths[i], i
- end
- end
- return nil
- end
- function serve()
- updatesites()
- while true do
- id, msg = rednet.receive()
- thing, thing2, thing3 = checksites(msg)
- if msg == "firewolf.broadcast.dns.list" then
- updatesites()
- for i = 1, #sites do
- rednet.send(id,"firewolf-site:"..sites[i])
- end
- elseif thing ~= nil then
- if thing then
- if msg == thing then
- msg = msg.."/home"
- end
- local path = string.gsub(msg,thing,thing2)
- local page = fs.open(path,"r")
- if page ~= nil then
- rednet.send(id,page.readAll())
- page.close()
- end
- end
- end
- end
- end
- serve()
Advertisement
Add Comment
Please, Sign In to add comment