Skip to content

Commit

Permalink
fix(server): issue with phone not being found when using unique after…
Browse files Browse the repository at this point in the history
… changing phone and disconnecting
  • Loading branch information
Maximus7474 committed Jan 1, 2025
1 parent 6d79688 commit fb79f7e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ if Inventory.RegisterItemCB then
Inventory.RegisterItemCB(
function (source, newNumber, slot)
local currentNumber = exports['lb-phone']:GetEquippedPhoneNumber(source)
local identifier = Framework.GetIdentifier(source)

if Config.SimCard.ReplaceSimCardNumber then
Inventory.UpdateSimCardNumber(source, slot, currentNumber)
Expand All @@ -19,15 +20,15 @@ if Inventory.RegisterItemCB then
if newNumber then
Inventory.SetNewNumber(source, Config.Item.Name, currentNumber, newNumber)
MySQL.insert.await('INSERT IGNORE INTO phone_phones (id, owner_id, phone_number) VALUES (?, ?, ?)', {
Utils.GenerateSerialNumber(5), Framework.GetIdentifier(source), newNumber
Utils.GenerateSerialNumber(5), identifier, newNumber
})
else
Inventory.ClearCurrentNumber(source, Config.Item.Name, currentNumber)
end

MySQL.update.await('UPDATE phone_phones SET id = ? WHERE phone_number = ? AND id = ?', {currentNumber, currentNumber, Framework.GetIdentifier(source)})
MySQL.update.await('UPDATE phone_phones SET id = ? WHERE phone_number = ? AND id = ?', {currentNumber, currentNumber, identifier})

local rows = MySQL.update.await('DELETE FROM phone_last_phone WHERE id = ?', {Framework.GetIdentifier(source)})
local rows = MySQL.update.await('DELETE FROM phone_last_phone WHERE id = ?', {})
success = rows == 1
else
local rows = MySQL.update.await('UPDATE phone_phones SET id = ? WHERE phone_number = ?', {currentNumber, currentNumber})
Expand All @@ -36,6 +37,11 @@ if Inventory.RegisterItemCB then

if not success then return end

local rows = MySQL.update.await('INSERT IGNORE INTO phone_last_phone (id, phone_number) VALUES (?, ?) ON DUPLICATE KEY UPDATE phone_number = VALUES(phone_number)', {identifier, newNumber})
success = rows == 1

if not success then return end

lib.callback('lbphonesim:changingsimcard', source, function (response)
if response == true then
if Config.SimCard.DeleteSimCard then
Expand Down

0 comments on commit fb79f7e

Please sign in to comment.