/*========================================== * アイテム追加完了(ok押し) *------------------------------------------ */ void trade_tradeok(struct map_session_data *sd) { struct map_session_data *target_sd; int trade_i; nullpo_retv(sd); // check items for(trade_i = 0; trade_i < 10; trade_i++) { if ((((sd->deal.item[trade_i].index) >= 0) && (sd->deal.item[trade_i].amount > sd->status.inventory[sd->deal.item[trade_i].index].amount)) || (sd->deal.item[trade_i].amount < 0)) { trade_tradecancel(sd); return; } } // check exploit (trade more items that you have) if (impossible_trade_check(sd)) { trade_tradecancel(sd); return; } // check zeny if (sd->deal.zeny < 0 || sd->deal.zeny > MAX_ZENY || sd->deal.zeny > sd->status.zeny) { // check amount trade_tradecancel(sd); return; } if ((target_sd = map_id2sd(sd->trade_partner)) != NULL) { sd->state.deal_locked = 1; clif_tradeitemok(sd, 0, 0); clif_tradedeal_lock(sd, 0); clif_tradedeal_lock(target_sd, 1); } }
/*========================================== * Žæˆø‹–‘ø(trade‰Ÿ‚µ) *------------------------------------------*/ 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) { pc_payzeny (sd , sd->deal.zeny, LOG_TYPE_TRADE, tsd); pc_getzeny (tsd, sd->deal.zeny, LOG_TYPE_TRADE, sd); sd->deal.zeny = 0; 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; 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 *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); if (flag == 0) { //Logs (T)rade [Lupus] if(log_config.enable_logs&0x2) { log_pick_pc(sd, "T", sd->status.inventory[n].nameid, -(sd->deal.item[trade_i].amount), &sd->status.inventory[n]); log_pick_pc(tsd, "T", sd->status.inventory[n].nameid, sd->deal.item[trade_i].amount, &sd->status.inventory[n]); } 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 (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); if (flag == 0) { //Logs (T)rade [Lupus] if(log_config.enable_logs&0x2) { log_pick_pc(tsd, "T", tsd->status.inventory[n].nameid, -(tsd->deal.item[trade_i].amount), &tsd->status.inventory[n]); log_pick_pc(sd, "T", tsd->status.inventory[n].nameid, tsd->deal.item[trade_i].amount, &tsd->status.inventory[n]); } pc_delitem(tsd, n, tsd->deal.item[trade_i].amount, 1); } 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_config.zeny ) log_zeny(tsd, "T", sd, sd->deal.zeny); if( tsd->deal.zeny && log_config.zeny ) log_zeny(sd, "T", 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; 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 [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 }