Guest User

lock server

a guest
Jun 5th, 2017
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. local client = changeme
  2. local usr = "changeme"
  3. local pass = "changeme"
  4. rednet.open("back")
  5.  
  6. -- Helper function to split strings at the first line-break ("n").
  7. -- Returns: Two strings representing the first and second half of the given string.
  8. local function splitAtLineBreak( toSplit )
  9. for i = 1, #toSplit do
  10. local currChar = string.sub( toSplit, i, i )
  11. if currChar == "n" then
  12. firstHalf = string.sub( toSplit, 1, i - 1 )
  13. secondHalf = string.sub( toSplit, i + 1 )
  14.  
  15. return firstHalf, secondHalf
  16. end -- of IF
  17. end -- of FOR
  18. end
  19.  
  20. while true do
  21. local id, loginDetails
  22. repeat
  23. id, loginDetails = rednet.receive()
  24. until id == client
  25.  
  26. local receivedUser, receivedPass = splitAtLineBreak( loginDetails )
  27. if receivedUser == usr and receivedPass == pass then
  28. sleep(5)
  29. rednet.send(client, "granted")
  30. else
  31. sleep(5)
  32. rednet.send(client, "denied")
  33. end
  34. end
Add Comment
Please, Sign In to add comment