mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-04 08:13:21 +00:00
Merge pull request #922 from Sub-Zero-Interactive/test
Feat/Fix(es_extended & esx_multicharacter): Added Validations + bug fixes
This commit is contained in:
@@ -406,6 +406,15 @@ function ESX.Game.SpawnVehicle(vehicle, coords, heading, cb, networked)
|
||||
local model = type(vehicle) == 'number' and vehicle or joaat(vehicle)
|
||||
local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z)
|
||||
networked = networked or true
|
||||
local playerCoords = GetEntityCoords(ESX.PlayerData.ped)
|
||||
if not vector or not playerCoords then
|
||||
return
|
||||
end
|
||||
local dist = #(playerCoords - vector)
|
||||
if dist > 424 then -- Onesync infinity Range (https://docs.fivem.net/docs/scripting-reference/onesync/)
|
||||
local executingResource = GetInvokingResource() or "Unknown"
|
||||
return print(("[^1ERROR^7] Resource ^5%s^7 Tried to spawn vehicle on the client but the position is too far away (Out of onesync range)."):format(executing_resource))
|
||||
end
|
||||
CreateThread(function()
|
||||
ESX.Streaming.RequestModel(model)
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ Config.EnableDefaultInventory = true -- Display the default Inventory ( F2 )
|
||||
Config.EnableWantedLevel = false -- Use Normal GTA wanted Level?
|
||||
Config.EnablePVP = true -- Allow Player to player combat
|
||||
|
||||
Config.Multichar = true -- Enable support for esx_multicharacter
|
||||
Config.Multichar = GetResourceState("esx_multicharacter") ~= "missing"
|
||||
Config.Identity = true -- Select a characters identity data before they have loaded in (this happens by default with multichar)
|
||||
Config.DistanceGive = 4.0 -- Max distance when giving items, weapons etc.
|
||||
|
||||
|
||||
@@ -74,8 +74,7 @@ files {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
'/server:5949',
|
||||
'/onesync',
|
||||
'/native:0x6AE51D4B',
|
||||
'oxmysql',
|
||||
'spawnmanager',
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ Core.RegisteredCommands = {}
|
||||
Core.Pickups = {}
|
||||
Core.PickupId = 0
|
||||
Core.PlayerFunctionOverrides = {}
|
||||
|
||||
Core.DatabaseConnected = false
|
||||
Core.playersByIdentifier = {}
|
||||
|
||||
Core.vehicleTypesByModel = {}
|
||||
@@ -39,6 +39,7 @@ local function StartDBSync()
|
||||
end
|
||||
|
||||
MySQL.ready(function()
|
||||
Core.DatabaseConnected = true
|
||||
if not Config.OxInventory then
|
||||
local items = MySQL.query.await('SELECT * FROM items')
|
||||
for k, v in ipairs(items) do
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
SetMapName('San Andreas')
|
||||
SetGameType('ESX Legacy')
|
||||
|
||||
local oneSyncState = GetConvar('onesync', 'off')
|
||||
local newPlayer = 'INSERT INTO `users` SET `accounts` = ?, `identifier` = ?, `group` = ?'
|
||||
local loadPlayer = 'SELECT `accounts`, `job`, `job_grade`, `group`, `position`, `inventory`, `skin`, `loadout`, `meta`'
|
||||
|
||||
@@ -55,6 +56,7 @@ function onPlayerJoined(playerId)
|
||||
if result then
|
||||
loadESXPlayer(identifier, playerId, false)
|
||||
else
|
||||
|
||||
createESXPlayer(identifier, playerId)
|
||||
end
|
||||
end
|
||||
@@ -95,16 +97,24 @@ if not Config.Multichar then
|
||||
local playerId = source
|
||||
local identifier = ESX.GetIdentifier(playerId)
|
||||
|
||||
if oneSyncState == "off" or oneSyncState == "legacy" then
|
||||
return deferrals.done(('[ESX] ESX Requires Onesync Infinity to work. This server currently has Onesync set to: %s'):format(oneSyncState))
|
||||
end
|
||||
|
||||
if not Core.DatabaseConnected then
|
||||
return deferrals.done(('[ESX] ESX Cannot Connect to your database. Please make sure it is correctly configured in your server.cfg'):format(oneSyncState))
|
||||
end
|
||||
|
||||
if identifier then
|
||||
if ESX.GetPlayerFromIdentifier(identifier) then
|
||||
deferrals.done(
|
||||
return deferrals.done(
|
||||
('[ESX] There was an error loading your character!\nError code: identifier-active\n\nThis error is caused by a player on this server who has the same identifier as you have. Make sure you are not playing on the same account.\n\nYour identifier: %s'):format(
|
||||
identifier))
|
||||
else
|
||||
deferrals.done()
|
||||
return deferrals.done()
|
||||
end
|
||||
else
|
||||
deferrals.done(
|
||||
return deferrals.done(
|
||||
'[ESX] There was an error loading your character!\nError code: identifier-missing\n\nThe cause of this error is not known, your identifier could not be found. Please come back later or report this problem to the server administration team.')
|
||||
end
|
||||
end)
|
||||
|
||||
@@ -1,23 +1,26 @@
|
||||
if not ESX then
|
||||
error('\n^1Unable to start Multicharacter - you must be using ESX Legacy^0')
|
||||
elseif ESX.GetConfig().Multichar then
|
||||
local DATABASE do
|
||||
local connectionString = GetConvar('mysql_connection_string', '');
|
||||
if connectionString == '' then
|
||||
error(connectionString..'\n^1Unable to start Multicharacter - unable to determine database from mysql_connection_string^0', 0)
|
||||
elseif connectionString:find('mysql://') then
|
||||
connectionString = connectionString:sub(9, -1)
|
||||
DATABASE = connectionString:sub(connectionString:find('/')+1, -1):gsub('[%?]+[%w%p]*$', '')
|
||||
else
|
||||
connectionString = {string.strsplit(';', connectionString)}
|
||||
for i = 1, #connectionString do
|
||||
local v = connectionString[i]
|
||||
if v:match('database') then
|
||||
DATABASE = v:sub(10, #v)
|
||||
end
|
||||
local databaseConnected = false
|
||||
local databaseFound = false
|
||||
local oneSyncState = GetConvar('onesync', 'off')
|
||||
|
||||
local DATABASE do
|
||||
local connectionString = GetConvar('mysql_connection_string', '');
|
||||
if connectionString == '' then
|
||||
error(connectionString..'\n^1Unable to start Multicharacter - unable to determine database from mysql_connection_string^0', 0)
|
||||
elseif connectionString:find('mysql://') then
|
||||
connectionString = connectionString:sub(9, -1)
|
||||
DATABASE = connectionString:sub(connectionString:find('/')+1, -1):gsub('[%?]+[%w%p]*$', '')
|
||||
databaseFound = true
|
||||
else
|
||||
connectionString = {string.strsplit(';', connectionString)}
|
||||
for i = 1, #connectionString do
|
||||
local v = connectionString[i]
|
||||
if v:match('database') then
|
||||
DATABASE = v:sub(10, #v)
|
||||
end
|
||||
end
|
||||
databaseFound = true
|
||||
end
|
||||
end
|
||||
|
||||
local DB_TABLES = {users = 'identifier'}
|
||||
local FETCH = nil
|
||||
@@ -92,11 +95,23 @@ elseif ESX.GetConfig().Multichar then
|
||||
AddEventHandler('playerConnecting', function(playerName, setKickReason, deferrals)
|
||||
deferrals.defer()
|
||||
local identifier = GetIdentifier(source)
|
||||
if oneSyncState == "off" or oneSyncState == "legacy" then
|
||||
return deferrals.done(('[ESX] ESX Requires Onesync Infinity to work. This server currently has Onesync set to: %s'):format(oneSyncState))
|
||||
end
|
||||
|
||||
if not databaseFound then
|
||||
deferrals.done(('[ESX Multicharacter] Cannot Find the servers mysql_connection_string. Please make sure it is correctly configured in your server.cfg'):format(oneSyncState))
|
||||
end
|
||||
|
||||
if not databaseConnected then
|
||||
deferrals.done(('[ESX Multicharacter] ESX Cannot Connect to your database. Please make sure it is correctly configured in your server.cfg'):format(oneSyncState))
|
||||
end
|
||||
|
||||
if identifier then
|
||||
|
||||
if not ESX.GetConfig().EnableDebug then
|
||||
if ESX.Players[identifier] then
|
||||
deferrals.done(('A player is already connected to the server with this identifier.\nYour identifier: %s:%s'):format(PRIMARY_IDENTIFIER, identifier))
|
||||
deferrals.done(('[ESX Multicharacter] A player is already connected to the server with this identifier.\nYour identifier: %s:%s'):format(PRIMARY_IDENTIFIER, identifier))
|
||||
else
|
||||
deferrals.done()
|
||||
end
|
||||
@@ -141,11 +156,12 @@ elseif ESX.GetConfig().Multichar then
|
||||
local count = 0
|
||||
|
||||
for i = 1, #DB_COLUMNS do
|
||||
local v = DB_COLUMNS[i]
|
||||
local column = DB_COLUMNS[i]
|
||||
DB_TABLES[column.TABLE_NAME] = column.COLUMN_NAME
|
||||
|
||||
if v?.CHARACTER_MAXIMUM_LENGTH ~= length then
|
||||
if column?.CHARACTER_MAXIMUM_LENGTH ~= length then
|
||||
count += 1
|
||||
columns[v.TABLE_NAME] = v.COLUMN_NAME
|
||||
columns[column.TABLE_NAME] = column.COLUMN_NAME
|
||||
end
|
||||
end
|
||||
|
||||
@@ -179,6 +195,7 @@ elseif ESX.GetConfig().Multichar then
|
||||
until next(ESX.Jobs)
|
||||
|
||||
FETCH = 'SELECT identifier, accounts, job, job_grade, firstname, lastname, dateofbirth, sex, skin, disabled FROM users WHERE identifier LIKE ? LIMIT ?'
|
||||
databaseConnected = true
|
||||
end
|
||||
end)
|
||||
|
||||
@@ -219,8 +236,4 @@ elseif ESX.GetConfig().Multichar then
|
||||
RegisterNetEvent('esx_multicharacter:relog', function()
|
||||
local source = source
|
||||
TriggerEvent('esx:playerLogout', source)
|
||||
end)
|
||||
|
||||
else
|
||||
assert(nil, '^3WARNING: Multicharacter is disabled - please check your ESX configuration^0')
|
||||
end
|
||||
end)
|
||||
Reference in New Issue
Block a user