diff --git a/__resource.lua b/__resource.lua
index 6b6702e4..86cfa1da 100644
--- a/__resource.lua
+++ b/__resource.lua
@@ -11,7 +11,7 @@ client_script 'client/main.lua'
server_scripts {
"@mysql-async/lib/MySQL.lua",
"@es_extended/locale.lua",
- "server/main.lua",
+ "server/main.lua"
}
ui_page 'html/index.html'
@@ -20,5 +20,5 @@ files {
'html/index.html',
'html/script.js',
'html/style.css',
- 'html/cursor.png',
+ 'html/cursor.png'
}
diff --git a/client/main.lua b/client/main.lua
index 9d7ba252..2496868f 100644
--- a/client/main.lua
+++ b/client/main.lua
@@ -1,5 +1,13 @@
local guiEnabled = false
local myIdentity = {}
+ESX = nil
+
+Citizen.CreateThread(function()
+ while ESX == nil do
+ TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
+ Citizen.Wait(0)
+ end
+end)
function EnableGui(enable)
SetNuiFocus(enable)
@@ -21,11 +29,42 @@ RegisterNUICallback('escape', function(data, cb)
end)
RegisterNUICallback('register', function(data, cb)
+ local reason = ""
myIdentity = data
- TriggerServerEvent('esx_identity:setIdentity', data)
- EnableGui(false)
- Citizen.Wait(500)
- TriggerEvent('esx_skin:openSaveableMenu')
+ for theData, value in pairs(myIdentity) do
+ if theData == "firstname" or theData == "lastname" then
+ reason = verifyName(value)
+
+ if reason ~= "" then
+ break
+ end
+ elseif theData == "dateofbirth" then
+ if value == "invalid" then
+ reason = "Invalid date of birth!"
+ break
+ end
+ elseif theData == "height" then
+ local height = tonumber(value)
+ if height then
+ if height > 200 or height < 140 then
+ reason = "Unacceptable player height!"
+ break
+ end
+ else
+ reason = "Unacceptable player height!"
+ break
+ end
+ end
+ end
+
+ if reason == "" then
+ --TriggerServerEvent('esx_identity:setIdentity', data)
+ EnableGui(false)
+ Citizen.Wait(500)
+ --TriggerEvent('esx_skin:openSaveableMenu')
+ else
+ ESX.ShowNotification(reason)
+ end
end)
Citizen.CreateThread(function()
@@ -44,3 +83,47 @@ Citizen.CreateThread(function()
Citizen.Wait(10)
end
end)
+
+function verifyName(name)
+ -- Don't allow short user names
+ local nameLength = string.len(name)
+ if nameLength > 25 or nameLength < 5 then
+ return 'Your player name is either too short or too long.'
+ end
+
+ -- Don't allow special characters (doesn't always work)
+ local count = 0
+ for i in name:gmatch('[abcdefghijklmnopqrstuvwxyzåäöABCDEFGHIJKLMNOPQRSTUVWXYZÅÄÖ0123456789 -]') do
+ count = count + 1
+ end
+ if count ~= nameLength then
+ return 'Your player name contains special characters that are not allowed on this server.'
+ end
+
+ -- Does the player carry a first and last name?
+ --
+ -- Example:
+ -- Allowed: 'Bob Joe'
+ -- Not allowed: 'Bob'
+ -- Not allowed: 'Bob joe'
+ local spacesInName = 0
+ local spacesWithUpper = 0
+ for word in string.gmatch(name, '%S+') do
+
+ if string.match(word, '%u') then
+ spacesWithUpper = spacesWithUpper + 1
+ end
+
+ spacesInName = spacesInName + 1
+ end
+
+ if spacesInName > 2 then
+ return 'Your name contains more than two spaces'
+ end
+
+ if spacesWithUpper ~= spacesInName then
+ return 'your name must start with a capital letter.'
+ end
+
+ return ''
+end
diff --git a/html/index.html b/html/index.html
index 827ec7f5..1ccd4730 100644
--- a/html/index.html
+++ b/html/index.html
@@ -1,8 +1,6 @@
-
-