Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local have_repeated = false
- local count_spaces = 0
- local check_repeated = function(char)
- if (char == " ") then
- have_repeated = false
- elseif (string.len (char) > 2) then
- have_repeated = false
- elseif (char == " ") then
- count_spaces = count_spaces + 1
- end
- end
- --we need to keep game smooth checking and formating nicknames.
- --SetNickname and names comming from other player need to be check.
- function NickTag:CheckName (name)
- --as nicktag only work internally in the guild, we think that is not necessary a work filter to avoid people using bad language.
- if (type(name) ~= "string") then
- return false, LibStub ("AceLocale-3.0"):GetLocale ("NickTag-1.0")["STRING_ERROR_4"] --error 4 = name isn't a valid string
- end
- name = trim (name)
- --which alphabet to use
- local alphabetToUse = "latin"
- local firstLetter = name:match("^.")
- local maxLength = 999
- if (alphabet["cyrillic"][firstLetter]) then
- --reserve cyrillic only to clients running ruRU
- if (GetLocale() == "ruRU") then
- alphabetToUse = "cyrillic"
- maxLength = 28 --cyrillic uses two bytes
- else
- alphabetToUse = "latin"
- end
- elseif (alphabet["chinese"][firstLetter]) then
- if (GetLocale() == "zhCN" or GetLocale() == "zhTW") then
- alphabetToUse = "chinese"
- maxLength = 56 --chinese uses 4 bytes
- else
- alphabetToUse = "latin"
- end
- end
- --limit nickname to 12 characters, same as wow.
- --cyrillic seems to double the len using 2 bytes
- local len = string.len (name)
- if (len > maxLength) then
- return false, LibStub ("AceLocale-3.0"):GetLocale ("NickTag-1.0")["STRING_ERROR_1"] --error 1 = nickname is too long, max of 12 characters.
- end
- --check if contain any non allowed characters, by now only accpet letters, numbers and spaces.
- --by default wow do not accetp spaces, but here will allow.
- --tested over lua 5.2 and this capture was okey with accents, not sure why inside wow this doesn't work.
- -- local notallow = string.find (name, "[^a-zA-Z�������%s]")
- -- if (notallow) then
- -- return false, LibStub ("AceLocale-3.0"):GetLocale ("NickTag-1.0")["STRING_ERROR_2"] --error 2 = nickname only support letters, numbers and spaces.
- -- end
- --[=[
- for letter in name:gmatch(".") do
- if (not allowedLetters[letter]) then
- return false, LibStub ("AceLocale-3.0"):GetLocale ("NickTag-1.0")["STRING_ERROR_2"] --error 2 = nickname only support letters, numbers and spaces.
- end
- end
- --]=]
- --check if there is sequencial repeated characters, like "Jasooon" were repeats 3 times the "o" character.
- --got this from http://stackoverflow.com/questions/15608299/lua-pattern-matching-repeating-character
- have_repeated = false
- count_spaces = 0
- string.gsub (name, '.', '\0%0%0'):gsub ('(.)%z%1','%1'):gsub ('%z.([^%z]+)', check_repeated)
- if (count_spaces > 3) then
- have_repeated = false
- end
- if (have_repeated) then
- return false, LibStub ("AceLocale-3.0"):GetLocale ("NickTag-1.0")["STRING_ERROR_3"] --error 3 = cant use the same letter three times consecutively, 2 spaces consecutively or 3 or more spaces.
- end
- return true
- end
- --set the "player" nickname and schedule for send updated persona
- function NickTag:SetNickname (name)
- --check data before
- assert (type(name) == "string", "NickTag 'SetNickname' expects a string on #1 argument.")
- --check if the nickname is okey to allowed to use.
- local okey, errortype = NickTag:CheckName (name)
- if (not okey) then
- NickTag:Msg ("SetNickname() invalid name ", name)
- return false, errortype
- end
- --here we format the text to match titles, e.g converts name like "JASON NICKSHOW" into "Jason Nickshow".
- local playerName = UnitName ("player")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement