Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- HouseCloud
- -- Made by houseofkraft
- -- Contributions by matimati433
- local sides = rs.getSides()
- local args = { ... }
- local loggedIn = false
- -- Functions
- local function modemFound()
- local modemFound, side
- modemFound = false
- for _,v in pairs(sides) do
- if peripheral.getType(v) == "modem" then
- modemFound = true
- side = v
- end
- end
- if modemFound then
- return modemFound, side
- else
- return modemFound
- end
- end
- if #args < 1 then
- -- Show usages
- printError("Usages:")
- printError("housecloud register <user>")
- printError("housecloud login <user>")
- printError("housecloud download")
- printError("housecloud upload")
- printError("For the login and register, you will be asked for a password.")
- error()
- end
- -- Modem checker
- local found, side = modemFound()
- if found then
- rednet.open(side)
- else
- printError("No modems detected!")
- error()
- end
- if args[1] == "register" then
- write("Password: ")
- pass = read("*")
- print("Registering Account...")
- info = {args[2], pass}
- rednet.broadcast("register", info)
- id, message = rednet.receive(1)
- if message == "sucessful" then
- print("Sucessful!")
- elseif message == "userexists" then
- print("Error: User Exists!")
- else
- print("No response, There may be no servers nearby.")
- end
- elseif args[1] == "login" then
- write("Password: ")
- pass = read("*")
- print("Logging in...")
- info = {args[2], pass}
- rednet.broadcast("login", info)
- id, message = rednet.receive(1)
- if message == "sucessful" then
- print("Sucessful!")
- file = fs.open(".login", "w")
- file.writeLine(args[2])
- file.writeLine(pass)
- file.close()
- end
- elseif message == "usernoexist" then
- print("Error: The user does not exist!")
- elseif message == "passwrong" then
- print("Error: Password Wrong!")
- else
- print("No reponse, There may be no servers nearby.")
- end
- elseif args[1] == "download" then
- if fs.exists(".login") then
- file = fs.open(".login", "r")
- user = file.readLine()
- pass = file.readLine()
- file.close()
- print("Downloading...")
- info = {user, pass}
- rednet.broadcast("download", info)
- fs.makeDir("cloud")
- while true do
- id, message, info = rednet.receive()
- if message == "receive" then
- file = fs.open(info[1], "w")
- file.write(info[2])
- elseif message == "stop" then
- break
- elseif message == "badauth" then
- print("Invaild Session, Try re-logging")
- break
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement