-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
AddEventHandler('playerConnecting', function(name, setCallback, deferrals) | ||
-- Mark this connection as deferred, this is to prevent problems while checking player identifiers. | ||
deferrals.defer() | ||
|
||
-- Save source in case we somehow lose it (which happens a lot) | ||
local _source = source | ||
|
||
-- Letting the user know what's going on. | ||
deferrals.update('Validating player name . . .') | ||
|
||
-- Needed, not sure why. | ||
Citizen.Wait(100) | ||
|
||
local playerName = GetPlayerName(_source) | ||
local allowed = true | ||
local reason = nil | ||
|
||
-- Don't allow short user names | ||
local nameLength = string.len(playerName) | ||
if nameLength > 25 or nameLength < 7 then | ||
reason = 'your player name is too short or too long. The name limit min: 7 | max: 25.' | ||
allowed = false | ||
end | ||
|
||
-- Don't allow special characters (doesn't always work) | ||
local charMatch = playerName:match("%W") | ||
if charMatch == '' or charMatch == ' ' or charMatch == '├' or charMatch == nil then | ||
|
||
else | ||
if reason == nil then | ||
reason = 'your player name contains special characters that are not allowed on this server.' | ||
end | ||
allowed = false | ||
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(playerName, '%S+') do | ||
|
||
if string.match(word, '%u') then | ||
spacesWithUpper = spacesWithUpper + 1 | ||
end | ||
|
||
spacesInName = spacesInName + 1 | ||
end | ||
|
||
if spacesInName < 2 then | ||
if reason == nil then | ||
reason = 'your player name does not contain a first and last name.' | ||
end | ||
allowed = false | ||
end | ||
|
||
if spacesWithUpper ~= spacesInName then | ||
if reason == nil then | ||
reason = 'your first and surname must start with a capital letter.' | ||
end | ||
allowed = false | ||
end | ||
|
||
if allowed then | ||
deferrals.done() | ||
else | ||
deferrals.done('You cannot connect with your current player name. Reason: ' .. reason .. ' If you belive that something is wrong, please contact the SCRP staff') | ||
end | ||
end) |