From 8ca8282f2a3b4e9c7e403daeb1b1a64dd905bcdd Mon Sep 17 00:00:00 2001 From: Scullyy <51968381+Scullyy@users.noreply.github.com> Date: Thu, 3 Feb 2022 13:31:48 +0000 Subject: [PATCH 1/4] Prevent duplicated phone and account numbers **Describe Pull request** This will prevent the chance of duplicated phone and account numbers, although the chance is very low it's still a possibility as I have experienced this myself and this will resolve that issue. I feel like this should be implemented as these are meant to be unique for each player. **Questions (please complete the following information):** - Have you personally loaded this code into an updated qbcore project and checked all it's functionality? Yes - Does your code fit the style guidelines? Yes - Does your PR fit the contribution guidelines? Yes --- server/player.lua | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/server/player.lua b/server/player.lua index f9ed6ad..869d8af 100644 --- a/server/player.lua +++ b/server/player.lua @@ -56,9 +56,9 @@ function QBCore.Player.CheckPlayerData(source, PlayerData) PlayerData.charinfo.birthdate = PlayerData.charinfo.birthdate or '00-00-0000' PlayerData.charinfo.gender = PlayerData.charinfo.gender or 0 PlayerData.charinfo.backstory = PlayerData.charinfo.backstory or 'placeholder backstory' - PlayerData.charinfo.nationality = PlayerData.charinfo.nationality or 'USA' - PlayerData.charinfo.phone = PlayerData.charinfo.phone ~= nil and PlayerData.charinfo.phone or '1' .. math.random(111111111, 999999999) - PlayerData.charinfo.account = PlayerData.charinfo.account ~= nil and PlayerData.charinfo.account or 'US0' .. math.random(1, 9) .. 'QBCore' .. math.random(1111, 9999) .. math.random(1111, 9999) .. math.random(11, 99) + PlayerData.charinfo.nationality = PlayerData.charinfo.nationality or 'American' + PlayerData.charinfo.phone = PlayerData.charinfo.phone ~= nil and PlayerData.charinfo.phone or QBCore.Functions.CreatePhoneNumber() + PlayerData.charinfo.account = PlayerData.charinfo.account ~= nil and PlayerData.charinfo.account or QBCore.Functions.CreateAccountNumber() -- Metadata PlayerData.metadata = PlayerData.metadata or {} PlayerData.metadata['hunger'] = PlayerData.metadata['hunger'] or 100 @@ -510,7 +510,6 @@ local playertables = { -- Add tables as needed { table = 'crypto_transactions' }, { table = 'phone_invoices' }, { table = 'phone_messages' }, - { table = 'playerskins' }, { table = 'player_boats' }, { table = 'player_contacts' }, { table = 'player_houses' }, @@ -652,6 +651,34 @@ function QBCore.Player.CreateCitizenId() return CitizenId end +function QBCore.Functions.CreateAccountNumber() + local UniqueFound = false + local AccountNumber = nil + while not UniqueFound do + AccountNumber = 'US0' .. math.random(1, 9) .. 'QBCore' .. math.random(1111, 9999) .. math.random(1111, 9999) .. math.random(11, 99) + local query = '%' .. AccountNumber .. '%' + local result = MySQL.Sync.prepare('SELECT COUNT(*) as count FROM players WHERE metadata LIKE ?', { query }) + if result == 0 then + UniqueFound = true + end + end + return AccountNumber +end + +function QBCore.Functions.CreatePhoneNumber() + local UniqueFound = false + local PhoneNumber = nil + while not UniqueFound do + PhoneNumber = math.random(100,999) .. math.random(1000000,9999999) + local query = '%' .. PhoneNumber .. '%' + local result = MySQL.Sync.prepare('SELECT COUNT(*) as count FROM players WHERE metadata LIKE ?', { query }) + if result == 0 then + UniqueFound = true + end + end + return PhoneNumber +end + function QBCore.Player.CreateFingerId() local UniqueFound = false local FingerId = nil From 6379245963c3c060c6b20024266d68e3ea5146e9 Mon Sep 17 00:00:00 2001 From: Scullyy Date: Thu, 3 Feb 2022 13:44:56 +0000 Subject: [PATCH 2/4] Revert "Prevent duplicated phone and account numbers" This reverts commit 8ca8282f2a3b4e9c7e403daeb1b1a64dd905bcdd. --- server/player.lua | 35 ++++------------------------------- 1 file changed, 4 insertions(+), 31 deletions(-) diff --git a/server/player.lua b/server/player.lua index 869d8af..f9ed6ad 100644 --- a/server/player.lua +++ b/server/player.lua @@ -56,9 +56,9 @@ function QBCore.Player.CheckPlayerData(source, PlayerData) PlayerData.charinfo.birthdate = PlayerData.charinfo.birthdate or '00-00-0000' PlayerData.charinfo.gender = PlayerData.charinfo.gender or 0 PlayerData.charinfo.backstory = PlayerData.charinfo.backstory or 'placeholder backstory' - PlayerData.charinfo.nationality = PlayerData.charinfo.nationality or 'American' - PlayerData.charinfo.phone = PlayerData.charinfo.phone ~= nil and PlayerData.charinfo.phone or QBCore.Functions.CreatePhoneNumber() - PlayerData.charinfo.account = PlayerData.charinfo.account ~= nil and PlayerData.charinfo.account or QBCore.Functions.CreateAccountNumber() + PlayerData.charinfo.nationality = PlayerData.charinfo.nationality or 'USA' + PlayerData.charinfo.phone = PlayerData.charinfo.phone ~= nil and PlayerData.charinfo.phone or '1' .. math.random(111111111, 999999999) + PlayerData.charinfo.account = PlayerData.charinfo.account ~= nil and PlayerData.charinfo.account or 'US0' .. math.random(1, 9) .. 'QBCore' .. math.random(1111, 9999) .. math.random(1111, 9999) .. math.random(11, 99) -- Metadata PlayerData.metadata = PlayerData.metadata or {} PlayerData.metadata['hunger'] = PlayerData.metadata['hunger'] or 100 @@ -510,6 +510,7 @@ local playertables = { -- Add tables as needed { table = 'crypto_transactions' }, { table = 'phone_invoices' }, { table = 'phone_messages' }, + { table = 'playerskins' }, { table = 'player_boats' }, { table = 'player_contacts' }, { table = 'player_houses' }, @@ -651,34 +652,6 @@ function QBCore.Player.CreateCitizenId() return CitizenId end -function QBCore.Functions.CreateAccountNumber() - local UniqueFound = false - local AccountNumber = nil - while not UniqueFound do - AccountNumber = 'US0' .. math.random(1, 9) .. 'QBCore' .. math.random(1111, 9999) .. math.random(1111, 9999) .. math.random(11, 99) - local query = '%' .. AccountNumber .. '%' - local result = MySQL.Sync.prepare('SELECT COUNT(*) as count FROM players WHERE metadata LIKE ?', { query }) - if result == 0 then - UniqueFound = true - end - end - return AccountNumber -end - -function QBCore.Functions.CreatePhoneNumber() - local UniqueFound = false - local PhoneNumber = nil - while not UniqueFound do - PhoneNumber = math.random(100,999) .. math.random(1000000,9999999) - local query = '%' .. PhoneNumber .. '%' - local result = MySQL.Sync.prepare('SELECT COUNT(*) as count FROM players WHERE metadata LIKE ?', { query }) - if result == 0 then - UniqueFound = true - end - end - return PhoneNumber -end - function QBCore.Player.CreateFingerId() local UniqueFound = false local FingerId = nil From ca5383f2d262d4d83908ba8fe7d6ea7dc1bc928b Mon Sep 17 00:00:00 2001 From: Scullyy Date: Thu, 3 Feb 2022 13:48:40 +0000 Subject: [PATCH 3/4] Prevent duplicated phone and account numbers Describe Pull request This will prevent the chance of duplicated phone and account numbers, although the chance is very low it's still a possibility as I have experienced this myself and this will resolve that issue. I feel like this should be implemented as these are meant to be unique for each player. Questions: - Have you personally loaded this code into an updated qbcore project and checked all it's functionality? Yes - Does your code fit the style guidelines? Yes - Does your PR fit the contribution guidelines? Yes --- server/player.lua | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/server/player.lua b/server/player.lua index f9ed6ad..6121334 100644 --- a/server/player.lua +++ b/server/player.lua @@ -57,8 +57,8 @@ function QBCore.Player.CheckPlayerData(source, PlayerData) PlayerData.charinfo.gender = PlayerData.charinfo.gender or 0 PlayerData.charinfo.backstory = PlayerData.charinfo.backstory or 'placeholder backstory' PlayerData.charinfo.nationality = PlayerData.charinfo.nationality or 'USA' - PlayerData.charinfo.phone = PlayerData.charinfo.phone ~= nil and PlayerData.charinfo.phone or '1' .. math.random(111111111, 999999999) - PlayerData.charinfo.account = PlayerData.charinfo.account ~= nil and PlayerData.charinfo.account or 'US0' .. math.random(1, 9) .. 'QBCore' .. math.random(1111, 9999) .. math.random(1111, 9999) .. math.random(11, 99) + PlayerData.charinfo.phone = PlayerData.charinfo.phone ~= nil and PlayerData.charinfo.phone or QBCore.Functions.CreatePhoneNumber() + PlayerData.charinfo.account = PlayerData.charinfo.account ~= nil and PlayerData.charinfo.account or QBCore.Functions.CreateAccountNumber() -- Metadata PlayerData.metadata = PlayerData.metadata or {} PlayerData.metadata['hunger'] = PlayerData.metadata['hunger'] or 100 @@ -652,6 +652,34 @@ function QBCore.Player.CreateCitizenId() return CitizenId end +function QBCore.Functions.CreateAccountNumber() + local UniqueFound = false + local AccountNumber = nil + while not UniqueFound do + AccountNumber = 'US0' .. math.random(1, 9) .. 'QBCore' .. math.random(1111, 9999) .. math.random(1111, 9999) .. math.random(11, 99) + local query = '%' .. AccountNumber .. '%' + local result = MySQL.Sync.prepare('SELECT COUNT(*) as count FROM players WHERE metadata LIKE ?', { query }) + if result == 0 then + UniqueFound = true + end + end + return AccountNumber +end + +function QBCore.Functions.CreatePhoneNumber() + local UniqueFound = false + local PhoneNumber = nil + while not UniqueFound do + PhoneNumber = math.random(100,999) .. math.random(1000000,9999999) + local query = '%' .. PhoneNumber .. '%' + local result = MySQL.Sync.prepare('SELECT COUNT(*) as count FROM players WHERE metadata LIKE ?', { query }) + if result == 0 then + UniqueFound = true + end + end + return PhoneNumber +end + function QBCore.Player.CreateFingerId() local UniqueFound = false local FingerId = nil From 1baa0bf868d0a2685ecf8ad0f2666a7b00708bbd Mon Sep 17 00:00:00 2001 From: Scullyy <51968381+Scullyy@users.noreply.github.com> Date: Thu, 3 Feb 2022 13:58:24 +0000 Subject: [PATCH 4/4] Fix personal changes for public repo --- server/player.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/player.lua b/server/player.lua index 6121334..a1efc7b 100644 --- a/server/player.lua +++ b/server/player.lua @@ -658,7 +658,7 @@ function QBCore.Functions.CreateAccountNumber() while not UniqueFound do AccountNumber = 'US0' .. math.random(1, 9) .. 'QBCore' .. math.random(1111, 9999) .. math.random(1111, 9999) .. math.random(11, 99) local query = '%' .. AccountNumber .. '%' - local result = MySQL.Sync.prepare('SELECT COUNT(*) as count FROM players WHERE metadata LIKE ?', { query }) + local result = MySQL.Sync.prepare('SELECT COUNT(*) as count FROM players WHERE charinfo LIKE ?', { query }) if result == 0 then UniqueFound = true end @@ -672,7 +672,7 @@ function QBCore.Functions.CreatePhoneNumber() while not UniqueFound do PhoneNumber = math.random(100,999) .. math.random(1000000,9999999) local query = '%' .. PhoneNumber .. '%' - local result = MySQL.Sync.prepare('SELECT COUNT(*) as count FROM players WHERE metadata LIKE ?', { query }) + local result = MySQL.Sync.prepare('SELECT COUNT(*) as count FROM players WHERE charinfo LIKE ?', { query }) if result == 0 then UniqueFound = true end