Advertisement
Guest User

Untitled

a guest
Sep 8th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1. function checkValidCharacterName(theText)
  2. local foundSpace, valid = false, true
  3. local lastChar, current = ' ', ''
  4. for i = 1, #theText do
  5. local char = theText:sub( i, i )
  6. if char == ' ' then -- it's a space
  7. if i == #theText then -- space at the end of name is not allowed
  8. valid = false
  9. return false
  10. else
  11. foundSpace = true -- we have at least two name parts
  12. end
  13.  
  14. if #current < 2 then -- check if name's part is at least 2 chars
  15. valid = false
  16. return false
  17. end
  18. current = ''
  19. elseif lastChar == ' ' then -- this char follows a space, we need a capital letter
  20. if char < 'A' or char > 'Z' then
  21. valid = false
  22. return false
  23. end
  24. current = current .. char
  25. elseif ( char >= 'a' and char <= 'z' ) or ( char >= 'A' and char <= 'Z' ) or (char == "'") then -- can have letters anywhere in the name
  26. current = current .. char
  27. else -- unrecognized char (numbers, special chars)
  28. valid = false
  29. return false
  30. end
  31. lastChar = char
  32. end
  33.  
  34. if valid and foundSpace and #theText < 25 and #current >= 2 then
  35. return true
  36. else
  37. return false
  38. end
  39. end
  40.  
  41. function registerPlayer(username,password,passwordConfirm)
  42. if not (username == "") then
  43. if not (password == "") then
  44. if not (passwordConfirm == "") then
  45. if password == passwordConfirm then
  46. local trueLogin = checkValidCharacterName(username)
  47. if trueLogin then
  48. local account = getAccount (username,password)
  49. if (account == false) then
  50. local accountAdded = addAccount(tostring(username),tostring(password))
  51. if (accountAdded) then
  52. triggerClientEvent(source,"hideRegisterWindow",getRootElement())
  53. outputChatBox ("#0000FF* #FFFFFFYou have sucessfuly registered! [Username: #ABCDEF" .. username .. " #FF0000| #FFFFFFPassword: #ABCDEF" .. password .. "#FFFFFF]",source,255,255,255,true )
  54. setTimer(outputChatBox,800,1,"#0000FF* #FFFFFFТеперь вы можете войти в систему с новой учетной записи.",source,255,255,255,true )
  55. else
  56. outputChatBox ("#0000FF* #FFFFFF Неизвестная ошибка! Пожалуйста выберете другой логин/пароль и попробуйте еще раз.",source,255,255,255,true )
  57. end
  58. else
  59. outputChatBox ("#0000FF* #FFFFFFОшибка! Такой аккаунт уже есть попробуйте другой логин!",source,255,255,255,true )
  60. end
  61. else
  62. outputChatBox ("#0000FF* #FFFFFFОшибка! Пример имени: Carl_Jackson!",source,255,255,255,true)
  63. end
  64. else
  65. outputChatBox ("#0000FF* #FFFFFFОшибка! Пароли не совпадают!",source,255,255,255,true)
  66. end
  67. else
  68. outputChatBox ("#0000FF* #FFFFFFОшибка! Пожалуйста, подтвердите свой пароль!",source,255,255,255,true)
  69. end
  70. else
  71. outputChatBox ("#0000FF* #FFFFFFОшибка! Пожалуйста, введите пароль!",source,255,255,255,true)
  72. end
  73. else
  74. outputChatBox ("#0000FF* #FFFFFFОшибка! Пожалуйста введите имя пользователя под которым хотите зарегистрироваться!",source,255,255,255,true)
  75. end
  76. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement