mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-31 02:08:55 +00:00
Merge pull request #149 from thelindat/master
fix(legacy/multichar): Add support when using multicharacter
This commit is contained in:
+1
-1
@@ -56,7 +56,7 @@ if not Config.UseDeferrals then
|
|||||||
if callback then
|
if callback then
|
||||||
ESX.ShowNotification(_U('thank_you_for_registering'))
|
ESX.ShowNotification(_U('thank_you_for_registering'))
|
||||||
EnableGui(false)
|
EnableGui(false)
|
||||||
TriggerEvent('esx_skin:playerRegistered')
|
if not ESX.GetConfig().Multichar then TriggerEvent('esx_skin:playerRegistered') end
|
||||||
else
|
else
|
||||||
ESX.ShowNotification(_U('registration_error'))
|
ESX.ShowNotification(_U('registration_error'))
|
||||||
end
|
end
|
||||||
|
|||||||
+88
-79
@@ -1,20 +1,29 @@
|
|||||||
ESX = nil
|
ESX = nil
|
||||||
|
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
|
||||||
local playerIdentity = {}
|
local playerIdentity = {}
|
||||||
local alreadyRegistered = {}
|
local alreadyRegistered = {}
|
||||||
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
|
local multichar = ESX.GetConfig().Multichar
|
||||||
|
|
||||||
|
function getIdentifier(playerId)
|
||||||
|
if multichar ~= nil then
|
||||||
|
return ESX.GetIdentifier(playerId)
|
||||||
|
else
|
||||||
|
ESX.GetIdentifier = function(playerId)
|
||||||
|
for k,v in ipairs(GetPlayerIdentifiers(playerId)) do
|
||||||
|
if string.match(v, 'license') then
|
||||||
|
local identifier = string.gsub(v, 'license:', '')
|
||||||
|
return identifier
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if Config.UseDeferrals then
|
if Config.UseDeferrals then
|
||||||
AddEventHandler('playerConnecting', function(playerName, setKickReason, deferrals)
|
AddEventHandler('playerConnecting', function(playerName, setKickReason, deferrals)
|
||||||
deferrals.defer()
|
deferrals.defer()
|
||||||
local playerId, identifier = source
|
local playerId, identifier = source, getIdentifier(source)
|
||||||
Citizen.Wait(100)
|
Citizen.Wait(100)
|
||||||
|
|
||||||
for k,v in ipairs(GetPlayerIdentifiers(playerId)) do
|
|
||||||
if string.match(v, 'license:') then
|
|
||||||
identifier = string.sub(v, 9)
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if identifier then
|
if identifier then
|
||||||
MySQL.Async.fetchAll('SELECT firstname, lastname, dateofbirth, sex, height FROM users WHERE identifier = @identifier', {
|
MySQL.Async.fetchAll('SELECT firstname, lastname, dateofbirth, sex, height FROM users WHERE identifier = @identifier', {
|
||||||
@@ -108,95 +117,90 @@ if Config.UseDeferrals then
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
elseif not Config.UseDeferrals then
|
elseif not Config.UseDeferrals then
|
||||||
AddEventHandler('playerConnecting', function(playerName, setKickReason, deferrals)
|
if not multichar then
|
||||||
deferrals.defer()
|
AddEventHandler('playerConnecting', function(playerName, setKickReason, deferrals)
|
||||||
local playerId, identifier = source
|
deferrals.defer()
|
||||||
Citizen.Wait(40)
|
local playerId, identifier = source, getIdentifier(source)
|
||||||
|
Citizen.Wait(40)
|
||||||
|
|
||||||
for k,v in ipairs(GetPlayerIdentifiers(playerId)) do
|
if identifier then
|
||||||
if string.match(v, 'license:') then
|
MySQL.Async.fetchAll('SELECT firstname, lastname, dateofbirth, sex, height FROM users WHERE identifier = @identifier', {
|
||||||
identifier = string.sub(v, 9)
|
['@identifier'] = identifier
|
||||||
break
|
}, function(result)
|
||||||
end
|
if result[1] then
|
||||||
end
|
if result[1].firstname then
|
||||||
|
playerIdentity[identifier] = {
|
||||||
|
firstName = result[1].firstname,
|
||||||
|
lastName = result[1].lastname,
|
||||||
|
dateOfBirth = result[1].dateofbirth,
|
||||||
|
sex = result[1].sex,
|
||||||
|
height = result[1].height
|
||||||
|
}
|
||||||
|
|
||||||
if identifier then
|
alreadyRegistered[identifier] = true
|
||||||
MySQL.Async.fetchAll('SELECT firstname, lastname, dateofbirth, sex, height FROM users WHERE identifier = @identifier', {
|
|
||||||
['@identifier'] = identifier
|
|
||||||
}, function(result)
|
|
||||||
if result[1] then
|
|
||||||
if result[1].firstname then
|
|
||||||
playerIdentity[identifier] = {
|
|
||||||
firstName = result[1].firstname,
|
|
||||||
lastName = result[1].lastname,
|
|
||||||
dateOfBirth = result[1].dateofbirth,
|
|
||||||
sex = result[1].sex,
|
|
||||||
height = result[1].height
|
|
||||||
}
|
|
||||||
|
|
||||||
alreadyRegistered[identifier] = true
|
deferrals.done()
|
||||||
|
else
|
||||||
deferrals.done()
|
playerIdentity[identifier] = nil
|
||||||
|
alreadyRegistered[identifier] = false
|
||||||
|
deferrals.done()
|
||||||
|
end
|
||||||
else
|
else
|
||||||
playerIdentity[identifier] = nil
|
playerIdentity[identifier] = nil
|
||||||
alreadyRegistered[identifier] = false
|
alreadyRegistered[identifier] = false
|
||||||
deferrals.done()
|
deferrals.done()
|
||||||
end
|
end
|
||||||
else
|
end)
|
||||||
playerIdentity[identifier] = nil
|
else
|
||||||
alreadyRegistered[identifier] = false
|
deferrals.done(_U('no_identifier'))
|
||||||
deferrals.done()
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
else
|
|
||||||
deferrals.done(_U('no_identifier'))
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
AddEventHandler('onResourceStart', function(resource)
|
|
||||||
if resource == GetCurrentResourceName() then
|
|
||||||
Citizen.Wait(300)
|
|
||||||
|
|
||||||
while not ESX do
|
|
||||||
Citizen.Wait(10)
|
|
||||||
end
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
local xPlayers = ESX.GetPlayers()
|
AddEventHandler('onResourceStart', function(resource)
|
||||||
|
if resource == GetCurrentResourceName() then
|
||||||
|
Citizen.Wait(300)
|
||||||
|
|
||||||
for i=1, #xPlayers, 1 do
|
while not ESX do
|
||||||
local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
|
Citizen.Wait(10)
|
||||||
|
end
|
||||||
|
|
||||||
if xPlayer then
|
local xPlayers = ESX.GetPlayers()
|
||||||
checkIdentity(xPlayer)
|
|
||||||
|
for i=1, #xPlayers, 1 do
|
||||||
|
local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
|
||||||
|
|
||||||
|
if xPlayer then
|
||||||
|
checkIdentity(xPlayer)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end)
|
||||||
end)
|
|
||||||
|
|
||||||
RegisterNetEvent('esx:playerLoaded')
|
RegisterNetEvent('esx:playerLoaded')
|
||||||
AddEventHandler('esx:playerLoaded', function(playerId, xPlayer)
|
AddEventHandler('esx:playerLoaded', function(playerId, xPlayer)
|
||||||
if alreadyRegistered[xPlayer.identifier] == true then
|
|
||||||
local currentIdentity = playerIdentity[xPlayer.identifier]
|
local currentIdentity = playerIdentity[xPlayer.identifier]
|
||||||
|
if currentIdentity and alreadyRegistered[xPlayer.identifier] == true then
|
||||||
|
|
||||||
xPlayer.setName(('%s %s'):format(currentIdentity.firstName, currentIdentity.lastName))
|
xPlayer.setName(('%s %s'):format(currentIdentity.firstName, currentIdentity.lastName))
|
||||||
xPlayer.set('firstName', currentIdentity.firstName)
|
xPlayer.set('firstName', currentIdentity.firstName)
|
||||||
xPlayer.set('lastName', currentIdentity.lastName)
|
xPlayer.set('lastName', currentIdentity.lastName)
|
||||||
xPlayer.set('dateofbirth', currentIdentity.dateOfBirth)
|
xPlayer.set('dateofbirth', currentIdentity.dateOfBirth)
|
||||||
xPlayer.set('sex', currentIdentity.sex)
|
xPlayer.set('sex', currentIdentity.sex)
|
||||||
xPlayer.set('height', currentIdentity.height)
|
xPlayer.set('height', currentIdentity.height)
|
||||||
|
|
||||||
if currentIdentity.saveToDatabase then
|
if currentIdentity.saveToDatabase then
|
||||||
saveIdentityToDatabase(xPlayer.identifier, currentIdentity)
|
saveIdentityToDatabase(xPlayer.identifier, currentIdentity)
|
||||||
|
end
|
||||||
|
|
||||||
|
Citizen.Wait(10)
|
||||||
|
TriggerClientEvent('esx_identity:alreadyRegistered', xPlayer.source)
|
||||||
|
|
||||||
|
playerIdentity[xPlayer.identifier] = nil
|
||||||
|
else
|
||||||
|
TriggerClientEvent('esx_identity:showRegisterIdentity', xPlayer.source)
|
||||||
end
|
end
|
||||||
|
end)
|
||||||
Citizen.Wait(10)
|
end
|
||||||
TriggerClientEvent('esx_identity:alreadyRegistered', xPlayer.source)
|
|
||||||
|
|
||||||
playerIdentity[xPlayer.identifier] = nil
|
|
||||||
else
|
|
||||||
TriggerClientEvent('esx_identity:showRegisterIdentity', xPlayer.source)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
ESX.RegisterServerCallback('esx_identity:registerIdentity', function(source, cb, data)
|
ESX.RegisterServerCallback('esx_identity:registerIdentity', function(source, cb, data)
|
||||||
local xPlayer = ESX.GetPlayerFromId(source)
|
local xPlayer = ESX.GetPlayerFromId(source)
|
||||||
@@ -232,6 +236,11 @@ elseif not Config.UseDeferrals then
|
|||||||
else
|
else
|
||||||
cb(false)
|
cb(false)
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
if multichar and checkNameFormat(data.firstname) and checkNameFormat(data.lastname) and checkSexFormat(data.sex) and checkDOBFormat(data.dateofbirth) and checkHeightFormat(data.height) then
|
||||||
|
TriggerEvent('esx_identity:completedRegistration', source, data)
|
||||||
|
cb(true)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user