Merge pull request #1675 from Zykem/feature/optional-identifier-type

feat(esx_core) Add optional player identifier type.
This commit is contained in:
Kenshin13
2025-08-01 11:15:10 +02:00
committed by GitHub
7 changed files with 19 additions and 24 deletions
+2 -2
View File
@@ -52,10 +52,10 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
if Config.Multichar then
local startIndex = identifier:find(":", 1)
if startIndex then
self.license = ("license%s"):format(identifier:sub(startIndex, identifier:len()))
self.license = ("%s%s"):format(Config.Identifier, identifier:sub(startIndex, identifier:len()))
end
else
self.license = ("license:%s"):format(identifier)
self.license = ("%s:%s"):format(Config.Identifier, identifier)
end
if type(self.metadata.jobDuty) ~= "boolean" then
+6 -2
View File
@@ -381,8 +381,12 @@ function ESX.GetIdentifier(playerId)
playerId = tostring(playerId)
local identifier = GetPlayerIdentifierByType(playerId, "license")
return identifier and identifier:gsub("license:", "")
local identifierType = Config.Identifier
local identifier = GetPlayerIdentifierByType(playerId, identifierType)
assert(identifier, ("[ESX] GetIdentifier failed: no identifier found for playerId %s with type '%s'"):format(playerId, identifierType))
return identifier:gsub(("%s:"):format(identifierType), "")
end
---@param model string|number
@@ -72,3 +72,4 @@ if GetResourceState("ox_inventory") ~= "missing" then
end
Config.EnableDefaultInventory = Config.CustomInventory == false -- Display the default Inventory ( F2 )
Config.Identifier = GetConvar("esx:identifier", "license")
+1 -1
View File
@@ -4,7 +4,7 @@ Server._index = Server
Server.oneSync = GetConvar("onesync", "off")
Server.slots = Config.Slots or 4
Server.prefix = Config.Prefix or "char"
Server.identifierType = ESX.GetConfig().Identifier or GetConvar("sv_lan", "") == "true" and "ip" or "license"
Server.identifierType = ESX.GetConfig("Identifier") or GetConvar("sv_lan", "") == "true" and "ip" or "license"
AddEventHandler("playerConnecting", function(_, _, deferrals)
local source = source
@@ -73,7 +73,7 @@ MySQL.ready(function()
end)
function Database:DeleteCharacter(source, charid)
local identifier = ("%s%s:%s"):format(Server.prefix, charid, Server:GetIdentifier(source))
local identifier = ("%s%s:%s"):format(Server.prefix, charid, ESX.GetIdentifier(source))
local query = "DELETE FROM `%s` WHERE %s = ?"
local queries = {}
local count = 0
@@ -141,4 +141,4 @@ function Database:DisableSlot(identifier, slot)
return updated > 0
end
Database:GetConnection()
Database:GetConnection()
@@ -1,22 +1,12 @@
ESX.Players = {}
function Server:GetIdentifier(source)
local fxDk = GetConvarInt("sv_fxdkMode", 0)
if fxDk == 1 then
return "ESX-DEBUG-LICENCE"
end
local identifier = GetPlayerIdentifierByType(source, self.identifierType)
return identifier and identifier:gsub(self.identifierType .. ":", "")
end
function Server:ResetPlayers()
if next(ESX.Players) then
local players = table.clone(ESX.Players)
table.wipe(ESX.Players)
for _, v in pairs(players) do
ESX.Players[self:GetIdentifier(v.source)] = v.identifier
ESX.Players[ESX.GetIdentifier(v.source)] = v.identifier
end
else
ESX.Players = {}
@@ -26,7 +16,7 @@ end
function Server:OnConnecting(source, deferrals)
deferrals.defer()
Wait(0) -- Required
local identifier = self:GetIdentifier(source)
local identifier = ESX.GetIdentifier(source)
-- luacheck: ignore
if not SetEntityOrphanMode then
@@ -10,7 +10,7 @@ function Multicharacter:SetupCharacters(source)
Wait(100)
end
local identifier = Server:GetIdentifier(source)
local identifier = ESX.GetIdentifier(source)
ESX.Players[identifier] = source
local slots = Database:GetPlayerSlots(identifier)
@@ -70,7 +70,7 @@ function Multicharacter:CharacterChosen(source, charid, isNew)
else
SetPlayerRoutingBucket(source, 0)
if not ESX.GetConfig().EnableDebug then
local identifier = ("%s%s:%s"):format(Server.prefix, charid, Server:GetIdentifier(source))
local identifier = ("%s%s:%s"):format(Server.prefix, charid, ESX.GetIdentifier(source))
if ESX.GetPlayerFromIdentifier(identifier) then
DropPlayer(source, "[ESX Multicharacter] Your identifier " .. identifier .. " is already on the server!")
@@ -80,7 +80,7 @@ function Multicharacter:CharacterChosen(source, charid, isNew)
local charIdentifier = ("%s%s"):format(Server.prefix, charid)
TriggerEvent("esx:onPlayerJoined", source, charIdentifier)
ESX.Players[Server:GetIdentifier(source)] = charIdentifier
ESX.Players[ESX.GetIdentifier(source)] = charIdentifier
end
end
@@ -88,7 +88,7 @@ function Multicharacter:RegistrationComplete(source, data)
local charId = self.awaitingRegistration[source]
local charIdentifier = ("%s%s"):format(Server.prefix, charId)
self.awaitingRegistration[source] = nil
ESX.Players[Server:GetIdentifier(source)] = charIdentifier
ESX.Players[ESX.GetIdentifier(source)] = charIdentifier
SetPlayerRoutingBucket(source, 0)
TriggerEvent("esx:onPlayerJoined", source, charIdentifier, data)
@@ -96,5 +96,5 @@ end
function Multicharacter:PlayerDropped(player)
self.awaitingRegistration[player] = nil
ESX.Players[Server:GetIdentifier(player)] = nil
ESX.Players[ESX.GetIdentifier(player)] = nil
end