Alexhill2233

d

Dec 19th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. local oldpullevent = os.pullevent
  2. local os.pullevent = os.pullEventRaw
  3. local auth_channel = 234 --#Ensure that the auth channel is the same!
  4. local myChannel = 10 --#Any channel the user wishes
  5. local modem = peripheral.wrap("top")
  6. modem.open(myChannel) --#We don't need to open the auth_channel to send messages, only if we need to receive on that channel
  7.  
  8. while true do
  9. term.clear() term.setCursorPos(1,1)
  10. term.write("Username: ")
  11. local username = read() --#Gets the user's input
  12. local password = read("*") --#The asterisk is the masking character
  13.  
  14. local user_table = {["username"] = username, ["password"] = password}
  15. modem.transmit(auth_channel, myChannel, textutils.serialize(user_table)) --#Go ahead and send off the info to the server
  16. while true do --Now we wait for a response
  17. local event, modem_side, sender_channel, reply_channel, message = os.pullEvent("modem_message")
  18. if reply_channel == auth_channel then --#If it is indeed the server that sent the message
  19. if message == "valid" then --#It was indeed a valid username/password combo
  20. printError("Valid username/password!") --#Do whatever you want here + sets the exit error.
  21. os.pullEvent = oldpullevent
  22. error() -- Exit the program
  23.  
  24. else --#Nope, invalid.
  25. print("Invalid username/password!")
  26. sleep(3)
  27. end
  28. end
  29. end
  30. end
Add Comment
Please, Sign In to add comment