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 ]] ----------
- 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
- 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()
- local id, msg = rednet.receive()
- pcall(function()
- msg = textutils.unserialize(msg)
- end)
- local type = nil
- if string.sub(msg[1], 1, 6) == "CLOUD:" then
- if string.sub(msg[1], 7, 10) == "REC:" then
- return id, string.sub(msg[1], 11), nil, 2
- elseif string.sub(msg[1], 7, 9) == "UP:" then
- local prog = nil
- if msg[2] then
- prog = msg[2]
- end
- return id, string.sub(msg[1], 10), prog, 1
- else
- return nil
- end
- else
- return nil
- end
- end
- function checkf()
- if not fs.exists("/files") then
- print("Creating \"/files\"")
- fs.makeDir("/files")
- end
- end
- 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 rem(pth, rrats)
- local found = 0
- for i = 1, #pth do
- if string.sub(pth, 1, i) == rrats then
- pth = string.sub(pth, i+2)
- break
- end
- end
- return pth
- end
- function send(path, id)
- sleep(0.05)
- path = resolve2(path)
- path = resolve(path)
- local remedpath = rem(path, "files/"..tostring(id))
- if fs.isDir(path) then
- print("Sending "..remedpath)
- rednet.send(id, textutils.serialize({remedpath}))
- for i,v in pairs(fs.list(path)) do
- send(path.."/"..v, id)
- end
- else
- print("Sending "..remedpath)
- local fl = fs.open(path, "r")
- local rd = fl.readAll()
- fl.close()
- rednet.send(id, textutils.serialize({remedpath, rd}))
- print("Sent "..remedpath)
- end
- end
- function resolve( path )
- for i = 1, #path do
- if string.sub(path, 1 ,1) == "/" then
- path = string.sub(path, 2)
- end
- end
- return path
- end
- function resolve2( path )
- for i = 1, #path do
- if string.sub(path,#path, #path) == "/" then
- path = string.sub(path, 1, #path-1)
- end
- end
- return path
- end
- function loop()
- local id, files, prog, type = rec()
- if id and files then
- if not fs.exists("/files/"..tostring(id)) then
- fs.makeDir("/files/"..tostring(id))
- end
- if type == 1 then
- if not prog then
- scan(id, files)
- else
- scan(id, files, prog)
- end
- elseif type == 2 then
- local path = "/files/"..tostring(id).."/"..resolve(files)
- if fs.exists(path) then
- print("Requested: "..path)
- send(path, id)
- else
- print(path.." does not exist!")
- end
- end
- end
- loop()
- end
- function main()
- clear()
- print("Cloud server running on "..os.getComputerID())
- ports()
- checkf()
- loop()
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement