From d06c9c24c9268efbda11a9522ae3e344c4b08cb0 Mon Sep 17 00:00:00 2001 From: Layla Manley Date: Sun, 8 Oct 2023 00:30:50 -0400 Subject: [PATCH] iteration --- auth.lua | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 auth.lua diff --git a/auth.lua b/auth.lua new file mode 100644 index 0000000..f7380a9 --- /dev/null +++ b/auth.lua @@ -0,0 +1,71 @@ +args = { ... } + +if args[1] == nil then + io.write("Usage: auth \n") + return +end + +local action = args[1] +local server = "auth.layla.mc" + +function lns_lookup(hostname) + local data = { + ["action"] = "lookup", + ["hostname"] = hostname + } + + rednet.send(lns_server_id, data) + + while true do + id, msg = rednet.receive() + if id == lns_server_id then + if msg == nil then + return nil + else + return msg + end + end + end +end + + +auth_server_id = lns_lookup(server) + +if action == "login" then + io.write("Username: ") + local username = io.read() + io.write("Password: ") + local password = io.read("*") + + local data = { + ["action"] = "login", + ["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 not found" then + io.write("User not found\n") + return + elseif msg == "invalid password" then + io.write("Invalid password\n") + return + else + token = msg + break + end + end + end + + io.write("Logged in as " .. username .. "\n") + io.write("Token: " .. token .. "\n") + return +end +