Advertisement
Guest User

housecloud

a guest
Oct 31st, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.59 KB | None | 0 0
  1. -- HouseCloud
  2. -- Made by houseofkraft
  3. -- Contributions by matimati433
  4. local sides = rs.getSides()
  5. local args = { ... }
  6. local loggedIn = false
  7.  
  8. -- Functions
  9. local function modemFound()
  10.   local modemFound, side
  11.   modemFound = false
  12.   for _,v in pairs(sides) do
  13.     if peripheral.getType(v) == "modem" then
  14.       modemFound = true
  15.       side = v
  16.     end
  17.   end
  18.   if modemFound then
  19.     return modemFound, side
  20.   else
  21.     return modemFound
  22.   end
  23. end    
  24.    
  25.  
  26. if #args < 1 then
  27.   -- Show usages
  28.   printError("Usages:")
  29.   printError("housecloud register <user>")
  30.   printError("housecloud login <user>")
  31.   printError("housecloud download")
  32.   printError("housecloud upload")
  33.   printError("For the login and register, you will be asked for a password.")
  34.   error()
  35. end
  36.  
  37. -- Modem checker
  38. local found, side = modemFound()
  39. if found then
  40.   rednet.open(side)
  41. else
  42.   printError("No modems detected!")
  43.   error()
  44. end
  45.  
  46. if args[1] == "register" then
  47.   write("Password: ")
  48.   pass = read("*")
  49.   print("Registering Account...")
  50.   info = {args[2], pass}
  51.   rednet.broadcast("register", info)
  52.   id, message = rednet.receive(1)
  53.   if message == "sucessful" then
  54.     print("Sucessful!")
  55.   elseif message == "userexists" then
  56.     print("Error: User Exists!")
  57.   else
  58.     print("No response, There may be no servers nearby.")
  59.   end
  60. elseif args[1] == "login" then
  61.   write("Password: ")
  62.   pass = read("*")
  63.   print("Logging in...")
  64.   info = {args[2], pass}
  65.   rednet.broadcast("login", info)
  66.   id, message = rednet.receive(1)
  67.   if message == "sucessful" then
  68.     print("Sucessful!")
  69.     file = fs.open(".login", "w")
  70.     file.writeLine(args[2])
  71.     file.writeLine(pass)
  72.     file.close()
  73.   end  
  74. elseif message == "usernoexist" then
  75.       print("Error: The user does not exist!")
  76. elseif message == "passwrong" then
  77.       print("Error: Password Wrong!")
  78.     else
  79.       print("No reponse, There may be no servers nearby.")
  80.     end
  81. elseif args[1] == "download" then
  82.   if fs.exists(".login") then
  83.     file = fs.open(".login", "r")
  84.     user = file.readLine()
  85.     pass = file.readLine()
  86.     file.close()
  87.     print("Downloading...")
  88.     info = {user, pass}
  89.     rednet.broadcast("download", info)
  90.     fs.makeDir("cloud")
  91.     while true do
  92.       id, message, info = rednet.receive()
  93.       if message == "receive" then
  94.         file = fs.open(info[1], "w")
  95.         file.write(info[2])
  96.       elseif message == "stop" then
  97.         break
  98.       elseif message == "badauth" then
  99.         print("Invaild Session, Try re-logging")
  100.         break
  101.       end
  102.     end
  103.   end
  104. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement