Skip to content

Fix server-side abstraction bugs: carry check recursion, inventory aggregation, spy info, global leaks#2

Merged
Fonlogen merged 2 commits intocodex/refactor-ox_inventory-script-for-config-optionsfrom
copilot/sub-pr-1
Mar 23, 2026
Merged

Fix server-side abstraction bugs: carry check recursion, inventory aggregation, spy info, global leaks#2
Fonlogen merged 2 commits intocodex/refactor-ox_inventory-script-for-config-optionsfrom
copilot/sub-pr-1

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 23, 2026

Eight review issues in server/sv_main.lua introduced by the framework/inventory abstraction layer, ranging from infinite recursion to global variable leaks and broken duplicate detection.

Changes

CanCarryItem — infinite recursion on qs_inventory + QBCore

player.canCarryItem was patched by QBCore's DecoratePlayer to call CanCarryItem again, causing a stack overflow whenever Config.Framework == 'qbcore' and Config.Inventory == 'qs_inventory'. Now calls the export directly:

local ok = exports['qs-inventory']:CanCarryItem(src, item, amount)
return ok == true or ok == nil

GetInventoryItemList — ox_inventory items missing .name

ox_inventory's Items() export returns entries keyed by name but without a .name field. Labs.AddDepositItem indexes Item.name, so it would error on every deposit. Normalization now injects name = key where absent.

GetPlayerInventory — quantity overwrite on duplicate item names

Both the ox_inventory and qb_inventory branches keyed formatted by item name and overwrote entries when multiple stacks existed. Now aggregates qty across stacks for the same name.

Labs.GetLabSpyExtraInfo — ESX-only DB query + dead spin loop

  • Added Config.Framework == 'qbcore' branch that falls back to the owner identifier instead of querying the ESX-specific users table.
  • Removed while not pInfo do Wait(100) endMySQL.query.await already blocks; the loop could spin forever on a nil return.
  • Both branches now handle missing/nil DB rows with a safe fallback string.

Labs.GetRandomSpiedLabs — implicit globals + wrong duplicate key

lab and extraInfo were assigned without local, leaking into global state across calls. The duplicate-lab guard compared spiedLabs[1]['LabInfo'].LabID (always nil) instead of the correct top-level spiedLabs[1].LabID.

Autosave log — #LabsData always 0

LabsData is a string-keyed map; # returns 0. Replaced with TableSize(LabsData).


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: Fonlogen <25137574+Fonlogen@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Fonlogen/KmF_Lab/sessions/a03303f0-90d9-48de-a98b-9c82d7b4d3b9
Copilot AI changed the title [WIP] Add configurable framework and inventory support Fix server-side abstraction bugs: carry check recursion, inventory aggregation, spy info, global leaks Mar 23, 2026
Copilot AI requested a review from Fonlogen March 23, 2026 19:31
@Fonlogen Fonlogen marked this pull request as ready for review March 23, 2026 19:34
@Fonlogen Fonlogen merged commit ca2887e into codex/refactor-ox_inventory-script-for-config-options Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants