Advertisement
Guest User

pwordclient

a guest
Sep 14th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.61 KB | None | 0 0
  1. -----------------------------------------------
  2. --Copyright 2018 by Dusk the Dutch Angel Dragon
  3. -----------------------------------------------
  4. sides = {"back","top","left","right","bottom"}
  5. modem = "null"
  6. serverID = 0
  7. slp = 3
  8. door = "right"
  9.  
  10. function init()
  11.  for i=1, #sides do
  12.   if peripheral.getType(sides[i]) == "modem" then
  13.    modem = sides[i]
  14.    rednet.open(modem)
  15.   elseif i == #sides and modem == "null" then
  16.    error("No modem detected.")
  17.   end
  18.  end
  19. end
  20.  
  21. function filterResponse(filterID)
  22.  rid = -1
  23.  while rid ~= filterID do
  24.   rid, msg = rednet.receive(10)
  25.   if not msg then
  26.    return "timedout"
  27.   elseif rid == filterID then
  28.    return msg
  29.   end
  30.  end
  31. end
  32. --------------
  33. init()
  34. while true do
  35.  term.clear()
  36.  term.setCursorPos(1,1)
  37.  print("Press enter to log in.")
  38.  key = read()
  39.  rednet.send(serverID, "ack")
  40.  print("Requesting server acknowledgement...")
  41.  print("")
  42.  rsp = filterResponse(serverID)
  43.  if rsp == "ready" then
  44.   write("Username: ")
  45.   uname=read()
  46.   rednet.send(serverID, uname)
  47.   print("")
  48.   write("Password: ")
  49.   pword = read("*")
  50.   rednet.send(serverID, pword)
  51.   response = filterResponse(serverID)
  52.   if response == "auth" then
  53.    print("User authorized.")
  54.    rs.setOutput(door, true)
  55.    sleep(slp)
  56.    rs.setOutput(door, false)
  57.   elseif response == "nauth" then
  58.    print("User not authorized.")
  59.    sleep(slp)
  60.   end
  61.  elseif rsp == "timedout" then
  62.   print("Error connecting to server: Timed Out")
  63.   sleep(2)
  64.  elseif rsp == "400" then
  65.   print("Error connecting to server: Forbidden")
  66.   sleep(1)
  67.  else
  68.   print("Error: Invalid Server Response.")
  69.   sleep(slp)
  70.  end
  71. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement