Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Program Name: File Server Storage
- Created By: Techzune
- Version: 1.0
- Description: Handles 4 disk drives for storage.
- If using this script, please leave credit for the owner. Thank You!
- Operon Technologies - ComputerCraft and Lua
- --]]
- --!!Use Back Port For 1.0!!--
- running = true
- computerid = os.computerID()
- compid = "FSS: ID" .. computerid
- compidlen = string.len(compid)
- incomingfile = false
- outgoingfile = false
- function clear()
- term.clear()
- term.setCursorPos(1,1)
- print("File Server")
- print("ID: " .. computerid)
- print("------------------")
- print("")
- end
- function receiveFile(usSide)
- incomingfile = true
- clear()
- compn, filen = rednet.receive(120)
- disk.setLabel(usSide, filen .. " Disk")
- mountPath = disk.getMountPath(usSide)
- label = mountPath .. "/" .. filen
- file = io.open(label, "w")
- print("Receiving File: " .. filen)
- while incomingfile == true do
- compn, line = rednet.receive(120)
- if line == compid .. "END" then
- print("End Of File")
- file:close()
- DataEvent()
- incomingfile = false
- else
- if line == nil then
- print("Error: nil Data")
- incomingfile = false
- file:close()
- DataEvent()
- else
- if line ~= " " then
- wril = string.sub(line, 2)
- else
- wril = line
- end
- print(wril)
- file:write(wril .. "\n")
- end
- end
- sleep(0)
- end
- end
- function DataEvent()
- rednet.open("back")
- --[[rednet.open("front")
- rednet.open("left")
- rednet.open("right")
- rednet.open("top")
- rednet.open("bottom")]]
- clear()
- local sEvent, cid, data = os.pullEvent()
- if sEvent == "rednet_message" then
- if data == compid then
- print(compid .. " SENT")
- sleep(1)
- rednet.broadcast("1")
- DataEvent()
- 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
- usSide = string.sub(data, compidlen + 4)
- sleep(1)
- if disk.isPresent(usSide) then
- rednet.broadcast("1")
- else
- rednet.broadcast("false")
- end
- DataEvent()
- 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
- print("Receiving File...")
- usSide = string.sub(data, compidlen + 3)
- receiveFile(usSide)
- else
- DataEvent()
- end
- else
- DataEvent()
- end
- end
- DataEvent()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement