Advertisement
klindley

Untitled

Feb 28th, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.73 KB | None | 0 0
  1. --This is the preclient program that registers with the server and downloads the client
  2.  
  3. findDevice = function(t)
  4.     local sides = rs.getSides()
  5.     for k,v in pairs(sides) do
  6.         if peripheral.isPresent(v) then
  7.             if peripheral.getType(v) == t then
  8.                 return v
  9.             end
  10.         end
  11.     end
  12.     return "none"
  13. end
  14.  
  15. print("Computer ID:  "..os.getComputerID())
  16. rednet.open(findDevice("modem"))
  17. rednet.broadcast(textutils.serialize({cmd="HELO"}), "vcs")
  18.  
  19. while true do
  20.     local _, s, m, p = os.pullEvent("rednet_message")
  21.     print(m)
  22.     m = textutils.unserialize(m)
  23.     if m.cmd == "CLIENT" then
  24.         local f = fs.open(m.FileName, "w")
  25.         local s, m, p = rednet.receive()
  26.         f.write(m)
  27.         f.close()
  28.     elseif m.cmd == "DONE" then
  29.         os.reboot()
  30.     end
  31.        
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement