Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- local server = tonumber(args[1])
- local oldColor = term.setTextColor
- if not term.isColor or not term.isColor() then
- term.setTextColor = function() return end
- end
- local function parseReturn(id, msg)
- --print(id..": "..msg)
- msg = textutils.unserialize(msg)
- if type(msg) == "table" then
- if msg[1] == "DB" then
- if msg[2] == "error" then
- term.setTextColor(colors.red)
- write("Server at ")
- term.setTextColor(colors.lightBlue)
- write(id)
- term.setTextColor(colors.red)
- write(" reports error: \"")
- term.setTextColor(colors.orange)
- print(msg[3].."\"")
- term.setTextColor(colors.white)
- elseif msg[2] == "successful" then
- term.setTextColor(colors.lime)
- write("Server at ")
- term.setTextColor(colors.lightBlue)
- write(id)
- term.setTextColor(colors.lime)
- print(" reports that the operation was successful.")
- term.setTextColor(colors.white)
- --[[elseif msg[2] == "clone" then
- local database = shell.dir().."/"..msg[3].."/"
- local files = msg[6]
- local allCommits = msg[5]
- local messages = msg[4]
- fs.makeDir(database.."commits/.metadata/")
- for file, commits in pairs(allCommits) do
- fs.makeDir(database.."commits/"..file)
- for commit, data in pairs(commits) do
- local fileHandle = fs.open(database.."commits/"..file.."/"..commit, "w")
- fileHandle.write(data)
- fileHandle.close()
- end
- end
- for file,v in pairs(messages) do
- fs.makeDir(database.."commits/.metadata/")
- for commit, data in ipairs(v) do
- local fileHandle = fs.open(database.."commits/.metadata/"..file.."/"..commit, "w")
- fileHandle.write(data)
- fileHandle.close()
- end
- end
- for i,v in pairs(files) do
- local fileHandle = fs.open(database..i, "w")
- fileHandle.write(v)
- fileHandle.close()
- end]]
- elseif msg[2] == "file" then
- local fileHandle = fs.open(shell.dir().."/"..msg[3], "w")
- fileHandle.write(msg[4])
- fileHandle.close()
- elseif msg[2] == "commit_data" then
- local fileHandle = fs.open(shell.dir().."/commits/"..msg[3].."/"..msg[4], "w")
- fileHandle.write(msg[5])
- fileHandle.close()
- if msg[6] then
- local msgHandle = fs.open(shell.dir().."/commits/.metadata/"..msg[3].."/"..msg[4], "w")
- msgHandle.write(msg[5])
- msgHandle.close()
- end
- elseif msg[2] == "commits" then
- local file = msg[4]
- for i,v in ipairs(msg[5]) do
- local handle = fs.open(shell.dir().."/commits/"..file.."/"..i, "w")
- handle.write(v[1])
- handle.close()
- if v[2] then
- local msgHandle = fs.open(shell.dir().."/commits/"..file.."/"..i, "w")
- msgHandle.write(v[2])
- msgHandle.close()
- end
- end
- elseif msg[2] == "files" then
- print("FILES: ")
- textutils.pagedTabulate(msg[3])
- elseif msg[2] == "goodbye" then
- term.setTextColor(colors.lime)
- print("You have logged out.")
- term.setTextColor(colors.white)
- end
- else
- return false
- end
- return true
- else
- return false
- end
- end
- local servArgs = {}
- for i=2, #args do
- table.insert(servArgs, args[i])
- end
- for i,v in ipairs(rs.getSides()) do
- if peripheral.getType(v) == "modem" then
- rednet.open(v)
- end
- end
- if servArgs[1] == "sendfile" then
- local handle = fs.open(servArgs[2], "r")
- local data = handle.readAll()
- handle.close()
- if servArgs[3] == nil then
- servArgs[3] = fs.getName(servArgs[2])
- end
- servArgs = {"commit", servArgs[3], data, servArgs[4]}
- end
- rednet.send(server, textutils.serialize(servArgs))
- local timer = os.startTimer(10)
- while true do
- local event, id, msg = os.pullEvent()
- if event == "timer" and id == timer then
- printError("remote server timed out")
- break
- elseif event == "rednet_message" then
- if parseReturn(id, msg) then
- break
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement