From 0603076be309fefe4a4464a629e0560fb35adce1 Mon Sep 17 00:00:00 2001 From: GhzGarage Date: Thu, 8 Jul 2021 19:54:57 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9A=A0=EF=B8=8F=E2=9A=A0=EF=B8=8F=20Steam=20?= =?UTF-8?q?Ditch=20=E2=9A=A0=EF=B8=8F=E2=9A=A0=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.lua | 1 - qbcore.sql | 20 ++++++++-------- server/events.lua | 17 +++++++------- server/functions.lua | 56 +++++++++++++++++++++++--------------------- server/player.lua | 9 +++---- 5 files changed, 50 insertions(+), 53 deletions(-) diff --git a/config.lua b/config.lua index f4d27bc..fe7cbed 100644 --- a/config.lua +++ b/config.lua @@ -1,7 +1,6 @@ QBConfig = {} QBConfig.MaxPlayers = GetConvarInt('sv_maxclients', 64) -- Gets max players from config file, default 32 -QBConfig.IdentifierType = "steam" -- Set the identifier type (can be: steam, license) QBConfig.DefaultSpawn = vector4(-1035.71, -2731.87, 12.86, 0.0) QBConfig.Money = {} diff --git a/qbcore.sql b/qbcore.sql index f8be623..d352dab 100644 --- a/qbcore.sql +++ b/qbcore.sql @@ -1,8 +1,8 @@ CREATE TABLE IF NOT EXISTS `players` ( - `#` int(11) NOT NULL AUTO_INCREMENT, + `id` int(11) NOT NULL AUTO_INCREMENT, `citizenid` varchar(255) NOT NULL, `cid` int(11) DEFAULT NULL, - `steam` varchar(255) NOT NULL, + `license` varchar(255) NOT NULL, `license` varchar(255) NOT NULL, `name` varchar(255) NOT NULL, `money` text NOT NULL, @@ -13,26 +13,26 @@ CREATE TABLE IF NOT EXISTS `players` ( `metadata` text NOT NULL, `inventory` longtext DEFAULT NULL, `last_updated` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), - PRIMARY KEY (`#`), + PRIMARY KEY (`id`), KEY `citizenid` (`citizenid`), KEY `last_updated` (`last_updated`), - KEY `steam` (`steam`) + KEY `license` (`license`) ) ENGINE=InnoDB AUTO_INCREMENT=4189 DEFAULT CHARSET=latin1; CREATE TABLE IF NOT EXISTS `permissions` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, - `steam` varchar(255) NOT NULL, + `license` varchar(255) NOT NULL, `license` varchar(255) NOT NULL, `permission` varchar(255) NOT NULL, PRIMARY KEY (`id`), - KEY `steam` (`steam`) + KEY `license` (`license`) ) ENGINE=InnoDB AUTO_INCREMENT=54 DEFAULT CHARSET=latin1; CREATE TABLE IF NOT EXISTS `bans` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(50) DEFAULT NULL, - `steam` varchar(50) DEFAULT NULL, + `license` varchar(50) DEFAULT NULL, `license` varchar(50) DEFAULT NULL, `discord` varchar(50) DEFAULT NULL, `ip` varchar(50) DEFAULT NULL, @@ -40,17 +40,17 @@ CREATE TABLE IF NOT EXISTS `bans` ( `expire` int(11) DEFAULT NULL, `bannedby` varchar(255) NOT NULL DEFAULT 'LeBanhammer', PRIMARY KEY (`id`), - KEY `steam` (`steam`), + KEY `license` (`license`), KEY `license` (`license`), KEY `discord` (`discord`), KEY `ip` (`ip`) ) ENGINE=InnoDB AUTO_INCREMENT=518 DEFAULT CHARSET=utf8mb4; CREATE TABLE IF NOT EXISTS `whitelist` ( - `steam` varchar(255) NOT NULL, + `license` varchar(255) NOT NULL, `license` varchar(255) NOT NULL, `name` varchar(255) NOT NULL, - PRIMARY KEY (`steam`), + PRIMARY KEY (`license`), UNIQUE KEY `identifier` (`license`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; diff --git a/server/events.lua b/server/events.lua index 52e388d..9499153 100644 --- a/server/events.lua +++ b/server/events.lua @@ -16,18 +16,18 @@ end) local function OnPlayerConnecting(name, setKickReason, deferrals) local player = source - local steamIdentifier + local license local identifiers = GetPlayerIdentifiers(player) deferrals.defer() -- mandatory wait! Wait(0) - deferrals.update(string.format("Hello %s. Your Steam ID is being checked.", name)) + deferrals.update(string.format("Hello %s. Validating Your Rockstar License", name)) for _, v in pairs(identifiers) do - if string.find(v, "steam") then - steamIdentifier = v + if string.find(v, 'license') then + license = v break end end @@ -43,8 +43,8 @@ local function OnPlayerConnecting(name, setKickReason, deferrals) deferrals.update(string.format("Welcome %s to {Server Name}.", name)) - if not steamIdentifier then - deferrals.done("You are not connected to Steam.") + if not license then + deferrals.done('No Valid Rockstar License Found') elseif isBanned then deferrals.done(Reason) else @@ -231,11 +231,10 @@ AddEventHandler('QBCore:ToggleDuty', function() end) Citizen.CreateThread(function() - QBCore.Functions.ExecuteSql(true, "SELECT * FROM `permissions`", function(result) + exports.ghmattimysql:execute('SELECT * FROM permissions', function(result) if result[1] ~= nil then for k, v in pairs(result) do - QBCore.Config.Server.PermissionList[v.steam] = { - steam = v.steam, + QBCore.Config.Server.PermissionList[v.license] = { license = v.license, permission = v.permission, optin = true, diff --git a/server/functions.lua b/server/functions.lua index 97b4ceb..1f7b941 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -149,11 +149,11 @@ QBCore.Functions.IsWhitelisted = function(source) local identifiers = GetPlayerIdentifiers(source) local rtn = false if (QBCore.Config.Server.whitelist) then - QBCore.Functions.ExecuteSql(true, "SELECT * FROM `whitelist` WHERE `"..QBCore.Config.IdentifierType.."` = '".. QBCore.Functions.GetIdentifier(source).."'", function(result) + exports['ghmattimysql']:execute('SELECT * FROM whitelist WHERE license=@license', {['@license'] = QBCore.Functions.GetIdentifier(source, 'license')}, function(result) local data = result[1] if data ~= nil then for _, id in pairs(identifiers) do - if data.steam == id or data.license == id then + if data.license == id then rtn = true end end @@ -168,13 +168,18 @@ end QBCore.Functions.AddPermission = function(source, permission) local Player = QBCore.Functions.GetPlayer(source) if Player ~= nil then - QBCore.Config.Server.PermissionList[GetPlayerIdentifiers(source)[1]] = { - steam = GetPlayerIdentifiers(source)[1], - license = GetPlayerIdentifiers(source)[2], + QBCore.Config.Server.PermissionList[QBCore.Functions.GetIdentifier(source, 'license')] = { + license = QBCore.Functions.GetIdentifier(source, 'license'), permission = permission:lower(), } - QBCore.Functions.ExecuteSql(true, "DELETE FROM `permissions` WHERE `steam` = '"..GetPlayerIdentifiers(source)[1].."'") - QBCore.Functions.ExecuteSql(true, "INSERT INTO `permissions` (`name`, `steam`, `license`, `permission`) VALUES ('"..GetPlayerName(source).."', '"..GetPlayerIdentifiers(source)[1].."', '"..GetPlayerIdentifiers(source)[2].."', '"..permission:lower().."')") + exports['ghmattimysql']:execute('DELETE FROM permissions WHERE license=@license', {['@license'] = QBCore.Functions.GetIdentifier(source, 'license')}) + + exports['ghmattimysql']:execute('INSERT INTO permissions (name, license, permission) VALUES (@name, @license, @permission)', { + ['@name'] = GetPlayerName(source), + ['@license'] = QBCore.Functions.GetIdentifier(source, 'license'), + ['@permission'] = permission:lower() + }) + Player.Functions.UpdatePlayerData() TriggerClientEvent('QBCore:Client:OnPermissionUpdate', source, permission) end @@ -183,23 +188,22 @@ end QBCore.Functions.RemovePermission = function(source) local Player = QBCore.Functions.GetPlayer(source) if Player ~= nil then - QBCore.Config.Server.PermissionList[GetPlayerIdentifiers(source)[1]] = nil - QBCore.Functions.ExecuteSql(true, "DELETE FROM `permissions` WHERE `steam` = '"..GetPlayerIdentifiers(source)[1].."'") + QBCore.Config.Server.PermissionList[QBCore.Functions.GetIdentifier(source, 'license')] = nil + exports['ghmattimysql']:execute('DELETE FROM permissions WHERE license=@license', {['@license'] = QBCore.Functions.GetIdentifier(source, 'license')}) Player.Functions.UpdatePlayerData() end end QBCore.Functions.HasPermission = function(source, permission) local retval = false - local steamid = GetPlayerIdentifiers(source)[1] - local licenseid = GetPlayerIdentifiers(source)[2] + local license = QBCore.Functions.GetIdentifier(source, 'license') local permission = tostring(permission:lower()) if permission == "user" then retval = true else - if QBCore.Config.Server.PermissionList[steamid] ~= nil then - if QBCore.Config.Server.PermissionList[steamid].steam == steamid and QBCore.Config.Server.PermissionList[steamid].license == licenseid then - if QBCore.Config.Server.PermissionList[steamid].permission == permission or QBCore.Config.Server.PermissionList[steamid].permission == "god" then + if QBCore.Config.Server.PermissionList[license] ~= nil then + if QBCore.Config.Server.PermissionList[license].license == license then + if QBCore.Config.Server.PermissionList[license].permission == permission or QBCore.Config.Server.PermissionList[license].permission == "god" then retval = true end end @@ -211,12 +215,11 @@ end QBCore.Functions.GetPermission = function(source) local retval = "user" Player = QBCore.Functions.GetPlayer(source) - local steamid = GetPlayerIdentifiers(source)[1] - local licenseid = GetPlayerIdentifiers(source)[2] + local license = QBCore.Functions.GetIdentifier(source, 'license') if Player ~= nil then - if QBCore.Config.Server.PermissionList[Player.PlayerData.steam] ~= nil then - if QBCore.Config.Server.PermissionList[Player.PlayerData.steam].steam == steamid and QBCore.Config.Server.PermissionList[Player.PlayerData.steam].license == licenseid then - retval = QBCore.Config.Server.PermissionList[Player.PlayerData.steam].permission + if QBCore.Config.Server.PermissionList[Player.PlayerData.license] ~= nil then + if QBCore.Config.Server.PermissionList[Player.PlayerData.license].license == license then + retval = QBCore.Config.Server.PermissionList[Player.PlayerData.license].permission end end end @@ -225,34 +228,33 @@ end QBCore.Functions.IsOptin = function(source) local retval = false - local steamid = GetPlayerIdentifiers(source)[1] + local license = QBCore.Functions.GetIdentifier(source, 'license') if QBCore.Functions.HasPermission(source, "admin") then - retval = QBCore.Config.Server.PermissionList[steamid].optin + retval = QBCore.Config.Server.PermissionList[license].optin end return retval end QBCore.Functions.ToggleOptin = function(source) - local steamid = GetPlayerIdentifiers(source)[1] + local license = QBCore.Functions.GetIdentifier(source, 'license') if QBCore.Functions.HasPermission(source, "admin") then - QBCore.Config.Server.PermissionList[steamid].optin = not QBCore.Config.Server.PermissionList[steamid].optin + QBCore.Config.Server.PermissionList[license].optin = not QBCore.Config.Server.PermissionList[license].optin end end QBCore.Functions.IsPlayerBanned = function (source) local retval = false local message = "" - QBCore.Functions.ExecuteSql(true, "SELECT * FROM `bans` WHERE `steam` = '"..GetPlayerIdentifiers(source)[1].."' OR `license` = '"..GetPlayerIdentifiers(source)[2].."' OR `ip` = '"..GetPlayerIdentifiers(source)[3].."'", function(result) + exports['ghmattimysql']:execute('SELECT * FROM bans WHERE license=@license', {['@license'] = QBCore.Functions.GetIdentifier(source, 'license')}, function(result) if result[1] ~= nil then if os.time() < result[1].expire then retval = true local timeTable = os.date("*t", tonumber(result[1].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 - QBCore.Functions.ExecuteSql(true, "DELETE FROM `bans` WHERE `id` = "..result[1].id) + exports['ghmattimysql']:execute('DELETE FROM bans WHERE id=@id', {['@id'] = result[1].id}) end end end) return retval, message -end - +end \ No newline at end of file diff --git a/server/player.lua b/server/player.lua index 1a58359..e34b877 100644 --- a/server/player.lua +++ b/server/player.lua @@ -35,8 +35,7 @@ QBCore.Player.CheckPlayerData = function(source, PlayerData) PlayerData.source = source PlayerData.citizenid = PlayerData.citizenid ~= nil and PlayerData.citizenid or QBCore.Player.CreateCitizenId() - PlayerData.steam = PlayerData.steam ~= nil and PlayerData.steam or QBCore.Functions.GetIdentifier(source, "steam") - PlayerData.license = PlayerData.license ~= nil and PlayerData.license or QBCore.Functions.GetIdentifier(source, "license") + PlayerData.license = PlayerData.license ~= nil and PlayerData.license or QBCore.Functions.GetIdentifier(source, 'license') PlayerData.name = GetPlayerName(source) PlayerData.cid = PlayerData.cid ~= nil and PlayerData.cid or 1 @@ -420,10 +419,9 @@ QBCore.Player.Save = function(source) if PlayerData ~= nil then QBCore.Functions.ExecuteSql(true, "SELECT * FROM `players` WHERE `citizenid` = '"..PlayerData.citizenid.."'", function(result) if result[1] == nil then - exports.ghmattimysql:execute('INSERT INTO players (citizenid, cid, steam, license, name, money, charinfo, job, gang, position, metadata) VALUES (@citizenid, @cid, @steam, @license, @name, @money, @charinfo, @job, @gang, @position, @metadata)', { + exports.ghmattimysql:execute('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), - ['@steam'] = PlayerData.steam, ['@license'] = PlayerData.license, ['@name'] = PlayerData.name, ['@money'] = json.encode(PlayerData.money), @@ -434,9 +432,8 @@ QBCore.Player.Save = function(source) ['@metadata'] = json.encode(PlayerData.metadata) }) else - exports.ghmattimysql:execute('UPDATE players SET steam=@steam, license=@license, name=@name, money=@money, charinfo=@charinfo, job=@job, gang=@gang, position=@position, metadata=@metadata WHERE citizenid=@citizenid', { + exports.ghmattimysql: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, - ['@steam'] = PlayerData.steam, ['@license'] = PlayerData.license, ['@name'] = PlayerData.name, ['@money'] = json.encode(PlayerData.money),