diff --git a/auth.lua b/auth.lua index d458c30..aff73fc 100644 --- a/auth.lua +++ b/auth.lua @@ -70,3 +70,40 @@ if action == "login" then return end +if action == "register" then + io.write("Username: ") + local username = io.read() + io.write("Password: ") + local password = read("*") + io.write("Confirm Password: ") + local confirm_password = read("*") + + if password ~= confirm_password then + io.write("Passwords do not match\n") + return + end + + local data = { + ["action"] = "register", + ["username"] = username, + ["password"] = password + } + + rednet.send(auth_server_id, data) + + while true do + id, msg = rednet.receive() + if id == auth_server_id then + if msg == "invalid request" then + io.write("Invalid request\n") + return + elseif msg == "user already exists" then + io.write("User already exists\n") + return + else + io.write("Registered user " .. username .. "\n") + return + end + end + end +end \ No newline at end of file