Merge branch 'main' into main

This commit is contained in:
Zerio
2024-07-15 04:55:14 +02:00
committed by GitHub
5 changed files with 917 additions and 711 deletions
+23
View File
@@ -27,6 +27,21 @@ AddEventHandler("onResourceStop", function(resName)
end)
-- Player Connecting
local readyFunction = MySQL.ready
local databaseConnected, bansTableExists = readyFunction == nil, readyFunction == nil
if readyFunction ~= nil then
MySQL.ready(function()
databaseConnected = true
local DatabaseInfo = QBCore.Functions.GetDatabaseInfo()
if not DatabaseInfo or not DatabaseInfo.exists then return end
local result = MySQL.query.await('SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ? AND TABLE_NAME = "bans";', {DatabaseInfo.database})
if result and result[1] then
bansTableExists = true
end
end)
end
local function onPlayerConnecting(name, _, deferrals)
local src = source
@@ -36,6 +51,10 @@ local function onPlayerConnecting(name, _, deferrals)
return deferrals.done(QBCore.Config.Server.ClosedReason)
end
if not databaseConnected then
return deferrals.done(Lang:t('error.connecting_database_error'))
end
if QBCore.Config.Server.Whitelist then
Wait(0)
deferrals.update(string.format(Lang:t('info.checking_whitelisted'), name))
@@ -57,6 +76,10 @@ local function onPlayerConnecting(name, _, deferrals)
Wait(0)
deferrals.update(string.format(Lang:t('info.checking_ban'), name))
if not bansTableExists then
return deferrals.done(Lang:t('error.ban_table_not_found'))
end
local success, isBanned, reason = pcall(QBCore.Functions.IsPlayerBanned, src)
if not success then return deferrals.done(Lang:t('error.connecting_database_error')) end
if isBanned then return deferrals.done(reason) end
+30
View File
@@ -642,6 +642,36 @@ function QBCore.Functions.IsPlayerBanned(source)
return false
end
-- Retrieves information about the database connection.
--- @return table; A table containing the database information.
function QBCore.Functions.GetDatabaseInfo()
local details = {
exists = false,
database = "",
}
local connectionString = GetConvar("mysql_connection_string", "")
if connectionString == "" then
return details
elseif connectionString:find("mysql://") then
connectionString = connectionString:sub(9, -1)
details.database = connectionString:sub(connectionString:find("/") + 1, -1):gsub("[%?]+[%w%p]*$", "")
details.exists = true
return details
else
connectionString = { string.strsplit(";", connectionString) }
for i = 1, #connectionString do
local v = connectionString[i]
if v:match("database") then
details.database = v:sub(10, #v)
details.exists = true
return details
end
end
end
end
---Check for duplicate license
---@param license any
---@return boolean