melzneni

TURTI_ResourceManager

Oct 17th, 2021 (edited)
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. rednet.open("top")
  2.  
  3. while true do
  4. local id, msg = rednet.receive()
  5. if msg.at == "resourceManager" then
  6. if msg.command[1] == "downloadFileById" then
  7. write("downloading '")
  8. write(msg.url)
  9. write("'... ")
  10. print(id)
  11. local answer = http.get(msg.url)
  12. if not answer then
  13. rednet.send(id, { at = "any", command = { "resourceManager", "resourceFailure" },
  14. resourceId = msg.resourceId })
  15. else
  16. rednet.send(id, { at = "any", command = { "resourceManager", "resourceSuccess" },
  17. resourceId = msg.resourceId,
  18. data = answer.readAll() })
  19. end
  20. answer.close()
  21. print("done")
  22. else
  23. print("unknownCommand: " .. msg.command[1])
  24. end
  25.  
  26. end
  27.  
  28. end
Add Comment
Please, Sign In to add comment