Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function checkValidCharacterName(theText)
- local foundSpace, valid = false, true
- local lastChar, current = ' ', ''
- for i = 1, #theText do
- local char = theText:sub( i, i )
- if char == ' ' then -- it's a space
- if i == #theText then -- space at the end of name is not allowed
- valid = false
- return false
- else
- foundSpace = true -- we have at least two name parts
- end
- if #current < 2 then -- check if name's part is at least 2 chars
- valid = false
- return false
- end
- current = ''
- elseif lastChar == ' ' then -- this char follows a space, we need a capital letter
- if char < 'A' or char > 'Z' then
- valid = false
- return false
- end
- current = current .. char
- elseif ( char >= 'a' and char <= 'z' ) or ( char >= 'A' and char <= 'Z' ) or (char == "'") then -- can have letters anywhere in the name
- current = current .. char
- else -- unrecognized char (numbers, special chars)
- valid = false
- return false
- end
- lastChar = char
- end
- if valid and foundSpace and #theText < 25 and #current >= 2 then
- return true
- else
- return false
- end
- end
- function registerPlayer(username,password,passwordConfirm)
- if not (username == "") then
- if not (password == "") then
- if not (passwordConfirm == "") then
- if password == passwordConfirm then
- local trueLogin = checkValidCharacterName(username)
- if trueLogin then
- local account = getAccount (username,password)
- if (account == false) then
- local accountAdded = addAccount(tostring(username),tostring(password))
- if (accountAdded) then
- triggerClientEvent(source,"hideRegisterWindow",getRootElement())
- outputChatBox ("#0000FF* #FFFFFFYou have sucessfuly registered! [Username: #ABCDEF" .. username .. " #FF0000| #FFFFFFPassword: #ABCDEF" .. password .. "#FFFFFF]",source,255,255,255,true )
- setTimer(outputChatBox,800,1,"#0000FF* #FFFFFFТеперь вы можете войти в систему с новой учетной записи.",source,255,255,255,true )
- else
- outputChatBox ("#0000FF* #FFFFFF Неизвестная ошибка! Пожалуйста выберете другой логин/пароль и попробуйте еще раз.",source,255,255,255,true )
- end
- else
- outputChatBox ("#0000FF* #FFFFFFОшибка! Такой аккаунт уже есть попробуйте другой логин!",source,255,255,255,true )
- end
- else
- outputChatBox ("#0000FF* #FFFFFFОшибка! Пример имени: Carl_Jackson!",source,255,255,255,true)
- end
- else
- outputChatBox ("#0000FF* #FFFFFFОшибка! Пароли не совпадают!",source,255,255,255,true)
- end
- else
- outputChatBox ("#0000FF* #FFFFFFОшибка! Пожалуйста, подтвердите свой пароль!",source,255,255,255,true)
- end
- else
- outputChatBox ("#0000FF* #FFFFFFОшибка! Пожалуйста, введите пароль!",source,255,255,255,true)
- end
- else
- outputChatBox ("#0000FF* #FFFFFFОшибка! Пожалуйста введите имя пользователя под которым хотите зарегистрироваться!",source,255,255,255,true)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement