/** * 'Cancel' is pressed. (or trade was force-cancelled by the code) * @param sd : Player that pressed the button */ void trade_tradecancel(struct map_session_data *sd) { struct map_session_data *target_sd; int trade_i; nullpo_retv(sd); target_sd = map_id2sd(sd->trade_partner); sd->state.isBoundTrading = 0; if(!sd->state.trading) { // Not trade accepted if( target_sd ) { target_sd->trade_partner = 0; clif_tradecancelled(target_sd); } sd->trade_partner = 0; clif_tradecancelled(sd); return; } for(trade_i = 0; trade_i < 10; trade_i++) { // give items back (only virtual) if (!sd->deal.item[trade_i].amount) continue; clif_additem(sd, sd->deal.item[trade_i].index, sd->deal.item[trade_i].amount, 0); sd->deal.item[trade_i].index = 0; sd->deal.item[trade_i].amount = 0; } if (sd->deal.zeny) { clif_updatestatus(sd, SP_ZENY); sd->deal.zeny = 0; } sd->state.deal_locked = 0; sd->state.trading = 0; sd->trade_partner = 0; clif_tradecancelled(sd); if (!target_sd) return; for(trade_i = 0; trade_i < 10; trade_i++) { // give items back (only virtual) if (!target_sd->deal.item[trade_i].amount) continue; clif_additem(target_sd, target_sd->deal.item[trade_i].index, 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 (target_sd->deal.zeny) { clif_updatestatus(target_sd, SP_ZENY); target_sd->deal.zeny = 0; } target_sd->state.deal_locked = 0; target_sd->trade_partner = 0; target_sd->state.trading = 0; clif_tradecancelled(target_sd); }
/*========================================== * 取引キャンセル *------------------------------------------ */ void trade_tradecancel(dumb_ptr<map_session_data> sd) { dumb_ptr<map_session_data> target_sd; int trade_i; nullpo_retv(sd); if ((target_sd = map_id2sd(account_to_block(sd->trade_partner))) != nullptr) { for (trade_i = 0; trade_i < TRADE_MAX; trade_i++) { //give items back (only virtual) if (sd->deal_item_amount[trade_i] != 0) { assert (sd->deal_item_index[trade_i].ok()); clif_additem(sd, sd->deal_item_index[trade_i].unshift(), sd->deal_item_amount[trade_i], PickupFail::OKAY); sd->deal_item_index[trade_i] = IOff2::from(0); sd->deal_item_amount[trade_i] = 0; } if (target_sd->deal_item_amount[trade_i] != 0) { assert (target_sd->deal_item_index[trade_i].ok()); clif_additem(target_sd, target_sd->deal_item_index[trade_i].unshift(), target_sd->deal_item_amount[trade_i], PickupFail::OKAY); target_sd->deal_item_index[trade_i] = IOff2::from(0); target_sd->deal_item_amount[trade_i] = 0; } } if (sd->deal_zeny) { sd->deal_zeny = 0; clif_updatestatus(sd, SP::ZENY); } if (target_sd->deal_zeny) { clif_updatestatus(target_sd, SP::ZENY); target_sd->deal_zeny = 0; } sd->deal_locked = 0; sd->trade_partner = AccountId(); target_sd->deal_locked = 0; target_sd->trade_partner = AccountId(); clif_tradecancelled(sd); clif_tradecancelled(target_sd); } }
/*========================================== * 取引キャンセル *------------------------------------------ */ void trade_tradecancel(dumb_ptr<map_session_data> sd) { dumb_ptr<map_session_data> target_sd; int trade_i; nullpo_retv(sd); if ((target_sd = map_id2sd(sd->trade_partner)) != NULL) { for (trade_i = 0; trade_i < 10; trade_i++) { //give items back (only virtual) if (sd->deal_item_amount[trade_i] != 0) { clif_additem(sd, sd->deal_item_index[trade_i] - 2, sd->deal_item_amount[trade_i], PickupFail::OKAY); sd->deal_item_index[trade_i] = 0; sd->deal_item_amount[trade_i] = 0; } if (target_sd->deal_item_amount[trade_i] != 0) { clif_additem(target_sd, target_sd->deal_item_index[trade_i] - 2, target_sd->deal_item_amount[trade_i], PickupFail::OKAY); target_sd->deal_item_index[trade_i] = 0; target_sd->deal_item_amount[trade_i] = 0; } } if (sd->deal_zeny) { sd->deal_zeny = 0; clif_updatestatus(sd, SP::ZENY); } if (target_sd->deal_zeny) { clif_updatestatus(target_sd, SP::ZENY); target_sd->deal_zeny = 0; } sd->deal_locked = 0; sd->trade_partner = 0; target_sd->deal_locked = 0; target_sd->trade_partner = 0; clif_tradecancelled(sd); clif_tradecancelled(target_sd); } }
void mail_deliveryfail(struct map_session_data *sd, struct mail_message *msg) { nullpo_retv(sd); nullpo_retv(msg); if( msg->item.amount > 0 ) { // Item recieve (due to failure) if(log_config.enable_logs&0x2000) log_pick_pc(sd, "E", msg->item.nameid, msg->item.amount, &msg->item, msg->item.serial); if( battle_config.lootevent & 8 ) { pc_setglobalreg( sd, "LastLootID", msg->item.nameid ); //Last lootet Item ID pc_setglobalreg( sd, "LastLootAmount", msg->item.amount ); //Last looted Item Amount npc_event_doall_id( "OnLoot", sd->bl.id ); } pc_additem(sd, &msg->item, msg->item.amount); } if( msg->zeny > 0 ) { //Zeny recieve (due to failure) if(log_config.zeny) log_zeny(sd, "E", sd, msg->zeny); sd->status.zeny += msg->zeny; clif_updatestatus(sd, SP_ZENY); } clif_Mail_send(sd->fd, true); }
/*========================================== * 取引キャンセル *------------------------------------------ */ void trade_tradecancel(struct map_session_data *sd) { struct map_session_data *target_sd; int trade_i; nullpo_retv(sd); target_sd = map_id2sd(sd->trade.partner); if(target_sd && target_sd->bl.prev) { for(trade_i = 0; trade_i < MAX_DEAL_ITEMS; trade_i++) { //give items back (only virtual) if(target_sd->trade.item_amount[trade_i] != 0) { clif_additem(target_sd,target_sd->trade.item_index[trade_i]-2,target_sd->trade.item_amount[trade_i],0); target_sd->trade.item_index[trade_i] = 0; target_sd->trade.item_amount[trade_i] = 0; } } if(target_sd->trade.zeny) { clif_updatestatus(target_sd,SP_ZENY); target_sd->trade.zeny = 0; } target_sd->state.deal_locked = 0; target_sd->state.deal_mode = 0; target_sd->trade.partner = 0; clif_tradecancelled(target_sd); } for(trade_i = 0; trade_i < MAX_DEAL_ITEMS; trade_i++) { //give items back (only virtual) if (sd->trade.item_amount[trade_i] != 0) { clif_additem(sd, sd->trade.item_index[trade_i]-2, sd->trade.item_amount[trade_i], 0); sd->trade.item_index[trade_i] = 0; sd->trade.item_amount[trade_i] = 0; } } if (sd->trade.zeny) { clif_updatestatus(sd, SP_ZENY); sd->trade.zeny = 0; } sd->state.deal_locked = 0; sd->state.deal_mode = 0; sd->trade.partner = 0; clif_tradecancelled(sd); return; }
/*========================================== * 性別変化終了 (modified by Yor) *------------------------------------------*/ int chrif_changedsex(int fd) { int acc, sex, i; struct map_session_data *sd; acc = RFIFOL(fd,2); sex = RFIFOL(fd,6); if (battle_config.etc_log) ShowNotice("chrif_changedsex %d.\n", acc); sd = map_id2sd(acc); if (sd) { //Normally there should not be a char logged on right now! if (sd->status.sex == sex) return 0; //Do nothing? Likely safe. sd->status.sex = !sd->status.sex; // reset skill of some job if ((sd->class_&MAPID_UPPERMASK) == MAPID_BARDDANCER) { // remove specifical skills of Bard classes for(i = 315; i <= 322; i++) { if (sd->status.skill[i].id > 0 && !sd->status.skill[i].flag) { if (sd->status.skill_point > USHRT_MAX - sd->status.skill[i].lv) sd->status.skill_point = USHRT_MAX; else sd->status.skill_point += sd->status.skill[i].lv; sd->status.skill[i].id = 0; sd->status.skill[i].lv = 0; } } // remove specifical skills of Dancer classes for(i = 323; i <= 330; i++) { if (sd->status.skill[i].id > 0 && !sd->status.skill[i].flag) { if (sd->status.skill_point > USHRT_MAX - sd->status.skill[i].lv) sd->status.skill_point = USHRT_MAX; else sd->status.skill_point += sd->status.skill[i].lv; sd->status.skill[i].id = 0; sd->status.skill[i].lv = 0; } } clif_updatestatus(sd, SP_SKILLPOINT); // change job if necessary if (sd->status.sex) //Changed from Dancer sd->status.class_ -= 1; else //Changed from Bard sd->status.class_ += 1; //sd->class_ needs not be updated as both Dancer/Bard are the same. } // save character sd->login_id1++; // change identify, because if player come back in char within the 5 seconds, he can change its characters // do same modify in login-server for the account, but no in char-server (it ask again login_id1 to login, and don't remember it) clif_displaymessage(sd->fd, "Your sex has been changed (need disconnection by the server)..."); clif_setwaitclose(sd->fd); // forced to disconnect for the change } return 0; }
int mail_removezeny(struct map_session_data *sd, short flag) { nullpo_ret(sd); if (flag && sd->mail.zeny > 0) { //Zeny send pc_payzeny(sd,sd->mail.zeny,LOG_TYPE_MAIL, NULL); } if (sd->mail.zeny > 0) clif_updatestatus(sd, SP_ZENY); sd->mail.zeny = 0; return 1; }
/*========================================== * 取引キャンセル *------------------------------------------ */ void trade_tradecancel(struct map_session_data *sd) { struct map_session_data *target_sd; int trade_i; nullpo_retv(sd); if ((target_sd = map_id2sd(sd->trade_partner)) != NULL) { for(trade_i = 0; trade_i < 10; trade_i++) { // give items back (only virtual) if (sd->deal.item[trade_i].amount != 0) { clif_additem(sd, sd->deal.item[trade_i].index, 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) { clif_additem(target_sd, target_sd->deal.item[trade_i].index, 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) { clif_updatestatus(sd, SP_ZENY); sd->deal.zeny = 0; } if (target_sd->deal.zeny) { 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_tradecancelled(sd); clif_tradecancelled(target_sd); } }
int mail_removezeny(struct map_session_data *sd, short flag) { nullpo_ret(sd); if (flag && sd->mail.zeny > 0) { //Zeny send log_zeny(sd, LOG_TYPE_MAIL, sd, -sd->mail.zeny); sd->status.zeny -= sd->mail.zeny; } sd->mail.zeny = 0; clif_updatestatus(sd, SP_ZENY); return 1; }
int mail_removezeny(struct map_session_data *sd, short flag) { nullpo_retr(0,sd); if (flag && sd->mail.zeny > 0) { //Zeny send if(log_config.zeny) log_zeny(sd, "E", sd, -sd->mail.zeny); sd->status.zeny -= sd->mail.zeny; } sd->mail.zeny = 0; clif_updatestatus(sd, SP_ZENY); return 1; }
void mail_deliveryfail(struct map_session_data *sd, struct mail_message *msg) { nullpo_retv(sd); nullpo_retv(msg); if( msg->item.amount > 0 ) pc_additem(sd, &msg->item, msg->item.amount, LOG_TYPE_MAIL); if( msg->zeny > 0 ) { //Zeny recieve (due to failure) log_zeny(sd, LOG_TYPE_MAIL, sd, msg->zeny); sd->status.zeny += msg->zeny; clif_updatestatus(sd, SP_ZENY); } clif_Mail_send(sd->fd, true); }
bool mail_removezeny( struct map_session_data *sd, bool flag ){ nullpo_retr( false, sd ); if( sd->mail.zeny > 0 ){ //Zeny send if( flag ){ if( pc_payzeny( sd, sd->mail.zeny + sd->mail.zeny * battle_config.mail_zeny_fee / 100, LOG_TYPE_MAIL, NULL ) ){ return false; } }else{ // Update is called by pc_payzeny, so only call it in the else condition clif_updatestatus(sd, SP_ZENY); } } sd->mail.zeny = 0; return true; }
void mail_deliveryfail(struct map_session_data *sd, struct mail_message *msg) { nullpo_retv(sd); nullpo_retv(msg); // Item recieve (due to failure) if(log_config.enable_logs&0x2000) log_pick_pc(sd, "E", msg->item.nameid, msg->item.amount, &msg->item); pc_additem(sd, &msg->item, msg->item.amount); if( msg->zeny > 0 ) { //Zeny recieve (due to failure) if(log_config.zeny) log_zeny(sd, "E", sd, msg->zeny); sd->status.zeny += msg->zeny; clif_updatestatus(sd, SP_ZENY); } clif_Mail_send(sd->fd, true); }
/*========================================== * 性別変化終了 (modified by Yor) *------------------------------------------*/ int chrif_changedsex(int fd) { int acc, sex, i; struct map_session_data *sd; acc = RFIFOL(fd,2); sex = RFIFOL(fd,6); if (battle_config.etc_log) ShowNotice("chrif_changedsex %d.\n", acc); sd = map_id2sd(acc); if (acc > 0) { if (sd != NULL && sd->status.sex != sex) { sd->status.sex = !sd->status.sex; // to avoid any problem with equipment and invalid sex, equipment is unequiped. for (i = 0; i < EQI_MAX; i++) { if (sd->equip_index[i] >= 0) pc_unequipitem((struct map_session_data*)sd, sd->equip_index[i], 2); } // reset skill of some job if ((sd->class_&MAPID_UPPERMASK) == MAPID_BARDDANCER) { // remove specifical skills of Bard classes for(i = 315; i <= 322; i++) { if (sd->status.skill[i].id > 0 && !sd->status.skill[i].flag) { if (sd->status.skill_point > USHRT_MAX - sd->status.skill[i].lv) sd->status.skill_point = USHRT_MAX; else sd->status.skill_point += sd->status.skill[i].lv; sd->status.skill[i].id = 0; sd->status.skill[i].lv = 0; } } // remove specifical skills of Dancer classes for(i = 323; i <= 330; i++) { if (sd->status.skill[i].id > 0 && !sd->status.skill[i].flag) { if (sd->status.skill_point > USHRT_MAX - sd->status.skill[i].lv) sd->status.skill_point = USHRT_MAX; else sd->status.skill_point += sd->status.skill[i].lv; sd->status.skill[i].id = 0; sd->status.skill[i].lv = 0; } } clif_updatestatus(sd, SP_SKILLPOINT); // change job if necessary if (sd->status.sex) //Changed from Dancer sd->status.class_ -= 1; else //Changed from Bard sd->status.class_ += 1; //sd->class_ needs not be updated as both Dancer/Bard are the same. } // save character //chrif_save(sd,1); Character will be saved on session closed -> map_quit sd->login_id1++; // change identify, because if player come back in char within the 5 seconds, he can change its characters // do same modify in login-server for the account, but no in char-server (it ask again login_id1 to login, and don't remember it) clif_displaymessage(sd->fd, "Your sex has been changed (need disconnection by the server)..."); clif_setwaitclose(sd->fd); // forced to disconnect for the change } } else { if (sd != NULL) { ShowError("chrif_changedsex failed.\n"); } } return 0; }
/*========================================== * lock sd and tsd trade data, execute the trade, clear, then save players *------------------------------------------*/ void trade_tradecommit(struct map_session_data *sd) { struct map_session_data *tsd; int trade_i; int flag; 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; if (sd->deal.item[trade_i].amount) { n = sd->deal.item[trade_i].index; flag = pc_additem(tsd, &sd->status.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->status.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 || tsd->deal.zeny ) { sd->status.zeny += tsd->deal.zeny - sd->deal.zeny; tsd->status.zeny += sd->deal.zeny - tsd->deal.zeny; //Logs Zeny (T)rade [Lupus] if( sd->deal.zeny ) log_zeny(tsd, LOG_TYPE_TRADE, sd, sd->deal.zeny); if( tsd->deal.zeny ) log_zeny(sd, LOG_TYPE_TRADE, tsd, tsd->deal.zeny); sd->deal.zeny = 0; tsd->deal.zeny = 0; clif_updatestatus(sd, SP_ZENY); clif_updatestatus(tsd, SP_ZENY); } sd->state.deal_locked = 0; sd->trade_partner = 0; sd->state.trading = 0; tsd->state.deal_locked = 0; tsd->trade_partner = 0; tsd->state.trading = 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&1) { chrif_save(sd,0); chrif_save(tsd,0); } }
/*========================================== * 取引許諾(trade押し) *------------------------------------------ */ void trade_tradecommit(struct map_session_data *sd) { struct map_session_data *target_sd; nullpo_retv(sd); target_sd = map_id2sd(sd->trade.partner); if(target_sd && target_sd->bl.prev) { 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 int trade_i, idx, flag; // checks quantity of items if (!trade_check(sd, target_sd)) { // this function do like the real trade, but with virtual inventories trade_tradecancel(sd); return; } // check zenys if (sd->trade.zeny > sd->status.zeny || target_sd->trade.zeny > target_sd->status.zeny || sd->status.zeny - sd->trade.zeny + target_sd->trade.zeny > MAX_ZENY || target_sd->status.zeny - target_sd->trade.zeny + sd->trade.zeny > MAX_ZENY) { trade_tradecancel(sd); return; } // do trade // ---- of items for(trade_i = 0; trade_i < MAX_DEAL_ITEMS; trade_i++) { if(sd->trade.item_amount[trade_i] != 0) { idx = sd->trade.item_index[trade_i] - 2; if (itemdb_isdropable(sd->status.inventory[idx].nameid)) { flag = pc_additem(target_sd, &sd->status.inventory[idx], sd->trade.item_amount[trade_i]); if(flag==0) pc_delitem(sd, idx, sd->trade.item_amount[trade_i], 1, 0); else clif_additem(sd, idx, sd->trade.item_amount[trade_i], 0); } sd->trade.item_amount[trade_i] = 0; } sd->trade.item_index[trade_i] = 0; if(target_sd->trade.item_amount[trade_i] != 0) { idx = target_sd->trade.item_index[trade_i] - 2; if (itemdb_isdropable(target_sd->status.inventory[idx].nameid)) { flag = pc_additem(sd, &target_sd->status.inventory[idx], target_sd->trade.item_amount[trade_i]); if(flag==0) pc_delitem(target_sd, idx, target_sd->trade.item_amount[trade_i], 1, 0); else clif_additem(target_sd, idx, target_sd->trade.item_amount[trade_i], 0); } target_sd->trade.item_amount[trade_i] = 0; } target_sd->trade.item_index[trade_i] = 0; } // ---- of zenys if(sd->trade.zeny || target_sd->trade.zeny) { sd->status.zeny = sd->status.zeny - sd->trade.zeny + target_sd->trade.zeny; target_sd->status.zeny = target_sd->status.zeny - target_sd->trade.zeny + sd->trade.zeny; clif_updatestatus(sd, SP_ZENY); clif_updatestatus(target_sd, SP_ZENY); } sd->trade.zeny = 0; target_sd->trade.zeny = 0; // clean up variables sd->state.deal_locked = 0; sd->state.deal_mode = 0; sd->trade.partner = 0; target_sd->state.deal_locked = 0; target_sd->state.deal_mode = 0; target_sd->trade.partner = 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); chrif_save(target_sd,0); } } } else { trade_tradecancel(sd); } return; }
/*========================================== * 取引許諾(trade押し) *------------------------------------------ */ void trade_tradecommit(dumb_ptr<map_session_data> sd) { dumb_ptr<map_session_data> target_sd; int trade_i; nullpo_retv(sd); if ((target_sd = map_id2sd(account_to_block(sd->trade_partner))) != nullptr) { MAP_LOG_PC(sd, " TRADECOMMIT WITH %d GIVE %d GET %d"_fmt, target_sd->status_key.char_id, sd->deal_zeny, target_sd->deal_zeny); if ((sd->deal_locked >= 1) && (target_sd->deal_locked >= 1)) { // both have pressed 'ok' if (sd->deal_locked < 2) { sd->deal_locked = 2; } // set locked to 2 if (target_sd->deal_locked == 2) { // the other one pressed 'trade' too if (sd->deal_zeny > sd->status.zeny) { sd->deal_zeny = 0; trade_tradecancel(sd); MAP_LOG_PC(sd, " TRADECANCEL"_fmt); return; } if (target_sd->deal_zeny > target_sd->status.zeny) { target_sd->deal_zeny = 0; trade_tradecancel(sd); MAP_LOG_PC(sd, " TRADECANCEL"_fmt); return; } sd->trade_partner = AccountId(); target_sd->trade_partner = AccountId(); for (trade_i = 0; trade_i < TRADE_MAX; trade_i++) { if (sd->deal_item_amount[trade_i] != 0) { assert (sd->deal_item_index[trade_i].ok()); IOff0 n = sd->deal_item_index[trade_i].unshift(); PickupFail flag = pc_additem(target_sd, &sd->status.inventory[n], sd->deal_item_amount[trade_i]); if (flag == PickupFail::OKAY) pc_delitem(sd, n, sd->deal_item_amount[trade_i], 1); else clif_additem(sd, n, sd->deal_item_amount[trade_i], PickupFail::OKAY); sd->deal_item_index[trade_i] = IOff2::from(0); sd->deal_item_amount[trade_i] = 0; } if (target_sd->deal_item_amount[trade_i] != 0) { assert (target_sd->deal_item_index[trade_i].ok()); IOff0 n = target_sd->deal_item_index[trade_i].unshift(); PickupFail flag = pc_additem(sd, &target_sd->status.inventory[n], target_sd->deal_item_amount[trade_i]); if (flag == PickupFail::OKAY) pc_delitem(target_sd, n, target_sd->deal_item_amount[trade_i], 1); else clif_additem(target_sd, n, target_sd->deal_item_amount[trade_i], PickupFail::OKAY); target_sd->deal_item_index[trade_i] = IOff2::from(0); target_sd->deal_item_amount[trade_i] = 0; } } if (sd->deal_zeny) { int deal = sd->deal_zeny; sd->deal_zeny = 0; sd->status.zeny -= deal; clif_updatestatus(sd, SP::ZENY); target_sd->status.zeny += deal; clif_updatestatus(target_sd, SP::ZENY); } if (target_sd->deal_zeny) { int deal = target_sd->deal_zeny; target_sd->deal_zeny = 0; target_sd->status.zeny -= deal; clif_updatestatus(target_sd, SP::ZENY); sd->status.zeny += deal; clif_updatestatus(sd, SP::ZENY); } sd->deal_locked = 0; target_sd->deal_locked = 0; clif_tradecompleted(sd, 0); clif_tradecompleted(target_sd, 0); MAP_LOG_PC(sd, " TRADEOK"_fmt); } } } }
/*========================================== * 取引許諾(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); } } } } }