/** * Execute the trade * lock sd and tsd trade data, execute the trade, clear, then save players * @param sd : Player that has click on trade button */ void trade_tradecommit(struct map_session_data *sd) { struct map_session_data *tsd; int trade_i; nullpo_retv(sd); if (!sd->state.trading || !sd->state.deal_locked) //Locked should be 1 (pressed ok) before you can press trade. return; if ((tsd = map_id2sd(sd->trade_partner)) == NULL) { trade_tradecancel(sd); return; } sd->state.deal_locked = 2; if (tsd->state.deal_locked < 2) return; //Not yet time for trading. // Now is a good time (to save on resources) to check that the trade can indeed be made and it's not exploitable. // check exploit (trade more items that you have) if (impossible_trade_check(sd)) { trade_tradecancel(sd); return; } // check exploit (trade more items that you have) if (impossible_trade_check(tsd)) { trade_tradecancel(tsd); return; } // check for full inventory (can not add traded items) if (!trade_check(sd,tsd)) { // check the both players trade_tradecancel(sd); return; } // trade is accepted and correct. for( trade_i = 0; trade_i < 10; trade_i++ ) { int n; unsigned char flag = 0; if (sd->deal.item[trade_i].amount) { n = sd->deal.item[trade_i].index; flag = pc_additem(tsd, &sd->inventory.u.items_inventory[n], sd->deal.item[trade_i].amount,LOG_TYPE_TRADE); if (flag == 0) pc_delitem(sd, n, sd->deal.item[trade_i].amount, 1, 6, LOG_TYPE_TRADE); else clif_additem(sd, n, sd->deal.item[trade_i].amount, 0); sd->deal.item[trade_i].index = 0; sd->deal.item[trade_i].amount = 0; } if (tsd->deal.item[trade_i].amount) { n = tsd->deal.item[trade_i].index; flag = pc_additem(sd, &tsd->inventory.u.items_inventory[n], tsd->deal.item[trade_i].amount,LOG_TYPE_TRADE); if (flag == 0) pc_delitem(tsd, n, tsd->deal.item[trade_i].amount, 1, 6, LOG_TYPE_TRADE); else clif_additem(tsd, n, tsd->deal.item[trade_i].amount, 0); tsd->deal.item[trade_i].index = 0; tsd->deal.item[trade_i].amount = 0; } } if( sd->deal.zeny ) { pc_payzeny(sd ,sd->deal.zeny, LOG_TYPE_TRADE, tsd); pc_getzeny(tsd,sd->deal.zeny,LOG_TYPE_TRADE, sd); sd->deal.zeny = 0; } if ( tsd->deal.zeny) { pc_payzeny(tsd,tsd->deal.zeny,LOG_TYPE_TRADE, sd); pc_getzeny(sd ,tsd->deal.zeny,LOG_TYPE_TRADE, tsd); tsd->deal.zeny = 0; } sd->state.deal_locked = 0; sd->trade_partner = 0; sd->state.trading = 0; sd->state.isBoundTrading = 0; tsd->state.deal_locked = 0; tsd->trade_partner = 0; tsd->state.trading = 0; tsd->state.isBoundTrading = 0; clif_tradecompleted(sd, 0); clif_tradecompleted(tsd, 0); // save both player to avoid crash: they always have no advantage/disadvantage between the 2 players if (save_settings&CHARSAVE_TRADE) { chrif_save(sd,0); chrif_save(tsd,0); } }
/** * Reply to a trade-request. * @param sd : player receiving the trade request answer * @param type : answer code * 0: Char is too far * 1: Character does not exist * 2: Trade failed * 3: Accept * 4: Cancel * Weird enough, the client should only send 3/4 * and the server is the one that can reply 0~2 */ void trade_tradeack(struct map_session_data *sd, int type) { struct map_session_data *tsd; nullpo_retv(sd); if (sd->state.trading || !sd->trade_partner) return; // Already trading or no partner set. if ((tsd = map_id2sd(sd->trade_partner)) == NULL) { clif_tradestart(sd, 1); // Character does not exist sd->trade_partner=0; return; } if (tsd->state.trading || tsd->trade_partner != sd->bl.id) { clif_tradestart(sd, 2); sd->trade_partner=0; return; // Already trading or wrong partner. } if (type == 4) { // Cancel clif_tradestart(tsd, type); clif_tradestart(sd, type); sd->state.deal_locked = 0; sd->trade_partner = 0; tsd->state.deal_locked = 0; tsd->trade_partner = 0; return; } if (type != 3) return; //If client didn't send accept, it's a broken packet? // Players can not request trade from far away, unless they are allowed to use @trade. // Check here as well since the original character could had warped. if (!pc_can_use_command(sd, "trade", COMMAND_ATCOMMAND) && (sd->bl.m != tsd->bl.m || !check_distance_bl(&sd->bl, &tsd->bl, TRADE_DISTANCE))) { clif_tradestart(sd, 0); // too far sd->trade_partner=0; tsd->trade_partner = 0; return; } // Check if you can start trade. if (sd->npc_id || sd->state.vending || sd->state.buyingstore || sd->state.storage_flag || tsd->npc_id || tsd->state.vending || tsd->state.buyingstore || tsd->state.storage_flag) { // Fail clif_tradestart(sd, 2); clif_tradestart(tsd, 2); sd->state.deal_locked = 0; sd->trade_partner = 0; tsd->state.deal_locked = 0; tsd->trade_partner = 0; return; } // Initiate trade sd->state.trading = 1; tsd->state.trading = 1; memset(&sd->deal, 0, sizeof(sd->deal)); memset(&tsd->deal, 0, sizeof(tsd->deal)); clif_tradestart(tsd, type); clif_tradestart(sd, type); }
/*========================================== * 取引許諾(trade押し) *------------------------------------------ */ void trade_tradecommit(struct map_session_data *sd) { struct map_session_data *target_sd; int trade_i; int flag; nullpo_retv(sd); if (sd->state.trading && (target_sd = map_id2sd(sd->trade_partner)) != NULL) { if ((sd->state.deal_locked >= 1) && (target_sd->state.deal_locked >= 1)) { // both have pressed 'ok' if (sd->state.deal_locked < 2) { // set locked to 2 sd->state.deal_locked = 2; } if (target_sd->state.deal_locked == 2) { // the other one pressed 'trade' too // check exploit (trade more items that you have) if (impossible_trade_check(sd)) { trade_tradecancel(sd); return; } // check exploit (trade more items that you have) if (impossible_trade_check(target_sd)) { trade_tradecancel(target_sd); return; } // check zenys value against hackers if (sd->deal.zeny >= 0 && sd->deal.zeny <= MAX_ZENY && sd->deal.zeny <= sd->status.zeny && // check amount (target_sd->status.zeny + sd->deal.zeny) <= MAX_ZENY && // fix positiv overflow target_sd->deal.zeny >= 0 && target_sd->deal.zeny <= MAX_ZENY && target_sd->deal.zeny <= target_sd->status.zeny && // check amount (sd->status.zeny + target_sd->deal.zeny) <= MAX_ZENY) { // fix positiv overflow // check for full inventory (can not add traded items) if (!trade_check(sd)) { // check the both players trade_tradecancel(sd); return; } // trade is accepted for(trade_i = 0; trade_i < 10; trade_i++) { if (sd->deal.item[trade_i].amount != 0) { int n = sd->deal.item[trade_i].index; if (sd->status.inventory[n].amount < sd->deal.item[trade_i].amount) sd->deal.item[trade_i].amount = sd->status.inventory[n].amount; log_trade(sd, target_sd, n, sd->deal.item[trade_i].amount); flag = pc_additem(target_sd, &sd->status.inventory[n], sd->deal.item[trade_i].amount); if (flag == 0) { //Logs (T)rade [Lupus] if(log_config.pick > 0 ) log_pick(sd, "T", 0, sd->status.inventory[n].nameid, -(sd->deal.item[trade_i].amount), &sd->status.inventory[n]); log_pick(target_sd, "T", 0, sd->status.inventory[n].nameid, sd->deal.item[trade_i].amount, &sd->status.inventory[n]); //Logs pc_delitem(sd, n, sd->deal.item[trade_i].amount, 1); } else { clif_additem(sd, n, sd->deal.item[trade_i].amount, 0); } sd->deal.item[trade_i].index = 0; sd->deal.item[trade_i].amount = 0; } if (target_sd->deal.item[trade_i].amount != 0) { int n = target_sd->deal.item[trade_i].index; if (target_sd->status.inventory[n].amount < target_sd->deal.item[trade_i].amount) target_sd->deal.item[trade_i].amount = target_sd->status.inventory[n].amount; log_trade(target_sd, sd, n, target_sd->deal.item[trade_i].amount); flag = pc_additem(sd, &target_sd->status.inventory[n], target_sd->deal.item[trade_i].amount); if (flag == 0) { //Logs (T)rade [Lupus] if(log_config.pick > 0 ) log_pick(target_sd, "T", 0, target_sd->status.inventory[n].nameid, -(target_sd->deal.item[trade_i].amount), &target_sd->status.inventory[n]); log_pick(sd, "T", 0, target_sd->status.inventory[n].nameid, target_sd->deal.item[trade_i].amount, &target_sd->status.inventory[n]); //Logs pc_delitem(target_sd, n, target_sd->deal.item[trade_i].amount, 1); } else { clif_additem(target_sd, n, target_sd->deal.item[trade_i].amount, 0); } target_sd->deal.item[trade_i].index = 0; target_sd->deal.item[trade_i].amount = 0; } } if (sd->deal.zeny) { //Logs Zeny (T)rade [Lupus] if(log_config.zeny > 0 ) log_zeny(target_sd, "T", sd, sd->deal.zeny); //Logs sd->status.zeny -= sd->deal.zeny; target_sd->status.zeny += sd->deal.zeny; } if (target_sd->deal.zeny) { //Logs Zeny (T)rade [Lupus] if(log_config.zeny > 0 ) log_zeny(sd, "T", target_sd, target_sd->deal.zeny); //Logs target_sd->status.zeny -= target_sd->deal.zeny; sd->status.zeny += target_sd->deal.zeny; } if (sd->deal.zeny || target_sd->deal.zeny) { clif_updatestatus(sd, SP_ZENY); sd->deal.zeny = 0; clif_updatestatus(target_sd, SP_ZENY); target_sd->deal.zeny = 0; } sd->state.deal_locked = 0; sd->trade_partner = 0; sd->state.trading = 0; target_sd->state.deal_locked = 0; target_sd->trade_partner = 0; target_sd->state.trading = 0; clif_tradecompleted(sd, 0); clif_tradecompleted(target_sd, 0); // save both player to avoid crash: they always have no advantage/disadvantage between the 2 players chrif_save(sd,0); // do pc_makesavestatus and save storage too chrif_save(target_sd,0); // do pc_makesavestatus and save storage too // zeny value was modified!!!! hacker with packet modified } else { trade_tradecancel(sd); } } } } }
/** * Adds an item/qty to the trade window * @param sd : Player requesting to add stuff to the trade * @param index : index of item in inventory * @param amount : amount of item to add from index */ void trade_tradeadditem(struct map_session_data *sd, short index, short amount) { struct map_session_data *target_sd; struct item *item; int trade_i, trade_weight; int src_lv, dst_lv; nullpo_retv(sd); if( !sd->state.trading || sd->state.deal_locked > 0 ) return; // Can't add stuff. if( (target_sd = map_id2sd(sd->trade_partner)) == NULL ) { trade_tradecancel(sd); return; } if( !amount ) { // Why do this.. ~.~ just send an ack, the item won't display on the trade window. clif_tradeitemok(sd, index, 0); return; } index -= 2; // 0 is for zeny, 1 is unknown. Gravity, go figure... // Item checks... if( index < 0 || index >= MAX_INVENTORY ) return; if( amount < 0 || amount > sd->inventory.u.items_inventory[index].amount ) return; item = &sd->inventory.u.items_inventory[index]; src_lv = pc_get_group_level(sd); dst_lv = pc_get_group_level(target_sd); if( !itemdb_cantrade(item, src_lv, dst_lv) && // Can't trade (pc_get_partner(sd) != target_sd || !itemdb_canpartnertrade(item, src_lv, dst_lv)) ) { // Can't partner-trade clif_displaymessage (sd->fd, msg_txt(sd,260)); clif_tradeitemok(sd, index+2, 1); return; } if( item->expire_time ) { // Rental System clif_displaymessage (sd->fd, msg_txt(sd,260)); clif_tradeitemok(sd, index+2, 1); return; } if( ((item->bound == BOUND_ACCOUNT || item->bound > BOUND_GUILD) || (item->bound == BOUND_GUILD && sd->status.guild_id != target_sd->status.guild_id)) && !pc_can_give_bounded_items(sd) ) { // Item Bound clif_displaymessage(sd->fd, msg_txt(sd,293)); clif_tradeitemok(sd, index+2, 1); return; } if (item->bound) sd->state.isBoundTrading |= (1<<item->bound); // Locate a trade position ARR_FIND( 0, 10, trade_i, sd->deal.item[trade_i].index == index || sd->deal.item[trade_i].amount == 0 ); if( trade_i == 10 ) { // No space left clif_tradeitemok(sd, index+2, 1); return; } trade_weight = sd->inventory_data[index]->weight * amount; if( target_sd->weight + sd->deal.weight + trade_weight > target_sd->max_weight ) { // fail to add item -- the player was over weighted. clif_tradeitemok(sd, index+2, 1); return; } if( sd->deal.item[trade_i].index == index ) { // The same item as before is being readjusted. if( sd->deal.item[trade_i].amount + amount > sd->inventory.u.items_inventory[index].amount ) { // packet deal exploit check amount = sd->inventory.u.items_inventory[index].amount - sd->deal.item[trade_i].amount; trade_weight = sd->inventory_data[index]->weight * amount; } sd->deal.item[trade_i].amount += amount; } else { // New deal item sd->deal.item[trade_i].index = index; sd->deal.item[trade_i].amount = amount; } sd->deal.weight += trade_weight; clif_tradeitemok(sd, index+2, 0); // Return the index as it was received clif_tradeadditem(sd, target_sd, index+2, amount); }
/*========================================== * Check here if we can add item in inventory (against full inventory) *------------------------------------------ */ int trade_check(struct map_session_data *sd) { struct item inventory[MAX_INVENTORY]; struct item inventory2[MAX_INVENTORY]; struct item_data *data; struct map_session_data *target_sd; int trade_i, i, amount; target_sd = map_id2sd(sd->trade_partner); // get inventory of player memcpy(&inventory, &sd->status.inventory, sizeof(struct item) * MAX_INVENTORY); memcpy(&inventory2, &target_sd->status.inventory, sizeof(struct item) * MAX_INVENTORY); // check free slot in both inventory for(trade_i = 0; trade_i < 10; trade_i++) { amount = sd->deal.item[trade_i].amount; if (amount > 0) { int n = sd->deal.item[trade_i].index; // check quantity if (amount > inventory[n].amount) amount = inventory[n].amount; if (amount > 0) { data = itemdb_search(inventory[n].nameid); i = MAX_INVENTORY; // check for non-equipement item if (!itemdb_isequip2(data)) { for(i = 0; i < MAX_INVENTORY; i++) if (inventory2[i].nameid == inventory[n].nameid && inventory2[i].card[0] == inventory[n].card[0] && inventory2[i].card[1] == inventory[n].card[1] && inventory2[i].card[2] == inventory[n].card[2] && inventory2[i].card[3] == inventory[n].card[3]) { if (inventory2[i].amount + amount > MAX_AMOUNT) return 0; inventory2[i].amount += amount; inventory[n].amount -= amount; if (inventory[n].amount <= 0) memset(&inventory[n], 0, sizeof(struct item)); break; } } // check for equipement if (i == MAX_INVENTORY) { for(i = 0; i < MAX_INVENTORY; i++) { if (inventory2[i].nameid == 0) { memcpy(&inventory2[i], &inventory[n], sizeof(struct item)); inventory2[i].amount = amount; inventory[n].amount -= amount; if (inventory[n].amount <= 0) memset(&inventory[n], 0, sizeof(struct item)); break; } } if (i == MAX_INVENTORY) return 0; } } } amount = target_sd->deal.item[trade_i].amount; if (amount > 0) { int n = target_sd->deal.item[trade_i].index; // check quantity if (amount > inventory2[n].amount) amount = inventory2[n].amount; if (amount > 0) { // search if it's possible to add item (for full inventory) data = itemdb_search(inventory2[n].nameid); i = MAX_INVENTORY; if (!itemdb_isequip2(data)) { for(i = 0; i < MAX_INVENTORY; i++) if (inventory[i].nameid == inventory2[n].nameid && inventory[i].card[0] == inventory2[n].card[0] && inventory[i].card[1] == inventory2[n].card[1] && inventory[i].card[2] == inventory2[n].card[2] && inventory[i].card[3] == inventory2[n].card[3]) { if (inventory[i].amount + amount > MAX_AMOUNT) return 0; inventory[i].amount += amount; inventory2[n].amount -= amount; if (inventory2[n].amount <= 0) memset(&inventory2[n], 0, sizeof(struct item)); break; } } if (i == MAX_INVENTORY) { for(i = 0; i < MAX_INVENTORY; i++) { if (inventory[i].nameid == 0) { memcpy(&inventory[i], &inventory2[n], sizeof(struct item)); inventory[i].amount = amount; inventory2[n].amount -= amount; if (inventory2[n].amount <= 0) memset(&inventory2[n], 0, sizeof(struct item)); break; } } if (i == MAX_INVENTORY) return 0; } } } } return 1; }
/*========================================== * Adds an item/qty to the trade window [rewrite by Skotlex] *------------------------------------------ */ void trade_tradeadditem(struct map_session_data *sd, int index, int amount) { struct map_session_data *target_sd; int trade_i, trade_weight, nameid; nullpo_retv(sd); if (!sd->state.trading || (target_sd = map_id2sd(sd->trade_partner)) == NULL || sd->state.deal_locked > 0) return; //Can't add stuff. if (index == 0) { //Adding Zeny if (amount >= 0 && amount <= MAX_ZENY && amount <= sd->status.zeny && // check amount (target_sd->status.zeny + amount) <= MAX_ZENY) // fix positiv overflow { //Check Ok sd->deal.zeny = amount; clif_tradeadditem(sd, target_sd, 0, amount); } else //Cancel Transaction trade_tradecancel(sd); return; } //Add an Item index = index -2; //Why the actual index used is -2? //Item checks... if (index < 0 || index > MAX_INVENTORY) return; if (amount < 0 || amount > sd->status.inventory[index].amount) return; nameid = sd->inventory_data[index]->nameid; if (!itemdb_cantrade(nameid, pc_isGM(sd), pc_isGM(target_sd)) && //Can't trade (pc_get_partner(sd) != target_sd || !itemdb_canpartnertrade(nameid, pc_isGM(sd), pc_isGM(target_sd)))) //Can't partner-trade { clif_displaymessage (sd->fd, msg_txt(260)); return; } for(trade_i = 0; trade_i < 10; trade_i++) { //Locate a trade position if (sd->deal.item[trade_i].index == index || sd->deal.item[trade_i].amount == 0) break; } if (trade_i >= 10) //No space left return; trade_weight = sd->inventory_data[index]->weight * amount; if (target_sd->weight + sd->deal.weight + trade_weight > target_sd->max_weight) { //fail to add item -- the player was over weighted. clif_tradeitemok(sd, index, 1); return; } if (sd->deal.item[trade_i].index == index) { //The same item as before is being readjusted. if (sd->deal.item[trade_i].amount + amount > sd->status.inventory[index].amount) { //packet deal exploit check amount = sd->status.inventory[index].amount - sd->deal.item[trade_i].amount; trade_weight = sd->inventory_data[index]->weight * amount; } sd->deal.item[trade_i].amount += amount; } else { //New deal item sd->deal.item[trade_i].index = index; sd->deal.item[trade_i].amount = amount; } sd->deal.weight += trade_weight; if (impossible_trade_check(sd)) { // check exploit (trade more items that you have) trade_tradecancel(sd); return; } clif_tradeitemok(sd, index+2, 0); // Return the index as it was received clif_tradeadditem(sd, target_sd, index+2, amount); //index fix }
void buyingstore_trade(struct map_session_data* sd, int account_id, unsigned int buyer_id, const uint8* itemlist, unsigned int count) { int zeny = 0; unsigned int i, weight, listidx, k; struct map_session_data* pl_sd; if( count == 0 ) {// nothing to do return; } if( !battle_config.feature_buying_store || pc_istrading(sd) ) {// not allowed to sell clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, 0); return; } if( !pc_can_give_items(pc_isGM(sd)) ) {// custom: GM is not allowed to sell clif_displaymessage(sd->fd, msg_txt(246)); clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, 0); return; } if( ( pl_sd = map_id2sd(account_id) ) == NULL || !pl_sd->state.buyingstore || pl_sd->buyer_id != buyer_id ) {// not online, not buying or not same store clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, 0); return; } if( !searchstore_queryremote(sd, account_id) && ( sd->bl.m != pl_sd->bl.m || !check_distance_bl(&sd->bl, &pl_sd->bl, AREA_SIZE) ) ) {// out of view range clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, 0); return; } searchstore_clearremote(sd); if( pl_sd->status.zeny < pl_sd->buyingstore.zenylimit ) {// buyer lost zeny in the mean time? fix the limit pl_sd->buyingstore.zenylimit = pl_sd->status.zeny; } weight = pl_sd->weight; // check item list for( i = 0; i < count; i++ ) {// itemlist: <index>.W <name id>.W <amount>.W unsigned short nameid, amount; int index; index = RBUFW(itemlist,i*6+0)-2; nameid = RBUFW(itemlist,i*6+2); amount = RBUFW(itemlist,i*6+4); if( i ) {// duplicate check. as the client does this too, only malicious intent should be caught here ARR_FIND( 0, i, k, RBUFW(itemlist,k*6+0)-2 == index ); if( k != i ) {// duplicate ShowWarning("buyingstore_trade: Found duplicate item on selling list (prevnameid=%hu, prevamount=%hu, nameid=%hu, amount=%hu, account_id=%d, char_id=%d).\n", RBUFW(itemlist,k*6+2), RBUFW(itemlist,k*6+4), nameid, amount, sd->status.account_id, sd->status.char_id); clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, nameid); return; } } if( index < 0 || index >= ARRAYLENGTH(sd->status.inventory) || sd->inventory_data[index] == NULL || sd->status.inventory[index].nameid != nameid || sd->status.inventory[index].amount < amount ) {// invalid input clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, nameid); return; } if( sd->status.inventory[index].expire_time || !itemdb_cantrade(&sd->status.inventory[index], pc_isGM(sd), pc_isGM(pl_sd)) || memcmp(sd->status.inventory[index].card, buyingstore_blankslots, sizeof(buyingstore_blankslots)) ) {// non-tradable item clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, nameid); return; } ARR_FIND( 0, pl_sd->buyingstore.slots, listidx, pl_sd->buyingstore.items[listidx].nameid == nameid ); if( listidx == pl_sd->buyingstore.slots || pl_sd->buyingstore.items[listidx].amount == 0 ) {// there is no such item or the buyer has already bought all of them clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, nameid); return; } if( pl_sd->buyingstore.items[listidx].amount < amount ) {// buyer does not need that much of the item clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_COUNT, nameid); return; } if( pc_checkadditem(pl_sd, nameid, amount) == ADDITEM_OVERAMOUNT ) {// buyer does not have enough space for this item clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, nameid); return; } if( amount*(unsigned int)sd->inventory_data[index]->weight > pl_sd->max_weight-weight ) {// normally this is not supposed to happen, as the total weight is // checked upon creation, but the buyer could have gained items clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, nameid); return; } weight+= amount*sd->inventory_data[index]->weight; if( amount*pl_sd->buyingstore.items[listidx].price > pl_sd->buyingstore.zenylimit-zeny ) {// buyer does not have enough zeny clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_ZENY, nameid); return; } zeny+= amount*pl_sd->buyingstore.items[listidx].price; } // process item list for( i = 0; i < count; i++ ) {// itemlist: <index>.W <name id>.W <amount>.W unsigned short nameid, amount; int index; index = RBUFW(itemlist,i*6+0)-2; nameid = RBUFW(itemlist,i*6+2); amount = RBUFW(itemlist,i*6+4); ARR_FIND( 0, pl_sd->buyingstore.slots, listidx, pl_sd->buyingstore.items[listidx].nameid == nameid ); zeny = amount*pl_sd->buyingstore.items[listidx].price; // log log_pick(&sd->bl, LOG_TYPE_BUYING_STORE, nameid, -((int)amount), &sd->status.inventory[index]); log_pick(&pl_sd->bl, LOG_TYPE_BUYING_STORE, nameid, amount, &sd->status.inventory[index]); log_zeny(sd, LOG_TYPE_BUYING_STORE, pl_sd, zeny); // move item pc_additem(pl_sd, &sd->status.inventory[index], amount); pc_delitem(sd, index, amount, 1, 0); pl_sd->buyingstore.items[listidx].amount-= amount; // pay up pc_payzeny(pl_sd, zeny); pc_getzeny(sd, zeny); pl_sd->buyingstore.zenylimit-= zeny; // notify clients clif_buyingstore_delete_item(sd, index, amount, pl_sd->buyingstore.items[listidx].price); clif_buyingstore_update_item(pl_sd, nameid, amount); } // check whether or not there is still something to buy ARR_FIND( 0, pl_sd->buyingstore.slots, i, pl_sd->buyingstore.items[i].amount != 0 ); if( i == pl_sd->buyingstore.slots ) {// everything was bought clif_buyingstore_trade_failed_buyer(pl_sd, BUYINGSTORE_TRADE_BUYER_NO_ITEMS); } else if( pl_sd->buyingstore.zenylimit == 0 ) {// zeny limit reached clif_buyingstore_trade_failed_buyer(pl_sd, BUYINGSTORE_TRADE_BUYER_ZENY); } else {// continue buying return; } // cannot continue buying buyingstore_close(pl_sd); // remove auto-trader if( pl_sd->state.autotrade ) { map_quit(pl_sd); } }
/*========================================== * Auth confirmation ack *------------------------------------------*/ void chrif_authok(int fd) { int account_id; uint32 login_id1; uint32 login_id2; time_t expiration_time; int gmlevel; struct mmo_charstatus* status; int char_id; struct auth_node *node; bool changing_mapservers; TBL_PC* sd; //Check if both servers agree on the struct's size if( RFIFOW(fd,2) - 25 != sizeof(struct mmo_charstatus) ) { ShowError("chrif_authok: Data size mismatch! %d != %d\n", RFIFOW(fd,2) - 25, sizeof(struct mmo_charstatus)); return; } account_id = RFIFOL(fd,4); login_id1 = RFIFOL(fd,8); login_id2 = RFIFOL(fd,12); expiration_time = (time_t)(int32)RFIFOL(fd,16); gmlevel = RFIFOL(fd,20); changing_mapservers = (RFIFOB(fd,24)); status = (struct mmo_charstatus*)RFIFOP(fd,25); char_id = status->char_id; //Check if we don't already have player data in our server //Causes problems if the currently connected player tries to quit or this data belongs to an already connected player which is trying to re-auth. if ((sd = map_id2sd(account_id)) != NULL) return; if ((node = chrif_search(account_id)) == NULL) return; // should not happen if (node->state != ST_LOGIN) return; //character in logout phase, do not touch that data. if (node->sd == NULL) { /* //When we receive double login info and the client has not connected yet, //discard the older one and keep the new one. chrif_auth_delete(node->account_id, node->char_id, ST_LOGIN); */ return; // should not happen } sd = node->sd; if( runflag == MAPSERVER_ST_RUNNING && node->char_dat == NULL && node->account_id == account_id && node->char_id == char_id && node->login_id1 == login_id1 ) { //Auth Ok if (pc_authok(sd, login_id2, expiration_time, gmlevel, status, changing_mapservers)) return; } else { //Auth Failed pc_authfail(sd); } chrif_char_offline(sd); //Set him offline, the char server likely has it set as online already. chrif_auth_delete(account_id, char_id, ST_LOGIN); }
/** * Start transaction * @param sd Player/Seller * @param account_id Buyer account ID * @param *itemlist List of sold items { <index>.W, <nameid>.W, <amount>.W }* * @param count Number of item on the itemlist */ void buyingstore_trade(struct map_session_data *sd, int account_id, unsigned int buyer_id, const uint8 *itemlist, unsigned int count) { int zeny = 0; unsigned int i, weight, listidx, k; struct map_session_data *pl_sd; nullpo_retv(sd); if( count == 0 ) // Nothing to do return; if( !battle_config.feature_buying_store || pc_istrading(sd) ) { // Not allowed to sell clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, 0); return; } if( !pc_can_give_items(sd) ) { // Custom: GM is not allowed to sell clif_displaymessage(sd->fd, msg_txt(246)); clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, 0); return; } // Not online, not buying or not same store if( (pl_sd = map_id2sd(account_id)) == NULL || !pl_sd->state.buyingstore || pl_sd->buyer_id != buyer_id ) { clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, 0); return; } if( !searchstore_queryremote(sd, account_id) && (sd->bl.m != pl_sd->bl.m || !check_distance_bl(&sd->bl, &pl_sd->bl, AREA_SIZE)) ) { // Out of view range clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, 0); return; } searchstore_clearremote(sd); if( pl_sd->status.zeny < pl_sd->buyingstore.zenylimit ) // Buyer lost zeny in the mean time? Fix the limit pl_sd->buyingstore.zenylimit = pl_sd->status.zeny; weight = pl_sd->weight; // Check item list for( i = 0; i < count; i++ ) { // itemlist: <index>.W <name id>.W <amount>.W unsigned short nameid, amount; int index; index = RBUFW(itemlist,i * 6 + 0) - 2; nameid = RBUFW(itemlist,i * 6 + 2); amount = RBUFW(itemlist,i * 6 + 4); if( i ) { // Duplicate check. as the client does this too, only malicious intent should be caught here ARR_FIND(0, i, k, RBUFW(itemlist,k * 6 + 0) - 2 == index); if( k != i ) { // Duplicate ShowWarning("buyingstore_trade: Found duplicate item on selling list (prevnameid=%hu, prevamount=%hu, nameid=%hu, amount=%hu, account_id=%d, char_id=%d).\n", RBUFW(itemlist,k * 6 + 2), RBUFW(itemlist,k * 6 + 4), nameid, amount, sd->status.account_id, sd->status.char_id); clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, nameid); return; } } if( index < 0 || index >= ARRAYLENGTH(sd->status.inventory) || sd->inventory_data[index] == NULL || sd->status.inventory[index].nameid != nameid || sd->status.inventory[index].amount < amount ) { // Invalid input clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, nameid); return; } if( sd->status.inventory[index].expire_time || (sd->status.inventory[index].bound && !pc_can_give_bounded_items(sd)) || !itemdb_cantrade(&sd->status.inventory[index], pc_get_group_level(sd), pc_get_group_level(pl_sd)) || memcmp(sd->status.inventory[index].card, buyingstore_blankslots, sizeof(buyingstore_blankslots)) ) { // Non-tradable item clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, nameid); return; } ARR_FIND(0, pl_sd->buyingstore.slots, listidx, pl_sd->buyingstore.items[listidx].nameid == nameid); // There is no such item or the buyer has already bought all of them if( listidx == pl_sd->buyingstore.slots || pl_sd->buyingstore.items[listidx].amount == 0 ) { clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, nameid); return; } // Buyer does not need that much of the item if( pl_sd->buyingstore.items[listidx].amount < amount ) { clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_COUNT, nameid); return; } // Buyer does not have enough space for this item if( pc_checkadditem(pl_sd, nameid, amount) == CHKADDITEM_OVERAMOUNT ) { clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, nameid); return; } // Normally this is not supposed to happen, as the total weight is // checked upon creation, but the buyer could have gained items if( amount * (unsigned int)sd->inventory_data[index]->weight > pl_sd->max_weight - weight ) { clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, nameid); return; } weight += amount * sd->inventory_data[index]->weight; // Buyer does not have enough zeny if( amount * pl_sd->buyingstore.items[listidx].price > pl_sd->buyingstore.zenylimit - zeny ) { clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_ZENY, nameid); return; } zeny += amount * pl_sd->buyingstore.items[listidx].price; } // Process item list for( i = 0; i < count; i++ ) { // itemlist: <index>.W <name id>.W <amount>.W unsigned short nameid, amount; int index; index = RBUFW(itemlist,i * 6 + 0) - 2; nameid = RBUFW(itemlist,i * 6 + 2); amount = RBUFW(itemlist,i * 6 + 4); ARR_FIND(0, pl_sd->buyingstore.slots, listidx, pl_sd->buyingstore.items[listidx].nameid == nameid); zeny = amount * pl_sd->buyingstore.items[listidx].price; // Move item pc_additem(pl_sd, &sd->status.inventory[index], amount, LOG_TYPE_BUYING_STORE); pc_delitem(sd, index, amount, 1, 0, LOG_TYPE_BUYING_STORE); pl_sd->buyingstore.items[listidx].amount -= amount; if( pl_sd->buyingstore.items[listidx].amount > 0 ) { if( Sql_Query(mmysql_handle, "UPDATE `%s` SET `amount` = %d WHERE `buyingstore_id` = %d AND `index` = %d;", buyingstore_items_db, pl_sd->buyingstore.items[listidx].amount, pl_sd->buyer_id, listidx) != SQL_SUCCESS ) Sql_ShowDebug(mmysql_handle); } else { if( Sql_Query(mmysql_handle, "DELETE FROM `%s` WHERE `buyingstore_id` = %d AND `index` = %d;", buyingstore_items_db, pl_sd->buyer_id, listidx) != SQL_SUCCESS ) Sql_ShowDebug(mmysql_handle); } // Pay up pc_payzeny(pl_sd, zeny, LOG_TYPE_BUYING_STORE, sd); pc_getzeny(sd, zeny, LOG_TYPE_BUYING_STORE, pl_sd); pl_sd->buyingstore.zenylimit -= zeny; // Notify clients clif_buyingstore_delete_item(sd, index, amount, pl_sd->buyingstore.items[listidx].price); clif_buyingstore_update_item(pl_sd, nameid, amount); } if( save_settings&128 ) { chrif_save(sd, 0); chrif_save(pl_sd, 0); } // Check whether or not there is still something to buy ARR_FIND(0, pl_sd->buyingstore.slots, i, pl_sd->buyingstore.items[i].amount != 0); if( i == pl_sd->buyingstore.slots ) // Everything was bought clif_buyingstore_trade_failed_buyer(pl_sd, BUYINGSTORE_TRADE_BUYER_NO_ITEMS); else if( pl_sd->buyingstore.zenylimit == 0 ) // Zeny limit reached clif_buyingstore_trade_failed_buyer(pl_sd, BUYINGSTORE_TRADE_BUYER_ZENY); else { // Continue buying if( Sql_Query(mmysql_handle, "UPDATE `%s` SET `limit` = %d WHERE `id` = %d;", buyingstores_db, pl_sd->buyingstore.zenylimit, pl_sd->buyer_id) != SQL_SUCCESS ) Sql_ShowDebug(mmysql_handle); return; } // Cannot continue buying buyingstore_close(pl_sd); // Remove auto-trader if( pl_sd->state.autotrade ) map_quit(pl_sd); }
/** * Purchase item(s) from a shop * @param sd : buyer player session * @param aid : account id of vender * @param uid : shop unique id * @param data : items data who would like to purchase * data := {<index>.w <amount>.w }[count] * @param count : number of different items he's trying to buy */ void vending_purchasereq(struct map_session_data *sd, int aid, int uid, const uint8 *data, int count) { int i, j, cursor, w, new_ = 0, blank, vend_list[MAX_VENDING]; double z; struct s_vending vending[MAX_VENDING]; //Against duplicate packets struct map_session_data *vsd = map_id2sd(aid); nullpo_retv(sd); if( vsd == NULL || !vsd->state.vending || vsd->bl.id == sd->bl.id ) return; //Invalid shop if( vsd->vender_id != uid ) { //Shop has changed clif_buyvending(sd, 0, 0, 6); //Store information was incorrect return; } if( !searchstore_queryremote(sd, aid) && ( sd->bl.m != vsd->bl.m || !check_distance_bl(&sd->bl, &vsd->bl, AREA_SIZE) ) ) return; //Shop too far away searchstore_clearremote(sd); if( count < 1 || count > MAX_VENDING || count > vsd->vend_num ) return; //Invalid amount of purchased items blank = pc_inventoryblank(sd); //Number of free cells in the buyer's inventory //Duplicate item in vending to check hacker with multiple packets memcpy(&vending, &vsd->vending, sizeof(vsd->vending)); //Copy vending list //Some checks z = 0.; //Zeny counter w = 0; //Weight counter for( i = 0; i < count; i++ ) { short amount = *(uint16 *)(data + 4 * i + 0); short idx = *(uint16 *)(data + 4 * i + 2); idx -= 2; if( amount <= 0 ) return; //Check of item index in the cart if( idx < 0 || idx >= MAX_CART ) return; ARR_FIND(0, vsd->vend_num, j, vsd->vending[j].index == idx); if( j == vsd->vend_num ) return; //Picked non-existing item else vend_list[i] = j; z += ((double)vsd->vending[j].value * (double)amount); if( z > (double)sd->status.zeny || z < 0. || z > (double)MAX_ZENY ) { clif_buyvending(sd, idx, amount, 1); //You don't have enough zeny return; } if( z + (double)vsd->status.zeny > (double)MAX_ZENY && !battle_config.vending_over_max ) { clif_buyvending(sd, idx, vsd->vending[j].amount, 4); //Too much zeny = overflow return; } w += itemdb_weight(vsd->cart.u.items_cart[idx].nameid) * amount; if( w + sd->weight > sd->max_weight ) { clif_buyvending(sd, idx, amount, 2); //You can not buy, because overweight return; } //Check to see if cart/vend info is in sync. if( vending[j].amount > vsd->cart.u.items_cart[idx].amount ) vending[j].amount = vsd->cart.u.items_cart[idx].amount; //If they try to add packets (example: get twice or more 2 apples if marchand has only 3 apples). //Here, we check cumulative amounts if( vending[j].amount < amount ) { //Send more quantity is not a hack (an other player can have buy items just before) clif_buyvending(sd, idx, vsd->vending[j].amount, 4); //Not enough quantity return; } vending[j].amount -= amount; switch( pc_checkadditem(sd, vsd->cart.u.items_cart[idx].nameid, amount) ) { case CHKADDITEM_EXIST: break; //We'd add this item to the existing one (in buyers inventory) case CHKADDITEM_NEW: new_++; if (new_ > blank) return; //Buyer has no space in his inventory break; case CHKADDITEM_OVERAMOUNT: return; //too many items } } pc_payzeny(sd, (int)z, LOG_TYPE_VENDING, vsd); achievement_update_objective(sd, AG_SPEND_ZENY, 1, (int)z); z = vending_calc_tax(sd, z); pc_getzeny(vsd, (int)z, LOG_TYPE_VENDING, sd); for( i = 0; i < count; i++ ) { short amount = *(uint16 *)(data + 4 * i + 0); short idx = *(uint16 *)(data + 4 * i + 2); idx -= 2; z = 0.; //Zeny counter //Vending item pc_additem(sd, &vsd->cart.u.items_cart[idx], amount, LOG_TYPE_VENDING); vsd->vending[vend_list[i]].amount -= amount; z += ((double)vsd->vending[i].value * (double)amount); if( vsd->vending[vend_list[i]].amount ) { if( Sql_Query(mmysql_handle, "UPDATE `%s` SET `amount` = %d WHERE `vending_id` = %d and `cartinventory_id` = %d", vending_items_db, vsd->vending[vend_list[i]].amount, vsd->vender_id, vsd->cart.u.items_cart[idx].id) != SQL_SUCCESS ) Sql_ShowDebug(mmysql_handle); } else { if( Sql_Query(mmysql_handle, "DELETE FROM `%s` WHERE `vending_id` = %d and `cartinventory_id` = %d", vending_items_db, vsd->vender_id, vsd->cart.u.items_cart[idx].id) != SQL_SUCCESS ) Sql_ShowDebug(mmysql_handle); } pc_cart_delitem(vsd, idx, amount, 0, LOG_TYPE_VENDING); z = vending_calc_tax(sd, z); clif_vendingreport(vsd, idx, amount, sd->status.char_id, (int)z); //Print buyer's name if( battle_config.buyer_name ) { char temp[256]; sprintf(temp, msg_txt(265), sd->status.name); clif_messagecolor(&vsd->bl, color_table[COLOR_LIGHT_GREEN], temp, false, SELF); } } //Compact the vending list for( i = 0, cursor = 0; i < vsd->vend_num; i++ ) { if( vsd->vending[i].amount == 0 ) continue; if( cursor != i ) { //Speedup vsd->vending[cursor].index = vsd->vending[i].index; vsd->vending[cursor].amount = vsd->vending[i].amount; vsd->vending[cursor].value = vsd->vending[i].value; } cursor++; } vsd->vend_num = cursor; //Always save BOTH: customer (buyer) and vender if( save_settings&CHARSAVE_VENDING ) { chrif_save(sd,CSAVE_INVENTORY|CSAVE_CART); chrif_save(vsd,CSAVE_INVENTORY|CSAVE_CART); } //Check for @AUTOTRADE users [durf] if( vsd->state.autotrade ) { //See if there is anything left in the shop ARR_FIND(0, vsd->vend_num, i, vsd->vending[i].amount > 0); if( i == vsd->vend_num ) { //Close Vending (this was automatically done by the client, we have to do it manually for autovenders) [Skotlex] vending_closevending(vsd); map_quit(vsd); //They have no reason to stay around anymore, do they? } } }
int guild_recv_memberinfoshort(int guild_id,int account_id,int char_id,int online,int lv,int class_) { // cleaned up [LuzZza] int i,alv,c,idx=-1,om=0,oldonline=-1; struct guild *g = guild_search(guild_id); if(g == NULL) return 0; for(i=0,alv=0,c=0,om=0;i<g->max_member;i++){ struct guild_member *m=&g->member[i]; if(!m->account_id) continue; if(m->account_id==account_id && m->char_id==char_id ){ oldonline=m->online; m->online=online; m->lv=lv; m->class_=class_; idx=i; } alv+=m->lv; c++; if(m->online) om++; } if(idx == -1 || c == 0) { // ギルドのメンバー外なので追放扱いする struct map_session_data *sd = map_id2sd(account_id); if(sd && sd->status.char_id == char_id) { sd->status.guild_id=0; sd->guild_emblem_id=0; } ShowWarning("guild: not found member %d,%d on %d[%s]\n", account_id,char_id,guild_id,g->name); return 0; } g->average_lv=alv/c; g->connect_member=om; //Ensure validity of pointer (ie: player logs in/out, changes map-server) g->member[idx].sd = guild_sd_check(guild_id, account_id, char_id); if(oldonline!=online) clif_guild_memberlogin_notice(g, idx, online); if(!g->member[idx].sd) return 0; //Send XY dot updates. [Skotlex] //Moved from guild_send_memberinfoshort [LuzZza] for(i=0; i < g->max_member; i++) { if(!g->member[i].sd || i == idx || g->member[i].sd->bl.m != g->member[idx].sd->bl.m) continue; clif_guild_xy_single(g->member[idx].sd->fd, g->member[i].sd); clif_guild_xy_single(g->member[i].sd->fd, g->member[idx].sd); } return 0; }
// ギルド同盟/敵対通知 int guild_allianceack(int guild_id1,int guild_id2,int account_id1,int account_id2,int flag,const char *name1,const char *name2) { struct guild *g[2]; int guild_id[2]; const char *guild_name[2]; struct map_session_data *sd[2]; int j,i; guild_id[0] = guild_id1; guild_id[1] = guild_id2; guild_name[0] = name1; guild_name[1] = name2; sd[0] = map_id2sd(account_id1); sd[1] = map_id2sd(account_id2); g[0]=guild_search(guild_id1); g[1]=guild_search(guild_id2); if(sd[0]!=NULL && (flag&0x0f)==0){ sd[0]->guild_alliance=0; sd[0]->guild_alliance_account=0; } if(flag&0x70){ // 失敗 for(i=0;i<2-(flag&1);i++) if( sd[i]!=NULL ) clif_guild_allianceack(sd[i],((flag>>4)==i+1)?3:4); return 0; } if(!(flag&0x08)){ // 関係追加 for(i=0;i<2-(flag&1);i++) { if(g[i]!=NULL) { ARR_FIND( 0, MAX_GUILDALLIANCE, j, g[i]->alliance[j].guild_id == 0 ); if( j < MAX_GUILDALLIANCE ) { g[i]->alliance[j].guild_id=guild_id[1-i]; memcpy(g[i]->alliance[j].name,guild_name[1-i],NAME_LENGTH); g[i]->alliance[j].opposition=flag&1; } } } }else{ // 関係解消 for(i=0;i<2-(flag&1);i++) { if(g[i]!=NULL) { ARR_FIND( 0, MAX_GUILDALLIANCE, j, g[i]->alliance[j].guild_id == guild_id[1-i] && g[i]->alliance[j].opposition == (flag&1) ); if( j < MAX_GUILDALLIANCE ) g[i]->alliance[j].guild_id = 0; } if( sd[i]!=NULL ) // 解消通知 clif_guild_delalliance(sd[i],guild_id[1-i],(flag&1)); } } if((flag&0x0f)==0){ // 同盟通知 if( sd[1]!=NULL ) clif_guild_allianceack(sd[1],2); }else if((flag&0x0f)==1){ // 敵対通知 if( sd[0]!=NULL ) clif_guild_oppositionack(sd[0],0); } for(i=0;i<2-(flag&1);i++){ // 同盟/敵対リストの再送信 struct map_session_data *sd; if(g[i]!=NULL) for(j=0;j<g[i]->max_member;j++) if((sd=g[i]->member[j].sd)!=NULL) clif_guild_allianceinfo(sd); } return 0; }
/* Process party invitation from sd to account_id. */ int party_invite(dumb_ptr<map_session_data> sd, int account_id) { dumb_ptr<map_session_data> tsd = map_id2sd(account_id); struct party *p = party_search(sd->status.party_id); int i; int full = 1; /* Indicates whether or not there's room for one more. */ nullpo_ret(sd); if (!tsd || !p || !tsd->fd) return 0; if (!battle_config.invite_request_check) { /* Disallow the invitation under these conditions. */ if (tsd->trade_partner || tsd->npc_id || tsd->npc_shopid || pc_checkskill(tsd, SkillID::NV_PARTY) < 1) { clif_party_inviteack(sd, tsd->status.name, 1); return 0; } } /* The target player is already in a party, or has a pending invitation. */ if (tsd->status.party_id > 0 || tsd->party_invite > 0) { clif_party_inviteack(sd, tsd->status.name, 0); return 0; } for (i = 0; i < MAX_PARTY; i++) { /* * A character from the target account is already in the same party. * The response isn't strictly accurate, as they're separate * characters, but we're making do with what was already in place and * leaving this (mostly) alone for now. */ if (p->member[i].account_id == account_id) { clif_party_inviteack(sd, tsd->status.name, 1); return 0; } if (!p->member[i].account_id) full = 0; } /* There isn't enough room for a new member. */ if (full) { clif_party_inviteack(sd, tsd->status.name, 3); return 0; } /* Otherwise, relay the invitation to the target player. */ tsd->party_invite = sd->status.party_id; tsd->party_invite_account = sd->status.account_id; clif_party_invite(sd, tsd); return 0; }
/// Invoked (from char-server) when a new member is added to the party. /// flag: 0-success, 1-failure int party_member_added(int party_id,int account_id,int char_id, int flag) { struct map_session_data *sd = map_id2sd(account_id),*sd2; struct party_data *p = party_search(party_id); int i; if(sd == NULL || sd->status.char_id != char_id || !sd->party_joining ) { if (!flag) //Char logged off before being accepted into party. intif_party_leave(party_id,account_id,char_id); return 0; } sd2 = map_id2sd(sd->party_invite_account); sd->party_joining = false; sd->party_invite = 0; sd->party_invite_account = 0; if (!p) { ShowError("party_member_added: party %d not found.\n",party_id); intif_party_leave(party_id,account_id,char_id); return 0; } if( flag ) {// failed if( sd2 != NULL ) clif_party_inviteack(sd2,sd->status.name,3); return 0; } sd->status.party_id = party_id; ARR_FIND( 0, MAX_PARTY, i, p->party.member[i].account_id == 0 ); if (i < MAX_PARTY) { //TODO: This is a hack to allow the following clif calls to send the data to the new player. //The correct player data is set when party_recv_info arrives soon afterwards. party_fill_member(&p->party.member[i], sd); p->data[i].sd = sd; } clif_party_member_info(p,sd); clif_party_option(p,sd,0x100); clif_party_info(p,sd); if( sd2 != NULL ) clif_party_inviteack(sd2,sd->status.name,2); for( i = 0; i < ARRAYLENGTH(p->data); ++i ) {// hp of the other party members sd2 = p->data[i].sd; if( sd2 && sd2->status.account_id != account_id && sd2->status.char_id != char_id ) clif_hpmeter_single(sd->fd, sd2->bl.id, sd2->battle_status.hp, sd2->battle_status.max_hp); } clif_party_hp(sd); clif_party_xy(sd); clif_charnameupdate(sd); //Update char name's display [Skotlex] if( p->instance_id ) clif_instance_join(sd->fd, p->instance_id); return 0; }
/*========================================== * Purchase item(s) from a shop *------------------------------------------*/ void vending_purchasereq(struct map_session_data* sd, int id, const uint8* data, int count) { int i, j, cursor, w, new_ = 0, blank, vend_list[MAX_VENDING]; double z; struct s_vending vending[MAX_VENDING]; // against duplicate packets struct map_session_data* vsd = map_id2sd(id); nullpo_retv(sd); if( vsd == NULL || vsd->vender_id == 0 || vsd->vender_id == sd->bl.id ) return; // invalid shop if( sd->bl.m != vsd->bl.m || !check_distance_bl(&sd->bl, &vsd->bl, AREA_SIZE) ) return; // shop too far away if( count < 1 || count > MAX_VENDING || count > vsd->vend_num ) return; // invalid amount of purchased items blank = pc_inventoryblank(sd); //number of free cells in the buyer's inventory // duplicate item in vending to check hacker with multiple packets memcpy(&vending, &vsd->vending, sizeof(vsd->vending)); // copy vending list // some checks z = 0.; // zeny counter w = 0; // weight counter for( i = 0; i < count; i++ ) { unsigned short amount = *(uint16*)(data + 4*i + 0); short idx = *(uint16*)(data + 4*i + 2); idx -= 2; if( amount <= 0 ) return; // check of item index in the cart if( idx < 0 || idx >= MAX_CART ) return; ARR_FIND( 0, vsd->vend_num, j, vsd->vending[j].index == idx ); if( j == vsd->vend_num ) return; //picked non-existing item else vend_list[i] = j; z += ((double)vsd->vending[j].value * (double)amount); if( z > (double)sd->status.zeny || z < 0. || z > (double)MAX_ZENY ) { clif_buyvending(sd, idx, amount, 1); // you don't have enough zeny return; } w += itemdb_weight(vsd->status.cart[idx].nameid) * amount; if( w + sd->weight > sd->max_weight ) { clif_buyvending(sd, idx, amount, 2); // you can not buy, because overweight return; } //Check to see if cart/vend info is in sync. if( vending[j].amount > vsd->status.cart[idx].amount ) vending[j].amount = vsd->status.cart[idx].amount; // if they try to add packets (example: get twice or more 2 apples if marchand has only 3 apples). // here, we check cumulative amounts if( vending[j].amount < amount ) { // send more quantity is not a hack (an other player can have buy items just before) clif_buyvending(sd, idx, vsd->vending[j].amount, 4); // not enough quantity return; } vending[j].amount -= amount; switch( pc_checkadditem(sd, vsd->status.cart[idx].nameid, amount) ) { case ADDITEM_EXIST: break; //We'd add this item to the existing one (in buyers inventory) case ADDITEM_NEW: new_++; if (new_ > blank) return; //Buyer has no space in his inventory break; case ADDITEM_OVERAMOUNT: return; //too many items } } //Logs (V)ending Zeny [Lupus] if( log_config.zeny > 0 ) log_zeny(vsd, "V", sd, (int)z); pc_payzeny(sd, (int)z); if( battle_config.vending_tax ) z -= z * (battle_config.vending_tax/10000.); pc_getzeny(vsd, (int)z); for( i = 0; i < count; i++ ) { unsigned short amount = *(uint16*)(data + 4*i + 0); short idx = *(uint16*)(data + 4*i + 2); idx -= 2; //Logs sold (V)ending items [Lupus] if(log_config.enable_logs&0x4) { log_pick_pc(vsd, "V", vsd->status.cart[idx].nameid, -amount, &vsd->status.cart[idx]); log_pick_pc( sd, "V", vsd->status.cart[idx].nameid, amount, &vsd->status.cart[idx]); } // vending item pc_additem(sd, &vsd->status.cart[idx], amount); vsd->vending[vend_list[i]].amount -= amount; pc_cart_delitem(vsd, idx, amount, 0); clif_vendingreport(vsd, idx, amount); //print buyer's name if( battle_config.buyer_name ) { char temp[256]; sprintf(temp, msg_txt(265), sd->status.name); clif_disp_onlyself(vsd,temp,strlen(temp)); } } // compact the vending list for( i = 0, cursor = 0; i < vsd->vend_num; i++ ) { if( vsd->vending[i].amount == 0 ) continue; if( cursor != i ) // speedup { vsd->vending[cursor].index = vsd->vending[i].index; vsd->vending[cursor].amount = vsd->vending[i].amount; vsd->vending[cursor].value = vsd->vending[i].value; } cursor++; } vsd->vend_num = cursor; //Always save BOTH: buyer and customer if( save_settings&2 ) { chrif_save(sd,0); chrif_save(vsd,0); } //check for @AUTOTRADE users [durf] if( vsd->state.autotrade ) { //see if there is anything left in the shop ARR_FIND( 0, vsd->vend_num, i, vsd->vending[i].amount > 0 ); if( i == vsd->vend_num ) { //Close Vending (this was automatically done by the client, we have to do it manually for autovenders) [Skotlex] vending_closevending(vsd); map_quit(vsd); //They have no reason to stay around anymore, do they? } } }