Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scripting/include/store/store-backend.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
33 changes: 27 additions & 6 deletions scripting/store-backend.sp
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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++)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
Expand All @@ -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);
}

Expand All @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions scripting/store-gifting.sp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ public DropGetCreditsCallback(credits, any:pack)
}
else
{
CloseHandle(pack);
PrintToChat(client, "%s%t", STORE_PREFIX, "Not enough credits", g_currencyName);
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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"))
{
Expand Down
9 changes: 5 additions & 4 deletions scripting/store-inventory.sp
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions scripting/store-shop.sp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down