Skip to content

Commit

Permalink
refactor(esx_multichar/server): use ESX function for identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
Mycroft-Studios committed Dec 8, 2024
1 parent 0e991ce commit 7958934
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 22 deletions.
4 changes: 2 additions & 2 deletions [core]/esx_multicharacter/server/modules/database.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -140,4 +140,4 @@ function Database:DisableSlot(identifier, slot)
return updated > 0
end

Database:GetConnection()
Database:GetConnection()
16 changes: 3 additions & 13 deletions [core]/esx_multicharacter/server/modules/functions.lua
Original file line number Diff line number Diff line change
@@ -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 = {}
Expand All @@ -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."))
Expand Down
15 changes: 8 additions & 7 deletions [core]/esx_multicharacter/server/modules/multicharacter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -69,30 +69,31 @@ 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)
end

function Multicharacter:PlayerDropped(player)
self.awaitingRegistration[player] = nil
ESX.Players[Server:GetIdentifier(player)] = nil
ESX.Players[ESX.GetIdentifier(player)] = nil
end

0 comments on commit 7958934

Please sign in to comment.