Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- while true do
- local event, id, msg, dist = api.evt("rednet_message")
- if string.find(msg, "update") then
- msg = string.sub(msg, string.len("update")+2)
- ids = textutils.unserialize(msg)
- if api.isID(id) then
- mesg = textutils.unserialize(msg)
- end
- elseif string.find(msg, "apply") then
- if api.isID(id) then
- msg = string.sub(msg, string.len("apply")+2)
- local _, _, user, pass = string.find(msg, "^(%w+)&pwd=(%w+)$")
- term.scroll(1)
- term.setTextColor(colors.yellow)
- print("Authenticating...")
- if api.isPermitted(user, pass) then -- using the API here, where it returns an error
- term.scroll(1)
- term.setTextColor(colors.lime)
- print("Authenticated!")
- api.send(id, encrypt.hash("OK"))
- else
- term.scroll(1)
- term.setTextColor(colors.lime)
- print("Not authenticated!")
- api.send(id, encrypt.hash("FAIL"))
- end
- sleep(2)
- end
- elseif msg == "ping" then
- term.scroll(1)
- term.setTextColor(colors.yellow)
- print("Got \"ping\" from "..id)
- if not api.isID(id) then
- api.saveID(id)
- term.scroll(1)
- term.setTextColor(colors.lime)
- print("Saved ID of client")
- end
- api.send(id, "pong")
- term.scroll(1)
- term.setTextColor(colors.lime)
- print("Successfully sended \"pong\"")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement