Advertisement
albrat

Client door opener

Jun 30th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.42 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw -- remove the CTRL + T escape
  2.  
  3. -- Local variables
  4.  
  5. local cmpid = os.getComputerID()
  6. local locker = true  -- Technically I no longer use this varible. it used to define the loop for my login.
  7. local failed = true
  8. local attempted_login = true
  9. local password_server = 30 -- change to the ID of your password server computer
  10. local moside = "top"  -- This is your modem location :- top, bottom, left, right, back or front
  11.  
  12. print("Computer ID : ".. cmpid)
  13. rednet.open(moside)  -- open the Rednet modem.
  14.  
  15.  
  16. while true do  -- infinite loop
  17.  attempted_login = false  -- reset the varible
  18.  term.clear()
  19.  term.setCursorPos(1,1)
  20.  print("Welcome to a Client PC : Roaming Profile Enabled")
  21.  print("What would you like to do?")
  22.  print("[1] Login (*)")
  23.  print("[2] Shutdown")
  24.  
  25.  -- end of the menu
  26.  
  27.  write("> ")
  28.  local input = read()
  29.  
  30.  if input == "2" then  -- reverse order shall we shut down ?
  31.   os.shutdown()
  32.  
  33.  elseif input == "1" then -- if not then lets do something maybe ?
  34.   attempted_login = true
  35.   print("Please login...")
  36.  
  37.   -- Username
  38.  
  39.   write("Username: ")
  40.   local username = read()  -- Get input of Username
  41.  
  42.   -- Password
  43.  
  44.   write("Password: ")
  45.   local password = read("*") -- Get masked input of Password
  46.  
  47.   local testmessage = username .. " " .. password  -- make our rednet message with seperator
  48.  
  49.   if debug then print(testmessage);sleep(5); end  -- Debug testing to check the message
  50.  
  51.   rednet.send(password_server, testmessage, true)
  52.   senderId, message, distance = rednet.receive(5)
  53.   if message == "valid" then  -- did the server send the message "valid" ?
  54.    failed = false
  55.    
  56.    --[[
  57.    locker = false  -- here is the non used Locker again, at this point it would unlock us from the loop.
  58.    -- the while true do makes that line obsolete.
  59.    --]]
  60.    
  61.    term.clear()
  62.    term.setCursorPos(1,1)
  63.    print("Welcome ", username) -- Welcome the user.
  64.    
  65.    ---[[ This next section is my door opening server. Send the open and close commands
  66.    -- to the door server, plus the wait time of 6 seconds to get out the terminal and through the door
  67.     rednet.send(17, "open")
  68.     sleep(6)
  69.     rednet.send(17, "close")
  70.     --]]
  71.    
  72.   else  -- The server sent a non valid respone.
  73.    print("Invalid Username or Password.")
  74.    sleep(3)
  75.   end
  76.  
  77.   -- If you did not type 1 or 2... I have no idea...
  78.  
  79.  else  
  80.   print("Command not recognised...")
  81.   sleep(2)
  82.  end
  83. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement