Guest User

Untitled

a guest
Sep 30th, 2012
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. pass = ""
  2. function call()
  3. local dg = string.format("%s $", "call")
  4. rednet.broadcast(dg)
  5. id, msg = rednet.receive(10)
  6. if msg then
  7. cmd, etc = msg:match("^(%S*) (.*)")
  8. if cmd == "call" then
  9. rednet.send(id, "call")
  10. return id
  11. end
  12. end
  13. end
  14.  
  15. function open(timeout)
  16. if timeout >= 100 then
  17. error("Timeout too high")
  18. else
  19. for k, v in pairs(rs.getSides()) do
  20. rednet.open(v)
  21. end
  22. os.startTimer(timeout)
  23. while true do
  24. event, p1, p2 = os.pullEvent()
  25. if event == "rednet_message" then
  26. -- p1 = id
  27. -- p2 = msg
  28. if p2 then
  29. cmd, etc = p2:match("^(%S*) (.*)")
  30. if cmd == "view" then
  31. local val = fs.list("/")
  32. local _val = textutils.serialize(val)
  33. local dg = string.format("%s %s", "view", _val)
  34. rednet.send(p1, dg)
  35. elseif cmd == "transfer" then
  36. local file = fs.open(etc, "r")
  37. local dg = string.format("%s %s", "transfer", file.readAll())
  38. file.close()
  39. rednet.send(p1, dg)
  40. elseif cmd == "call" then
  41. local dg = string.format("%s $", "call")
  42. rednet.send(p1, dg)
  43. end
  44. end
  45. elseif event == "timer" then
  46. break
  47. end
  48. end
  49. end
  50. end
  51.  
  52. function view(id)
  53. local dg = string.format("%s $", "view")
  54. rednet.send(id, dg)
  55. id, msg = rednet.receive(10)
  56. if msg then
  57. cmd, etc = msg:match("^(%S*) (.*)")
  58. if cmd == "view" then
  59. tbl = textutils.unserialize(etc)
  60. return tbl
  61. end
  62. end
  63. end
  64.  
  65. function transfer(id, file)
  66. local dg = string.format("%s %s", "transfer", file)
  67. rednet.send(id, dg)
  68. id, msg = rednet.receive(10)
  69. if msg then
  70. cmd, etc = msg:match("^(%S*) (.*)")
  71. if cmd == "transfer" then
  72. if fs.exists(file) then
  73. return false
  74. else
  75. hFile = fs.open(file, "w")
  76. hFile.write(etc)
  77. hFile.close()
  78. return true
  79. end
  80. end
  81. end
  82. end
  83.  
  84. function setPassword(password)
  85. pass = textutils.serialize({password = password})
  86. if pass then
  87. return true
  88. else
  89. return false
  90. end
  91. end
  92.  
  93. function getPassword()
  94. h = (textutils.unserialize(pass))
  95. if h then
  96. return h.password
  97. else
  98. return false
  99. end
  100. end
Advertisement
Add Comment
Please, Sign In to add comment