Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -----------------------------------------------
- --Copyright 2018 by Dusk the Dutch Angel Dragon
- -----------------------------------------------
- sides = {"back","top","left","right","bottom"}
- modem = "null"
- serverID = 0
- slp = 3
- door = "right"
- function init()
- for i=1, #sides do
- if peripheral.getType(sides[i]) == "modem" then
- modem = sides[i]
- rednet.open(modem)
- elseif i == #sides and modem == "null" then
- error("No modem detected.")
- end
- end
- end
- function filterResponse(filterID)
- rid = -1
- while rid ~= filterID do
- rid, msg = rednet.receive()
- end
- return msg
- end
- --------------
- init()
- while true do
- term.clear()
- term.setCursorPos(1,1)
- print("Press enter to log in.")
- key = read()
- rednet.send(serverID, "ack")
- rsp = filterResponse(serverID)
- print(rsp)
- if rsp == "ready" then
- write("Username: ")
- uname=read()
- rednet.send(serverID, uname)
- print("")
- write("Password: ")
- pword = read("*")
- rednet.send(serverID, pword)
- response = filterResponse(serverID)
- if response == "auth" then
- print("User authorized.")
- rs.setOutput(door, true)
- sleep(slp)
- rs.setOutput(door, false)
- elseif response == "nauth" then
- print("User not authorized.")
- sleep(slp)
- end
- elseif allowed == 400 then
- print("Error connecting to server: Forbidden")
- sleep(1)
- else
- print("unknown message")
- sleep(slp)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement