diff --git a/server/events.lua b/server/events.lua index c91366c..d373cfa 100644 --- a/server/events.lua +++ b/server/events.lua @@ -306,9 +306,9 @@ end) RegisterServerEvent('QBCore:Command:CheckOwnedVehicle') AddEventHandler('QBCore:Command:CheckOwnedVehicle', function(VehiclePlate) if VehiclePlate ~= nil then - local result = exports.oxmysql:fetchSync('SELECT * FROM player_vehicles WHERE plate=@plate', {['@plate'] = VehiclePlate}) + local result = exports.oxmysql:fetchSync('SELECT * FROM player_vehicles WHERE plate = ?', { VehiclePlate }) if result[1] ~= nil then - exports.oxmysql:execute('UPDATE player_vehicles SET state=@state WHERE citizenid=@citizenid', {['@state'] = 1, ['@citizenid'] = result[1].citizenid}) + exports.oxmysql:execute('UPDATE player_vehicles SET state = ? WHERE citizenid = ?', { 1, result[1].citizenid }) TriggerEvent('qb-garages:server:RemoveVehicle', result[1].citizenid, VehiclePlate) end end diff --git a/server/functions.lua b/server/functions.lua index 605700b..67e28cb 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -128,7 +128,7 @@ QBCore.Functions.IsWhitelisted = function(source) local identifiers = GetPlayerIdentifiers(source) local rtn = false if (QBCore.Config.Server.whitelist) then - local result = exports.oxmysql:fetchSync('SELECT * FROM whitelist WHERE license=@license', {['@license'] = QBCore.Functions.GetIdentifier(source, 'license')}) + local result = exports.oxmysql:fetchSync('SELECT * FROM whitelist WHERE license = ?', { QBCore.Functions.GetIdentifier(source, 'license') }) local data = result[1] if data ~= nil then for _, id in pairs(identifiers) do @@ -150,12 +150,12 @@ QBCore.Functions.AddPermission = function(source, permission) license = QBCore.Functions.GetIdentifier(source, 'license'), permission = permission:lower(), } - exports.oxmysql:execute('DELETE FROM permissions WHERE license=@license', {['@license'] = QBCore.Functions.GetIdentifier(source, 'license')}) + exports.oxmysql:execute('DELETE FROM permissions WHERE license = ?', { QBCore.Functions.GetIdentifier(source, 'license') }) - exports.oxmysql:insert('INSERT INTO permissions (name, license, permission) VALUES (@name, @license, @permission)', { - ['@name'] = GetPlayerName(source), - ['@license'] = QBCore.Functions.GetIdentifier(source, 'license'), - ['@permission'] = permission:lower() + exports.oxmysql:insert('INSERT INTO permissions (name, license, permission) VALUES (?)', { + GetPlayerName(source), + QBCore.Functions.GetIdentifier(source, 'license'), + permission:lower() }) Player.Functions.UpdatePlayerData() @@ -167,7 +167,7 @@ QBCore.Functions.RemovePermission = function(source) local Player = QBCore.Functions.GetPlayer(source) if Player ~= nil then QBCore.Config.Server.PermissionList[QBCore.Functions.GetIdentifier(source, 'license')] = nil - exports.oxmysql:execute('DELETE FROM permissions WHERE license=@license', {['@license'] = QBCore.Functions.GetIdentifier(source, 'license')}) + exports.oxmysql:execute('DELETE FROM permissions WHERE license = ?', { QBCore.Functions.GetIdentifier(source, 'license') }) Player.Functions.UpdatePlayerData() end end @@ -223,14 +223,14 @@ end QBCore.Functions.IsPlayerBanned = function (source) local retval = false local message = "" - local result = exports.oxmysql:fetchSync('SELECT * FROM bans WHERE license=@license', {['@license'] = QBCore.Functions.GetIdentifier(source, 'license')}) + local result = exports.oxmysql:fetchSync('SELECT * FROM bans WHERE license = ?', { QBCore.Functions.GetIdentifier(source, 'license') }) if result[1] ~= nil then if os.time() < result[1].expire then retval = true local timeTable = os.date("*t", tonumber(result.expire)) message = "You have been banned from the server:\n"..result[1].reason.."\nYour ban expires "..timeTable.day.. "/" .. timeTable.month .. "/" .. timeTable.year .. " " .. timeTable.hour.. ":" .. timeTable.min .. "\n" else - exports.oxmysql:execute('DELETE FROM bans WHERE id=@id', {['@id'] = result[1].id}) + exports.oxmysql:execute('DELETE FROM bans WHERE id = ?', { result[1].id }) end end return retval, message diff --git a/server/player.lua b/server/player.lua index b37a26f..8722ebf 100644 --- a/server/player.lua +++ b/server/player.lua @@ -4,7 +4,7 @@ QBCore.Player = {} QBCore.Player.Login = function(source, citizenid, newData) if source ~= nil then if citizenid then - local result = exports.oxmysql:fetchSync('SELECT * FROM players WHERE citizenid=@citizenid', {['@citizenid'] = citizenid}) + local result = exports.oxmysql:fetchSync('SELECT * FROM players WHERE citizenid = ?', { citizenid }) local PlayerData = result[1] if PlayerData ~= nil then PlayerData.money = json.decode(PlayerData.money) @@ -439,31 +439,32 @@ end QBCore.Player.Save = function(source) local PlayerData = QBCore.Players[source].PlayerData if PlayerData ~= nil then - local result = exports.oxmysql:fetchSync('SELECT * FROM players WHERE citizenid=@citizenid', {['@citizenid'] = PlayerData.citizenid}) + -- TODO: Merge these 3 queries into 1 with an on duplicate (citizenid isn't primary so https://stackoverflow.com/a/33495408/3200040 might need to be used) + local result = exports.oxmysql:fetchSync('SELECT * FROM players WHERE citizenid = ?', { PlayerData.citizenid }) if result[1] == nil then - exports.oxmysql:insert('INSERT INTO players (citizenid, cid, license, name, money, charinfo, job, gang, position, metadata) VALUES (@citizenid, @cid, @license, @name, @money, @charinfo, @job, @gang, @position, @metadata)', { - ['@citizenid'] = PlayerData.citizenid, - ['@cid'] = tonumber(PlayerData.cid), - ['@license'] = PlayerData.license, - ['@name'] = PlayerData.name, - ['@money'] = json.encode(PlayerData.money), - ['@charinfo'] = json.encode(PlayerData.charinfo), - ['@job'] = json.encode(PlayerData.job), - ['@gang'] = json.encode(PlayerData.gang), - ['@position'] = json.encode(PlayerData.position), - ['@metadata'] = json.encode(PlayerData.metadata) + exports.oxmysql:insert('INSERT INTO players (citizenid, cid, license, name, money, charinfo, job, gang, position, metadata) VALUES (?)', { + PlayerData.citizenid, + tonumber(PlayerData.cid), + PlayerData.license, + PlayerData.name, + json.encode(PlayerData.money), + json.encode(PlayerData.charinfo), + json.encode(PlayerData.job), + json.encode(PlayerData.gang), + json.encode(PlayerData.position), + json.encode(PlayerData.metadata) }) else - exports.oxmysql:execute('UPDATE players SET license=@license, name=@name, money=@money, charinfo=@charinfo, job=@job, gang=@gang, position=@position, metadata=@metadata WHERE citizenid=@citizenid', { - ['@citizenid'] = PlayerData.citizenid, - ['@license'] = PlayerData.license, - ['@name'] = PlayerData.name, - ['@money'] = json.encode(PlayerData.money), - ['@charinfo'] = json.encode(PlayerData.charinfo), - ['@job'] = json.encode(PlayerData.job), - ['@gang'] = json.encode(PlayerData.gang), - ['@position'] = json.encode(PlayerData.position), - ['@metadata'] = json.encode(PlayerData.metadata) + exports.oxmysql:execute('UPDATE players SET license = ?, name = ?, money = ?, charinfo = ?, job = ?, gang = ?, position = ?, metadata = ? WHERE citizenid = ?', { + PlayerData.license, + PlayerData.name, + json.encode(PlayerData.money), + json.encode(PlayerData.charinfo), + json.encode(PlayerData.job), + json.encode(PlayerData.gang), + json.encode(PlayerData.position), + json.encode(PlayerData.metadata), + PlayerData.citizenid }) end QBCore.Player.SaveInventory(source) @@ -498,10 +499,10 @@ local playertables = { QBCore.Player.DeleteCharacter = function(source, citizenid) local license = QBCore.Functions.GetIdentifier(source, 'license') - local result = exports.oxmysql:scalarSync('SELECT license FROM players where citizenid = ?', {citizenid}) + local result = exports.oxmysql:scalarSync('SELECT license FROM players where citizenid = ?', { citizenid }) if license == result then for k,v in pairs(playertables) do - exports.oxmysql:execute('DELETE FROM '..v.table..' WHERE citizenid = ?', {citizenid}) + exports.oxmysql:execute('DELETE FROM '..v.table..' WHERE citizenid = ?', { citizenid }) end TriggerEvent("qb-log:server:CreateLog", "joinleave", "Character Deleted", "red", "**".. GetPlayerName(source) .. "** ("..QBCore.Functions.GetIdentifier(source, 'license')..") deleted **"..citizenid.."**..") else @@ -512,7 +513,7 @@ end QBCore.Player.LoadInventory = function(PlayerData) PlayerData.items = {} - local result = exports.oxmysql:fetchSync('SELECT * FROM players WHERE citizenid=@citizenid', {['@citizenid'] = PlayerData.citizenid}) + local result = exports.oxmysql:fetchSync('SELECT * FROM players WHERE citizenid = ?', { PlayerData.citizenid }) if result[1] ~= nil then if result[1].inventory ~= nil then plyInventory = json.decode(result[1].inventory) @@ -562,9 +563,9 @@ QBCore.Player.SaveInventory = function(source) }) end end - exports.oxmysql:execute('UPDATE players SET inventory=@inventory WHERE citizenid=@citizenid', {['@inventory'] = json.encode(ItemsJson), ['@citizenid'] = PlayerData.citizenid}) + exports.oxmysql:execute('UPDATE players SET inventory = ? WHERE citizenid = ?', { json.encode(ItemsJson), PlayerData.citizenid }) else - exports.oxmysql:execute('UPDATE players SET inventory=@inventory WHERE citizenid=@citizenid', {['@inventory'] = '[]', ['@citizenid'] = PlayerData.citizenid}) + exports.oxmysql:execute('UPDATE players SET inventory = ? WHERE citizenid = ?', { '[]', PlayerData.citizenid }) end end end @@ -608,7 +609,7 @@ QBCore.Player.CreateCitizenId = function() while not UniqueFound do CitizenId = tostring(QBCore.Shared.RandomStr(3) .. QBCore.Shared.RandomInt(5)):upper() - local result = exports.oxmysql:fetchSync('SELECT COUNT(*) as count FROM players WHERE citizenid=@citizenid', {['@citizenid'] = CitizenId}) + local result = exports.oxmysql:fetchSync('SELECT COUNT(*) as count FROM players WHERE citizenid = ?', { CitizenId }) if result[1].count == 0 then UniqueFound = true end @@ -622,7 +623,7 @@ QBCore.Player.CreateFingerId = function() while not UniqueFound do FingerId = tostring(QBCore.Shared.RandomStr(2) .. QBCore.Shared.RandomInt(3) .. QBCore.Shared.RandomStr(1) .. QBCore.Shared.RandomInt(2) .. QBCore.Shared.RandomStr(3) .. QBCore.Shared.RandomInt(4)) local query = '%'..FingerId..'%' - local result = exports.oxmysql:fetchSync('SELECT COUNT(*) as count FROM `players` WHERE `metadata` LIKE @query', {['@query'] = query}) + local result = exports.oxmysql:fetchSync('SELECT COUNT(*) as count FROM `players` WHERE `metadata` LIKE ?', { query }) if result[1].count == 0 then UniqueFound = true end @@ -636,7 +637,7 @@ QBCore.Player.CreateWalletId = function() while not UniqueFound do WalletId = "QB-"..math.random(11111111, 99999999) local query = '%'..WalletId..'%' - local result = exports.oxmysql:fetchSync('SELECT COUNT(*) as count FROM players WHERE metadata LIKE @query', {['@query'] = query}) + local result = exports.oxmysql:fetchSync('SELECT COUNT(*) as count FROM players WHERE metadata LIKE ?', { query }) if result[1].count == 0 then UniqueFound = true end @@ -651,7 +652,7 @@ QBCore.Player.CreateSerialNumber = function() while not UniqueFound do SerialNumber = math.random(11111111, 99999999) local query = '%'..SerialNumber..'%' - local result = exports.oxmysql:fetchSync('SELECT COUNT(*) as count FROM players WHERE metadata LIKE @query', {['@query'] = query}) + local result = exports.oxmysql:fetchSync('SELECT COUNT(*) as count FROM players WHERE metadata LIKE ?', { query }) if result[1].count == 0 then UniqueFound = true end @@ -659,9 +660,4 @@ QBCore.Player.CreateSerialNumber = function() return SerialNumber end -QBCore.EscapeSqli = function(str) - local replacements = { ['"'] = '\\"', ["'"] = "\\'" } - return str:gsub( "['\"]", replacements ) -- or string.gsub( source, "['\"]", replacements ) -end - PaycheckLoop()