Advertisement
ZNZNCOOP

MC

Dec 18th, 2014
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.49 KB | None | 0 0
  1. rednet.open('top')
  2. function reply(adress,data)
  3.    data= textutils.unserialize(data)
  4.    if (data[1] == 'pop') then
  5.       if (fs.exists(data[2]) == true) then
  6.          if (fs.isDir(data[2]) == true) then
  7.          list= fs.list(data[2])
  8.          for i=1,#list do
  9.             if (fs.isDir(data[2]..'/'..list[i]) == true) then
  10.                list[i]= 'Dir:'..list[i]
  11.             end
  12.          end
  13.             datas= createreply(adress,list,'pop','true')
  14.             sleep(1)
  15.             rednet.send(adress,datas)
  16.          else
  17.             datas= createreply(adress,nil,'pop','false')
  18.             sleep(1)
  19.             rednet.send(adress,datas)
  20.          end
  21.       else
  22.          datas= createreply(adress,nil,'pop','false')
  23.          sleep(1)
  24.          rednet.send(adress,datas)
  25.       end
  26.    end
  27. end
  28.  
  29. function draw(arr)
  30.    for i=1,#arr do
  31.       write(arr[i],' ')
  32.    end
  33. end
  34.  
  35. function createreply(adress,data,func,stat)
  36.    local datas= {}
  37.    datas= data
  38.    if (func == 'pop' and stat == 'true') then
  39.       table.insert(datas,1,stat)
  40.       table.insert(datas,2,'pop')
  41.       temp= textutils.serialize(datas)
  42.       return temp
  43.    elseif (func == 'pop' and stat == 'false') then
  44.       datas= {}
  45.       datas[1]= stat
  46.       datas[2]= 'pop'
  47.       temp= textutils.serialize(datas)
  48.       return temp
  49.    end
  50. end
  51. args= {...}
  52. if (args[1] == nil) then error() end
  53. MAIN_SERBER_ID= args[1]+0
  54. while true do
  55.    id,message= rednet.receive()
  56.    if (id == MAIN_SERBER_ID) then
  57.       reply(id,message)
  58.    end
  59. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement