From 7958934f8f48c17dd1ed98c505cbe6c646b1293c Mon Sep 17 00:00:00 2001 From: Kasey FItton Date: Sun, 8 Dec 2024 16:50:12 +0000 Subject: [PATCH 1/2] refactor(esx_multichar/server): use ESX function for identifier --- .../server/modules/database.lua | 4 ++-- .../server/modules/functions.lua | 16 +++------------- .../server/modules/multicharacter.lua | 15 ++++++++------- 3 files changed, 13 insertions(+), 22 deletions(-) diff --git a/[core]/esx_multicharacter/server/modules/database.lua b/[core]/esx_multicharacter/server/modules/database.lua index 96294523e..e3fc245c6 100644 --- a/[core]/esx_multicharacter/server/modules/database.lua +++ b/[core]/esx_multicharacter/server/modules/database.lua @@ -72,7 +72,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 @@ -140,4 +140,4 @@ function Database:DisableSlot(identifier, slot) return updated > 0 end -Database:GetConnection() \ No newline at end of file +Database:GetConnection() diff --git a/[core]/esx_multicharacter/server/modules/functions.lua b/[core]/esx_multicharacter/server/modules/functions.lua index f1750e2fb..d9c226075 100644 --- a/[core]/esx_multicharacter/server/modules/functions.lua +++ b/[core]/esx_multicharacter/server/modules/functions.lua @@ -1,20 +1,10 @@ -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)] = true + ESX.Players[ESX.GetIdentifier(v.source)] = true end else ESX.Players = {} @@ -24,8 +14,8 @@ 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 return deferrals.done(("[ESX] ESX Requires a minimum Artifact version of 10188, Please update your server.")) diff --git a/[core]/esx_multicharacter/server/modules/multicharacter.lua b/[core]/esx_multicharacter/server/modules/multicharacter.lua index c43be5819..55a8b9a0c 100644 --- a/[core]/esx_multicharacter/server/modules/multicharacter.lua +++ b/[core]/esx_multicharacter/server/modules/multicharacter.lua @@ -10,7 +10,7 @@ function Multicharacter:SetupCharacters(source) Wait(100) end - local identifier = Server:GetIdentifier(source) + local identifier = ESX.GetIdentifier(source) ESX.Players[identifier] = true local slots = Database:GetPlayerSlots(identifier) @@ -69,24 +69,25 @@ function Multicharacter:CharacterChosen(source, charid, isNew) self.awaitingRegistration[source] = charid else SetPlayerRoutingBucket(source, 0) + local identifier = ESX.GetIdentifier(source) if not ESX.GetConfig().EnableDebug then - local identifier = ("%s%s:%s"):format(Server.prefix, charid, Server:GetIdentifier(source)) + local formattedIdentifier = ("%s%s:%s"):format(Server.prefix, charid, identifier) - if ESX.GetPlayerFromIdentifier(identifier) then - DropPlayer(source, "[ESX Multicharacter] Your identifier " .. identifier .. " is already on the server!") + if ESX.GetPlayerFromIdentifier(formattedIdentifier) then + DropPlayer(source, "[ESX Multicharacter] Your identifier " .. formattedIdentifier .. " is already on the server!") return end end TriggerEvent("esx:onPlayerJoined", source, ("%s%s"):format(Server.prefix, charid)) - ESX.Players[Server:GetIdentifier(source)] = true + ESX.Players[identifier] = true end end function Multicharacter:RegistrationComplete(source, data) local charId = self.awaitingRegistration[source] self.awaitingRegistration[source] = nil - ESX.Players[Server:GetIdentifier(source)] = true + ESX.Players[ESX.GetIdentifier(source)] = true SetPlayerRoutingBucket(source, 0) TriggerEvent("esx:onPlayerJoined", source, ("%s%s"):format(Server.prefix, charId), data) @@ -94,5 +95,5 @@ end function Multicharacter:PlayerDropped(player) self.awaitingRegistration[player] = nil - ESX.Players[Server:GetIdentifier(player)] = nil + ESX.Players[ESX.GetIdentifier(player)] = nil end From eeddf8ae4872f9b7e213c7a858585d7d0bdae1b1 Mon Sep 17 00:00:00 2001 From: Kasey FItton Date: Sun, 8 Dec 2024 18:45:22 +0000 Subject: [PATCH 2/2] refactor: Convar to use FiveM identifier as main --- [core]/es_extended/server/common.lua | 2 ++ [core]/es_extended/server/functions.lua | 4 ++-- [core]/esx_multicharacter/server/main.lua | 1 - [core]/esx_multicharacter/server/modules/functions.lua | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/[core]/es_extended/server/common.lua b/[core]/es_extended/server/common.lua index edbc39529..84f84e92f 100644 --- a/[core]/es_extended/server/common.lua +++ b/[core]/es_extended/server/common.lua @@ -13,6 +13,8 @@ Core.playersByIdentifier = {} Core.vehicleTypesByModel = {} +ESX.identifierType = GetConvar("esx:useFiveMId", "false") == "true" and "fivem" or "license" + RegisterNetEvent("esx:onPlayerSpawn", function() ESX.Players[source].spawned = true end) diff --git a/[core]/es_extended/server/functions.lua b/[core]/es_extended/server/functions.lua index 884ef4a57..152e95c72 100644 --- a/[core]/es_extended/server/functions.lua +++ b/[core]/es_extended/server/functions.lua @@ -368,8 +368,8 @@ function ESX.GetIdentifier(playerId) playerId = tostring(playerId) - local identifier = GetPlayerIdentifierByType(playerId, "license") - return identifier and identifier:gsub("license:", "") + local identifier = GetPlayerIdentifierByType(playerId, ESX.identifierType) + return identifier and identifier:gsub(ESX.identifierType, "") end ---@param model string|number diff --git a/[core]/esx_multicharacter/server/main.lua b/[core]/esx_multicharacter/server/main.lua index 0418e1737..c35c34472 100644 --- a/[core]/esx_multicharacter/server/main.lua +++ b/[core]/esx_multicharacter/server/main.lua @@ -4,7 +4,6 @@ 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" AddEventHandler("playerConnecting", function(_, _, deferrals) local source = source diff --git a/[core]/esx_multicharacter/server/modules/functions.lua b/[core]/esx_multicharacter/server/modules/functions.lua index d9c226075..cccc02c28 100644 --- a/[core]/esx_multicharacter/server/modules/functions.lua +++ b/[core]/esx_multicharacter/server/modules/functions.lua @@ -36,7 +36,7 @@ function Server:OnConnecting(source, deferrals) if identifier then if not ESX.GetConfig().EnableDebug then if ESX.Players[identifier] then - deferrals.done(("[ESX Multicharacter] A player is already connected to the server with this identifier.\nYour identifier: %s:%s"):format(Server.identifierType, identifier)) + deferrals.done(("[ESX Multicharacter] A player is already connected to the server with this identifier.\nYour identifier: %s:%s"):format(ESX.identifierType, identifier)) else deferrals.done() end @@ -44,7 +44,7 @@ function Server:OnConnecting(source, deferrals) deferrals.done() end else - deferrals.done(("[ESX Multicharacter] Unable to retrieve player identifier.\nIdentifier type: %s"):format(Server.identifierType)) + deferrals.done(("[ESX Multicharacter] Unable to retrieve player identifier.\nIdentifier type: %s"):format(ESX.identifierType)) end end