diff --git a/[core]/es_extended/shared/config/main.lua b/[core]/es_extended/shared/config/main.lua index 108d292d..8932e30c 100644 --- a/[core]/es_extended/shared/config/main.lua +++ b/[core]/es_extended/shared/config/main.lua @@ -39,6 +39,14 @@ Config.AdminGroups = { ["admin"] = true, } +Config.ValidCharacterSets = { -- Only enable additional charsets if your server is multilingual. By default everything is false. + ['el'] = false, -- Greek + ['sr'] = false, -- Cyrillic + ['he'] = false, -- Hebrew + ['ar'] = false, -- Arabic + ['zh-cn'] = false -- Chinese, Japanese, Korean +} + Config.EnablePaycheck = true -- enable paycheck Config.LogPaycheck = false -- Logs paychecks to a nominated Discord channel via webhook (default is false) Config.EnableSocietyPayouts = false -- pay from the society account that the player is employed at? Requirement: esx_society diff --git a/[core]/es_extended/shared/functions.lua b/[core]/es_extended/shared/functions.lua index 184def1b..8e326150 100644 --- a/[core]/es_extended/shared/functions.lua +++ b/[core]/es_extended/shared/functions.lua @@ -210,3 +210,78 @@ function ESX.Await(conditionFunc, errorMessage, timeoutMs) return false end + +---@param str string +---@param allowDigits boolean? Allow numbers if necessary +---@return boolean +function ESX.IsValidLocaleString(str, allowDigits) + if not ESX.ValidateType(str, 'string') then + return false + end + + local locale = string.lower(Config.Locale) + + local defaultRanges ={ + {0x0041, 0x005A}, -- Basic Latin uppercase + {0x0061, 0x007A}, -- Basic Latin lowercase + {0x0020, 0x0020}, -- Space + {0x002D, 0x002D}, -- Dash + {0x00C0, 0x02AF} -- Latin Extended + } + + if allowDigits then + defaultRanges[#defaultRanges + 1] = {0x0030, 0x0039} -- 0-9 Numbers + end + + local localeRanges = { + ["el"] = { {0x0370, 0x03FF} }, -- Greek + ["sr"] ={ {0x0400, 0x04FF} }, -- Cyrillic + ["he"] ={ {0x05D0, 0x05EA} }, -- Hebrew letters + ["ar"] = { + {0x0620, 0x063F}, -- Arabic + {0x0641, 0x064A}, + {0x066E, 0x066F}, + {0x0671, 0x06D3}, + {0x06D5, 0x06D5}, + {0x0750, 0x077F}, + {0x08A0, 0x08BD} + }, + ["zh-cn"] ={ {0x4E00, 0x9FFF} } -- CJK + } + + local validRanges = { table.unpack(defaultRanges) } + + if localeRanges[locale] then + for i = 1, #localeRanges[locale] do + validRanges[#validRanges + 1] = localeRanges[locale][i] + end + end + + if Config.ValidCharacterSets then + for charset, enabled in pairs(Config.ValidCharacterSets) do + if enabled and charset ~= locale and localeRanges[charset] then + for i = 1, #localeRanges[charset] do + validRanges[#validRanges + 1] = localeRanges[charset][i] + end + end + end + end + + for _, code in utf8.codes(str) do + local isValid = false + + for i = 1, #validRanges do + local range = validRanges[i] + if code >= range[1] and code <= range[2] then + isValid = true + break + end + end + + if not isValid then + return false + end + end + + return true +end diff --git a/[core]/esx_identity/server/main.lua b/[core]/esx_identity/server/main.lua index d0461b92..9ee283da 100644 --- a/[core]/esx_identity/server/main.lua +++ b/[core]/esx_identity/server/main.lua @@ -84,16 +84,8 @@ local function formatDate(str) return date end -local function checkAlphanumeric(str) - return (string.match(str, "%W")) -end - -local function checkForNumbers(str) - return (string.match(str, "%d")) -end - local function checkNameFormat(name) - if not checkAlphanumeric(name) and not checkForNumbers(name) then + if ESX.IsValidLocaleString(name) then local stringLength = string.len(name) return stringLength > 0 and stringLength < Config.MaxNameLength end