Exemplo n.º 1
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, 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);
	}
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
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);
	}
}
Exemplo n.º 4
0
Arquivo: trade.cpp Projeto: mrktj/tmwa
/*==========================================
 * 取引許諾(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);
            }
        }
    }
}
Exemplo n.º 5
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);
				}
			}
		}
	}
}