diff --git a/scripting/include/store/store-backend.inc b/scripting/include/store/store-backend.inc index 6903af3..3995313 100644 --- a/scripting/include/store/store-backend.inc +++ b/scripting/include/store/store-backend.inc @@ -525,7 +525,7 @@ native Store_GetLoadoutTeam(id); * To determine how many items the player has of the same name, the callback provides the * itemCount[] array. * - * To deremine whether or not an item is equipped in the loadout specified, the callback + * To determine whether or not an item is equipped in the loadout specified, the callback * provides the equipped[] array. * * For example: @@ -720,7 +720,7 @@ native Store_SetItemEquippedState(accountId, itemId, loadoutId, bool:isEquipped, * To determine how many items the player has of the same name, the callback provides the * itemCount[] array. * - * To deremine whether or not an item is equipped in the loadout specified, the callback + * To determine whether or not an item is equipped in the loadout specified, the callback * provides the equipped[] array. * * For example: diff --git a/scripting/store-backend.sp b/scripting/store-backend.sp index 4849db3..75fb667 100644 --- a/scripting/store-backend.sp +++ b/scripting/store-backend.sp @@ -393,7 +393,8 @@ GetItems(Handle:filter = INVALID_HANDLE, Store_GetItemsCallback:callback = Store new flags; new bool:flagsFilter = filter == INVALID_HANDLE ? false : GetTrieValue(filter, "flags", flags); - CloseHandle(filter); + if(filter != INVALID_HANDLE) + CloseHandle(filter); new items[g_itemCount]; @@ -435,6 +436,10 @@ public T_GetItemsCallback(Handle:owner, Handle:hndl, const String:error[], any:p { if (hndl == INVALID_HANDLE) { + ResetPack(pack); + new Handle:filter = Handle:ReadPackCell(pack); + if(filter != INVALID_HANDLE) + CloseHandle(filter); CloseHandle(pack); Store_LogError("SQL Error on GetItems: %s", error); @@ -683,7 +688,8 @@ GetLoadouts(Handle:filter, Store_GetItemsCallback:callback = Store_GetItemsCallb // new team = -1; // new bool:teamFilter = filter == INVALID_HANDLE ? false : GetTrieValue(filter, "team", team); - CloseHandle(filter); + if(filter != INVALID_HANDLE) + CloseHandle(filter); for (new loadout = 0; loadout < g_loadoutCount; loadout++) { @@ -720,6 +726,10 @@ public T_GetLoadoutsCallback(Handle:owner, Handle:hndl, const String:error[], an { if (hndl == INVALID_HANDLE) { + ResetPack(pack); + new Handle:filter = Handle:ReadPackCell(pack); + if(filter != INVALID_HANDLE) + CloseHandle(filter); CloseHandle(pack); Store_LogError("SQL Error on GetLoadouts: %s", error); @@ -791,7 +801,7 @@ GetLoadoutIndex(id) * To determine how many items the player has of the same name, the callback provides the * itemCount[] array. * - * To deremine whether or not an item is equipped in the loadout specified, the callback + * To determine whether or not an item is equipped in the loadout specified, the callback * provides the equipped[] array. * * For a full example of a usage of this method, see the store-inventory module. @@ -820,6 +830,7 @@ GetUserItems(Handle:filter, accountId, loadoutId, Store_GetUserItemsCallback:cal if (g_itemCount == -1) { Store_LogWarning("Store_GetUserItems has been called before item loading."); + // FIXME: If the GetItems query fails, this pack handle as well as the filter handle leak! GetItems(INVALID_HANDLE, GetUserItemsLoadCallback, INVALID_HANDLE, true, pack); return; @@ -888,7 +899,9 @@ public T_GetUserItemsCallback(Handle:owner, Handle:hndl, const String:error[], a return; } - SetPackPosition(pack, 16); + ResetPack(pack); + ReadPackCell(pack); //filter + ReadPackCell(pack); //accountId new loadoutId = ReadPackCell(pack); new Store_GetUserItemsCallback:callback = Store_GetUserItemsCallback:ReadPackCell(pack); @@ -1059,6 +1072,7 @@ BuyItem(accountId, itemId, Store_BuyItemCallback:callback, Handle:plugin = INVAL WritePackCell(pack, _:plugin); // 24 WritePackCell(pack, _:data); // 32 + // FIXME: If GetCredits query fails, this pack handle leaks! GetCredits(accountId, T_BuyItemGetCreditsCallback, INVALID_HANDLE, pack); } @@ -1074,6 +1088,8 @@ public T_BuyItemGetCreditsCallback(credits, any:pack) if (credits < g_items[GetItemIndex(itemId)][ItemPrice]) { + CloseHandle(pack); + Call_StartFunction(plugin, callback); Call_PushCell(0); Call_PushCell(_:arg); @@ -1082,6 +1098,7 @@ public T_BuyItemGetCreditsCallback(credits, any:pack) return; } + // FIXME: If GiveCredits query fails, this pack handle leaks! GiveCredits(accountId, -g_items[GetItemIndex(itemId)][ItemPrice], BuyItemGiveCreditsCallback, _, pack); } @@ -1095,7 +1112,9 @@ public BuyItemGiveCreditsCallback(accountId, any:pack) public BuyItemGiveItemCallback(accountId, any:pack) { - SetPackPosition(pack, 16); + ResetPack(pack); + ReadPackCell(pack); // itemId + ReadPackCell(pack); // accountId new Store_BuyItemCallback:callback = Store_BuyItemCallback:ReadPackCell(pack); new Handle:plugin = Handle:ReadPackCell(pack); @@ -1131,6 +1150,7 @@ RemoveUserItem(accountId, itemId, Store_UseItemCallback:callback, Handle:plugin WritePackCell(pack, _:plugin); WritePackCell(pack, _:data); + // FIXME: If UnequipItem query fails, this pack handle leaks! UnequipItem(accountId, itemId, -1, RemoveUserItemUnnequipCallback, _, pack); } @@ -1219,6 +1239,7 @@ EquipItem(accountId, itemId, loadoutId, Store_EquipItemCallback:callback, Handle WritePackCell(pack, _:plugin); WritePackCell(pack, _:data); + // FIXME: If UnequipItem query fails, this pack handle leaks! UnequipItem(accountId, itemId, loadoutId, EquipUnequipItemCallback, _, pack); } @@ -1339,7 +1360,7 @@ public T_UnequipItemCallback(Handle:owner, Handle:hndl, const String:error[], an * To determine how many items the player has of the same name, the callback provides the * itemCount[] array. * - * To deremine whether or not an item is equipped in the loadout specified, the callback + * To determine whether or not an item is equipped in the loadout specified, the callback * provides the equipped[] array. * * For a full example of a usage of this method, see the store-inventory module. diff --git a/scripting/store-gifting.sp b/scripting/store-gifting.sp index 9336e5c..c9a8e37 100644 --- a/scripting/store-gifting.sp +++ b/scripting/store-gifting.sp @@ -215,6 +215,7 @@ public DropGetCreditsCallback(credits, any:pack) } else { + CloseHandle(pack); PrintToChat(client, "%s%t", STORE_PREFIX, "Not enough credits", g_currencyName); } } @@ -891,7 +892,8 @@ GiftCredits(from, to, amount) public TakeCreditsCallback(accountId, any:pack) { - SetPackPosition(pack, 8); + ResetPack(pack); + ReadPackCell(pack); // from new to = ReadPackCell(pack); new amount = ReadPackCell(pack); @@ -931,7 +933,8 @@ GiftItem(from, to, itemId) public RemoveUserItemCallback(accountId, itemId, any:pack) { - SetPackPosition(pack, 8); + ResetPack(pack); + ReadPackCell(pack); // from new to = ReadPackCell(pack); @@ -1025,6 +1028,7 @@ public PickupGiveCallback(accountId, any:pack) decl String:itemType[32]; ReadPackString(pack, itemType, sizeof(itemType)); new value = ReadPackCell(pack); + CloseHandle(pack); if (StrEqual(itemType, "credits")) { diff --git a/scripting/store-inventory.sp b/scripting/store-inventory.sp index 7897a5f..f739278 100644 --- a/scripting/store-inventory.sp +++ b/scripting/store-inventory.sp @@ -144,8 +144,9 @@ public Action:Command_PrintItemTypes(client, args) ResetPack(itemType); new Handle:plugin = Handle:ReadPackCell(itemType); - - SetPackPosition(itemType, 24); + ReadPackCell(itemType); // useCallback + ReadPackCell(itemType); // attrsCallback + decl String:typeName[32]; ReadPackString(itemType, typeName, sizeof(typeName)); @@ -187,6 +188,7 @@ public GetCategoriesCallback(ids[], count, any:serial) if (client == 0) return; + // FIXME: If one of the GetUserItems queries fails, this menu handle leaks. categories_menu[client] = CreateMenu(InventoryMenuSelectHandle); SetMenuTitle(categories_menu[client], "%T\n \n", "Inventory", client); @@ -588,8 +590,7 @@ public Native_CallItemAttrsCallback(Handle:plugin, params) ResetPack(pack); new Handle:callbackPlugin = Handle:ReadPackCell(pack); - - SetPackPosition(pack, 16); + ReadPackCell(pack); // useCallback new callback = ReadPackCell(pack); diff --git a/scripting/store-shop.sp b/scripting/store-shop.sp index ba66e54..55f2dde 100644 --- a/scripting/store-shop.sp +++ b/scripting/store-shop.sp @@ -169,6 +169,7 @@ public GetCategoriesCallback(ids[], count, any:serial) if (client == 0) return; + // FIXME: If one of the GetUserItems queries fails, this menu handle leaks. categories_menu[client] = CreateMenu(ShopMenuSelectHandle); SetMenuTitle(categories_menu[client], "%T\n \n", "Shop", client);