Fixed potential race-condition possibility in cart item transaction (#4139)
Co-authored-by: Cydh Ramdh <cydh@users.noreply.github.com> Co-Authored-By: Aleos <aleos89@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
1832fdf67a
commit
7f772c32d3
@@ -5447,7 +5447,7 @@ void pc_putitemtocart(struct map_session_data *sd,int idx,int amount)
|
||||
|
||||
item_data = &sd->inventory.u.items_inventory[idx];
|
||||
|
||||
if( item_data->nameid == 0 || amount < 1 || item_data->amount < amount || sd->state.vending )
|
||||
if( item_data->nameid == 0 || amount < 1 || item_data->amount < amount || sd->state.vending || sd->state.prevend )
|
||||
return;
|
||||
|
||||
if( item_data->equipSwitch ){
|
||||
@@ -5487,21 +5487,25 @@ int pc_cartitem_amount(struct map_session_data* sd, int idx, int amount)
|
||||
*------------------------------------------*/
|
||||
void pc_getitemfromcart(struct map_session_data *sd,int idx,int amount)
|
||||
{
|
||||
struct item *item_data;
|
||||
unsigned char flag = 0;
|
||||
|
||||
nullpo_retv(sd);
|
||||
|
||||
if (idx < 0 || idx >= MAX_CART) //Invalid index check [Skotlex]
|
||||
return;
|
||||
|
||||
item_data=&sd->cart.u.items_cart[idx];
|
||||
item* item_data=&sd->cart.u.items_cart[idx];
|
||||
|
||||
if(item_data->nameid == 0 || amount < 1 || item_data->amount < amount || sd->state.vending )
|
||||
if (item_data->nameid == 0 || amount < 1 || item_data->amount < amount || sd->state.vending || sd->state.prevend)
|
||||
return;
|
||||
if((flag = pc_additem(sd,item_data,amount,LOG_TYPE_NONE)) == 0)
|
||||
pc_cart_delitem(sd,idx,amount,0,LOG_TYPE_NONE);
|
||||
else {
|
||||
|
||||
if (pc_checkadditem(sd, item_data->nameid, amount) == CHKADDITEM_OVERAMOUNT) {
|
||||
return;
|
||||
}
|
||||
|
||||
item item_copy = *item_data;
|
||||
|
||||
pc_cart_delitem(sd, idx, amount, 0, LOG_TYPE_NONE);
|
||||
char flag = pc_additem(sd, &item_copy, amount, LOG_TYPE_NONE);
|
||||
if(flag != ADDITEM_SUCCESS) {
|
||||
clif_dropitem(sd,idx,0);
|
||||
clif_additem(sd,0,0,flag);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user