Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- [[ CREATED BY ALAKAZARD12 ]] --
- --[[
- EDITTING THIS PROGRAM IN ANY WAY IS SCRITLY PROHIBITED
- CREDITS: ALAKAZARD12
- ]]
- ---------- [[ Script ]] ----------
- local stx, sty = term.getSize()
- function clear()
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(1)
- end
- function ports()
- rednet.open("back")
- rednet.open("top")
- rednet.open("front")
- rednet.open("bottom")
- rednet.open("left")
- rednet.open("right")
- end
- server = 0
- function scan(user, path, prog)
- local hasp = "/"
- for i,v in pairs(sep(path, "/")) do
- if not fs.exists("/files/"..tostring(user)..hasp..v) then
- if i == #sep(path, "/") and prog then
- if #prog > 100000 then
- print(path.." is to big!")
- else
- pcall(function()
- print("Creating \"/files/"..tostring(user)..hasp..v.."\"")
- local newf = fs.open("/files/"..tostring(user)..hasp..v, "w")
- newf.write(prog)
- end)
- end
- else
- print("Creating \"/files/"..tostring(user)..hasp..v.."\"")
- fs.makeDir("/files/"..tostring(user)..hasp..v)
- end
- end
- hasp = hasp..v.."/"
- end
- end
- function sep(list, by)
- local newlist = {}
- while true do
- local on = nil
- local done = false
- for i = 1, #list do
- if done == false then
- if string.sub(list, i, i) == by then
- on = i
- done = true
- end
- end
- end
- if on then
- table.insert(newlist, string.sub(list, 1, on - 1))
- list = string.sub(list, on + 1)
- else
- break
- end
- end
- table.insert(newlist, list)
- return newlist
- end
- function rec()
- if not fs.exists("/files") then
- fs.makeDir("/files")
- end
- local id, msg = rednet.receive()
- pcall(function()
- msg = textutils.unserialize(msg)
- end)
- if id == server then
- local hasp = "/"
- for i,v in pairs(sep(msg[1], "/")) do
- if not fs.exists("/files"..hasp..v) then
- if i == #sep(msg[1], "/") and msg[2] then
- if #msg[1] > 100000 then
- print(msg[1].." is to big!")
- else
- print("Creating \"/files"..hasp..v.."\"")
- local newf = fs.open("/files"..hasp..v, "w")
- newf.write(msg[1])
- end
- else
- print("Creating \"/files"..hasp..v.."\"")
- fs.makeDir("/files"..hasp..v)
- end
- end
- hasp = hasp..v.."/"
- end
- end
- rec()
- end
- function send(path)
- sleep(0.05)
- if fs.isDir(path) then
- print("Sending "..path)
- rednet.send(server, textutils.serialize({"CLOUD:UP:"..path}))
- for i,v in pairs(fs.list(path)) do
- send(path.."/"..v)
- end
- else
- print("Sending "..path)
- pcall(function()
- local fl = fs.open(path, "r")
- local rd = fl.readAll()
- fl.close()
- rednet.send(server, textutils.serialize({"CLOUD:UP:"..path, rd}))
- end)
- end
- end
- function drawlist(title, listr, num)
- clear()
- term.setTextColor(colors.lime)
- local list = {}
- print(title.."\n")
- for i,v in pairs(listr) do
- list[i] = v
- end
- local start = 1
- local last = #list
- if num > sty - 4 then
- start = num - (sty - 4)
- end
- local cnt = 0
- for i = start, #list do
- if cnt > sty - 4 then
- last = last - 1
- cnt = cnt - 1
- end
- cnt = cnt + 1
- end
- for m = start, last do
- local tor = true
- if tor == true then
- if m == num then
- term.setTextColor(colors.white)
- write("[")
- term.setTextColor(colors.lime)
- write("-")
- term.setTextColor(colors.white)
- write("]")
- term.setTextColor(colors.lime)
- print(" "..list[m])
- else
- term.setTextColor(colors.white)
- print("[ ] "..list[m])
- end
- end
- end
- end
- function getKey()
- local rt = nil
- function lop()
- local e, a1 = os.pullEvent("key")
- if a1 == 200 then
- rt = "up"
- elseif a1 == 208 then
- rt = "down"
- elseif a1 == 28 then
- rt = "enter"
- else
- lop()
- end
- end
- lop()
- repeat sleep(0) until rt ~= nil
- return rt
- end
- function ch(title, list)
- clear()
- local ind = 1
- drawlist(title, list, ind)
- local rt = nil
- cycle = function()
- local ke = getKey()
- if ke == "up" then
- if ind > 1 then
- ind = ind - 1
- else
- ind = #list
- end
- drawlist(title, list, ind)
- cycle()
- elseif ke == "down" then
- if ind < #list then
- ind = ind + 1
- else
- ind = 1
- end
- drawlist(title, list, ind)
- cycle()
- elseif ke == "enter" then
- rt = ind
- end
- end
- cycle()
- repeat sleep(0) until rt ~= nil
- return ind
- end
- function main()
- ports()
- clear()
- local ont = ch("What would you like to do?", {"Upload files", "Download files"})
- clear()
- write("Server ID: ")
- server = tonumber(read())
- if ont == 1 then
- write("Path to file: ")
- local tof = read()
- if fs.exists(tof) then
- send(tof)
- else
- print("File does not exist!")
- end
- elseif ont == 2 then
- print("Requesting files...")
- rednet.send(server, textutils.serialize({"CLOUD:REC:/"}))
- rec()
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement