Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Convar to use FiveM identifier as main #1532

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions [core]/es_extended/server/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions [core]/es_extended/server/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion [core]/esx_multicharacter/server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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()
20 changes: 5 additions & 15 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 All @@ -46,15 +36,15 @@ 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
else
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

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
Loading