Advertisement
Esbenmine

CC Cloud Server

Aug 1st, 2014
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.77 KB | None | 0 0
  1. --Made by Esbenmine
  2. term.clear()
  3. term.setCursorPos(1,1)
  4. Start = true
  5. UP = false
  6. PP = false
  7. rednet.open("top")
  8. Start = function()
  9.   id, x = rednet.receive()
  10.   if x == "@Pass" then
  11.     id, Uname = rednet.receive()
  12.     id, Pass = rednet.receive()
  13.      Check = LoginCheck(Uname, Pass)
  14.      if Check == true then
  15.        rednet.send(id, "@CP")
  16.       print("User: ",Uname," logged in to Goggle Cloud")
  17.      elseif Check == false then
  18.       print("User: ",Uname," failed logging in to Goggle Cloud")
  19.        rednet.send(id, "@WP")
  20.      end
  21.   elseif x == "@Upload" then
  22.     id, Uname = rednet.receive()
  23.     id, Pass = rednet.receive()
  24.     id, File = rednet.receive()
  25.     Login = LoginCheck(Uname, Pass)
  26.     if Login == false then
  27.       rednet.send(id, "@WP")
  28.     else
  29.       if fs.exists("/"..Uname.."/"..File.."") then
  30.         rednet.send(id, "@File Exists")
  31.       else
  32.         rednet.send(id, "@StartUL")
  33.         ID, Message = rednet.receive()
  34.         if id == ID then
  35.           if Message == "@File Exists" then
  36.             id, FileLines = rednet.receive()
  37.             if id == ID then
  38.               file = fs.open("/"..Uname.."/"..File, "w")
  39.               file.write(FileLines)
  40.               file.close()
  41.               print("User: ",Uname," uploaded ",File," to his Goggle Cloud")
  42.             else
  43.               rednet.send(id, "Nothing here")
  44.             end
  45.           elseif Message == "@CancelUL" then
  46.           end
  47.         else
  48.           rednet.send(id, "You send a message to an wrong idea")
  49.         end
  50.       end
  51.     end
  52.   elseif x == "@Download" then
  53.     ID, Uname = rednet.receive()
  54.     ID2, Pass = rednet.receive()
  55.     ID3, FileName = rednet.receive()
  56.     if id == ID and ID2 == id and ID3 == id then
  57.       Login = LoginCheck(Uname, Pass)
  58.       if Login == true then
  59.         rednet.send(id, true)
  60.         if fs.exists("/"..Uname.."/"..FileName.."") then
  61.           rednet.send(id, "@File exists")
  62.           file = fs.open("/"..Uname.."/"..FileName.." ","r")
  63.           Lines = file.readAll()
  64.           rednet.send(id, Lines)
  65.           print("User: ",Uname," downloaded ",FileName," from his Goggle Cloud")
  66.           file.close()
  67.         else
  68.           rednet.send(id, "@File do not exists")
  69.         end
  70.       elseif Login == false then
  71.         rednet.send(id, false)
  72.       end
  73.     else
  74.       rednet.send(ID, "Wrong ID")
  75.     end
  76.   elseif x == "@List" then
  77.     ID, Uname = rednet.receive()
  78.     ID2, Pass = rednet.receive()
  79.     if id == ID and id == ID2 then
  80.       Login = LoginCheck(Uname, Pass)
  81.       if Login == true then
  82.         rednet.send(id, true)
  83.         files = fs.list("/"..Uname.."/")
  84.         rednet.send(id, files)
  85.       elseif Login == false then
  86.         rednet.send(id, false)
  87.       end
  88.     end
  89.   elseif x == "@Delete" then
  90.     ID, Uname = rednet.receive()
  91.     ID2, Pass = rednet.receive()
  92.     if id == ID and id == ID2 then
  93.       Login = LoginCheck(Uname,Pass)
  94.       if Login == true then
  95.         rednet.send(ID, true)
  96.         ID, FileName = rednet.receive()
  97.         if id == ID then
  98.           if fs.exists("/"..Uname.."/"..FileName.." ") then
  99.             rednet.send(ID, true)
  100.             fs.delete("/"..Uname.."/"..FileName.." ")
  101.           else
  102.             rednet.send(ID, false)
  103.           end
  104.         else
  105.           rednet.send(ID, "Wrong ID")
  106.         end
  107.       elseif Login == false then
  108.         rednet.send(ID, false)
  109.       end
  110.     else
  111.       rednet.send(ID, "Wrong ID")
  112.     end
  113.   else
  114.     rednet.send(id, "Wrong ID")
  115.   end
  116. end
  117.  
  118. LoginCheck = function(Username, Password)
  119.   file = fs.open("/Users/"..Username,"r")
  120.      if file then
  121.        if Password == file.readLine() then
  122.          return true
  123.        else
  124.          return false
  125.        end
  126.      else
  127.        return false
  128.     end
  129.      file.close()
  130. end
  131. repeat
  132.   Start()
  133. until Start == false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement