From fb79f7ef9f6d9801bac08f01bff0374f578ac936 Mon Sep 17 00:00:00 2001 From: Maximus7474 Date: Wed, 1 Jan 2025 18:19:05 +0100 Subject: [PATCH] fix(server): issue with phone not being found when using unique after changing phone and disconnecting --- server/main.lua | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/server/main.lua b/server/main.lua index 1abfb4f..1b27770 100644 --- a/server/main.lua +++ b/server/main.lua @@ -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) @@ -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}) @@ -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