Advertisement
Esbenmine

CC Cloud

Aug 1st, 2014
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.36 KB | None | 0 0
  1. --Made by Esbenmine
  2. term.clear()
  3. term.setCursorPos(1,1)
  4. ServerID = 1
  5. Start = true
  6. xPos, yPos = term.getSize()
  7. term.setBackgroundColor(colors.white)
  8. term.setTextColor(colors.blue)
  9. term.clear()
  10. rednet.open("top")
  11. Menu = function()
  12.   term.clear()
  13.   term.setCursorPos(1,1)
  14.   print("Type 'help'")
  15.   repeat
  16.     term.setCursorPos(1,1)
  17.     print("Type 'help'")
  18.     term.setCursorPos(1,yPos)
  19.     command = read()
  20.     if command:upper() == "UPLOAD" then
  21.       term.setCursorPos(1, yPos-1)
  22.       print("Enter filename")
  23.       term.setCursorPos(1, yPos)
  24.       FileName = read()
  25.       rednet.send(ServerID, "@Upload")
  26.       rednet.send(ServerID, Uname)
  27.       rednet.send(ServerID, Pass)
  28.       rednet.send(ServerID, FileName)
  29.       id, Message = rednet.receive()
  30.       if id == ServerID then
  31.         if Message == "@File Exists" then
  32.           term.setCursorPos(1,(yPos-1))
  33.           print("File already exists.")
  34.         elseif Message == "@WP" then
  35.           term.clear()
  36.           term.setCursorPos((xPos/2 - #"You are not logged in."),(yPos/2))
  37.           print("You are not logged in.")
  38.           os.reboot()
  39.         elseif Message == "@StartUL" then
  40.           if fs.exists(FileName) then
  41.             rednet.send(ServerID, "@File Exists")
  42.             file = fs.open(FileName,"r")
  43.             FileLines = file.readAll()
  44.             rednet.send(ServerID,FileLines)
  45.             file.close()
  46.           else
  47.             rednet.send(ServerID, "@CancelUL")
  48.             term.setCursorPos(1,(yPos-1))
  49.             print("File do not exists on your computer.")
  50.           end
  51.         end
  52.       end  
  53.     elseif command:upper() == "HELP" then
  54.       term.setCursorPos(1,(yPos-1))
  55.       print("'Upload' / 'Ul'  Upload file to Goggle Cloud.")
  56.       term.setCursorPos(1,(yPos-2))
  57.       print("'Download' Download file from Goggle Cloud.")
  58.       term.setCursorPos(1,(yPos-3))
  59.       print("'ls' / 'list' List of your Goggle Cloud files.")
  60.       term.setCursorPos(1,(yPos-4))
  61.       print("'rm' / 'remove' Remove a file from your Goggle Cloud.")
  62.     elseif command:upper() == "DOWNLOAD" then
  63.       term.setCursorPos(1,(yPos-1))
  64.       print("File to download: ")
  65.       term.setCursorPos(1,yPos)
  66.       FileName = read()
  67.       if fs.exists(FileName) then
  68.         term.setCursorPos(1,(yPos-1))
  69.         print("File already exists on your computer.")
  70.       else
  71.         rednet.send(ServerID, "@Download")
  72.         rednet.send(ServerID, Uname)
  73.         rednet.send(ServerID, Pass)
  74.         rednet.send(ServerID, FileName)
  75.         id, Continue = rednet.receive()
  76.         if id == ServerID then
  77.           if Continue == true then
  78.             id, Message = rednet.receive()
  79.             if id == ServerID then
  80.               if Message == "@File exists" then
  81.                 id, Lines = rednet.receive()
  82.                 if id == ServerID then
  83.                   file = fs.open(FileName,"w")
  84.                   file.write(Lines)
  85.                   file.close()
  86.                   term.setCursorPos(1,(yPos-1))
  87.                   print(FileName," downloaded sucessful.")
  88.                 else
  89.                   rednet.send(id, "Wrong ID")  
  90.                 end
  91.               elseif Message == "@File do not exists" then
  92.                 term.setCursorPos(1,(yPos-1))
  93.                 print("File do not exists.")
  94.               end
  95.             end
  96.           elseif Continue == false then
  97.             term.setCursorPos(1,yPos)
  98.             print("You are not logged in.")
  99.           end
  100.         else
  101.           rednet.send(id, "Wrong ID")
  102.         end
  103.       end
  104.     elseif command:upper() == "LS" or command:upper() == "LIST" then
  105.       rednet.send(ServerID, "@List")
  106.       rednet.send(ServerID, Uname)
  107.       rednet.send(ServerID, Pass)
  108.       id, Login = rednet.receive()
  109.       if id == ServerID then
  110.         if Login == true then
  111.           id, Files = rednet.receive()
  112.           if id == ServerID then
  113.             term.setCursorPos(1,(yPos-1-table.getn(Files)))
  114.             print("You have ",table.getn(Files)," file(s) in Goggle Cloud.")
  115.             for i = 1, table.getn(Files) do
  116.               term.setCursorPos(1,(yPos-i))
  117.               print(Files[i],"      ")
  118.             end
  119.           else
  120.             rednet.send(id, "Wrong ID")
  121.           end
  122.         else
  123.           term.setCursorPos(1,(yPos-1))
  124.           print("You are not logged in.")
  125.         end
  126.       end
  127.     elseif command:upper() == "DELETE" or command:upper() == "RM" then
  128.       term.setCursorPos(1,(yPos-1))
  129.       print("File to delete: ")
  130.       FileName = read()
  131.       rednet.send(ServerID, "@Delete")
  132.       rednet.send(ServerID, Uname)
  133.       rednet.send(ServerID, Pass)
  134.       id, Login = rednet.receive()
  135.       if id == ServerID then
  136.         if Login == true then
  137.           rednet.send(ServerID, FileName)
  138.           id, Exists = rednet.receive()
  139.           if id == ServerID then
  140.             if Exists == true then
  141.               term.setCursorPos(1,(yPos-1))
  142.               print(FileName," deleted sucessful.")
  143.             elseif Exists == false then
  144.               term.setCursorPos(1,(yPos-1))
  145.               print("File do not exists.")
  146.             end
  147.           else
  148.             rednet.send(id, "Wrong ID")
  149.           end
  150.         elseif Login == false then
  151.           term.setCursorPos(1,(yPos-1))
  152.           print("You are not logged in.")
  153.         end
  154.       else
  155.         rednet.send(id, "Wrong ID")          
  156.       end            
  157.     end
  158.   until Start == false
  159. end
  160. Login = function()
  161.   repeat
  162.     term.clear()
  163.     term.setCursorPos((xPos/2 - #"-----------"/2),2)
  164.     print("-----------")
  165.     term.setCursorPos((xPos/2 - #"{Google Cloud}"/2),3)
  166.     print("{Goggle Cloud}")
  167.     term.setCursorPos((xPos/2 - #"-----------"/2),4)
  168.     print("-----------")
  169.     term.setCursorPos((xPos/2 - #"Username:"/2),7)
  170.     write("Username: ")
  171.     term.setCursorPos((xPos/2 - #"Password:"/2),8)
  172.     write("Password: ")
  173.     term.setCursorPos((xPos/2 + #"Username:  "/2),7)
  174.     Uname = read()
  175.     term.setCursorPos((xPos/2 + #"Password:  "/2),8)
  176.     Pass = read("*")
  177.     rednet.send(ServerID, "@Pass")
  178.     rednet.send(ServerID, Uname)
  179.     rednet.send(ServerID, Pass)
  180.     id, Answer = rednet.receive()
  181.     if Answer == "@CP" then
  182.       Menu()
  183.     elseif Answer == "@WP" then
  184.       term.setCursorPos((xPos/2 - #"Incorrect Password"/2),10)
  185.       print("Incorrect Password")
  186.       sleep(1)  
  187.     end
  188.   until Answer == "@CP"
  189. end
  190. Login()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement