Advertisement
Techzune

File Server Storage

Jan 17th, 2012
900
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. --[[
  2. Program Name: File Server Storage
  3. Created By: Techzune
  4. Version: 1.0
  5. Description: Handles 4 disk drives for storage.
  6.  
  7. If using this script, please leave credit for the owner. Thank You!
  8. Operon Technologies - ComputerCraft and Lua
  9. --]]
  10.  
  11. --!!Use Back Port For 1.0!!--
  12.  
  13.  
  14. running = true
  15. computerid = os.computerID()
  16. compid = "FSS: ID" .. computerid
  17. compidlen = string.len(compid)
  18. incomingfile = false
  19. outgoingfile = false
  20.  
  21. function clear()
  22. term.clear()
  23. term.setCursorPos(1,1)
  24. print("File Server")
  25. print("ID: " .. computerid)
  26. print("------------------")
  27. print("")
  28. end
  29.  
  30. function receiveFile(usSide)
  31. incomingfile = true
  32. clear()
  33. compn, filen = rednet.receive(120)
  34. disk.setLabel(usSide, filen .. " Disk")
  35. mountPath = disk.getMountPath(usSide)
  36. label = mountPath .. "/" .. filen
  37. file = io.open(label, "w")
  38. print("Receiving File: " .. filen)
  39. while incomingfile == true do
  40. compn, line = rednet.receive(120)
  41. if line == compid .. "END" then
  42. print("End Of File")
  43. file:close()
  44. DataEvent()
  45. incomingfile = false
  46. else
  47. if line == nil then
  48. print("Error: nil Data")
  49. incomingfile = false
  50. file:close()
  51. DataEvent()
  52. else
  53. if line ~= " " then
  54. wril = string.sub(line, 2)
  55. else
  56. wril = line
  57. end
  58. print(wril)
  59. file:write(wril .. "\n")
  60. end
  61. end
  62. sleep(0)
  63. end
  64. end
  65. function DataEvent()
  66. rednet.open("back")
  67. --[[rednet.open("front")
  68. rednet.open("left")
  69. rednet.open("right")
  70. rednet.open("top")
  71. rednet.open("bottom")]]
  72. clear()
  73. local sEvent, cid, data = os.pullEvent()
  74. if sEvent == "rednet_message" then
  75. if data == compid then
  76. print(compid .. " SENT")
  77. sleep(1)
  78. rednet.broadcast("1")
  79. DataEvent()
  80. elseif data == compid .. " DCfront" or data == compid .. " DCback" or data == compid .. " DCtop" or data == compid .. " DCbottom" or data == compid .. " DCleft" or data == compid .. " DCright" then
  81. usSide = string.sub(data, compidlen + 4)
  82. sleep(1)
  83. if disk.isPresent(usSide) then
  84. rednet.broadcast("1")
  85. else
  86. rednet.broadcast("false")
  87. end
  88. DataEvent()
  89. elseif data == compid .. " Sfront" or data == compid .. " Sback" or data == compid .. " Stop" or data == compid .. " Sbottom" or data == compid .. " Sleft" or data == compid .. " Sright" then
  90. print("Receiving File...")
  91. usSide = string.sub(data, compidlen + 3)
  92. receiveFile(usSide)
  93. else
  94. DataEvent()
  95. end
  96. else
  97. DataEvent()
  98. end
  99. end
  100. DataEvent()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement