Esempio n. 1
0
/*==========================================
 * 取引要請
 *------------------------------------------
 */
void trade_tradeack(struct map_session_data *sd, int type) {
	struct map_session_data *target_sd;
	nullpo_retv(sd);

	if ((target_sd = map_id2sd(sd->trade_partner)) != NULL) {
		clif_tradestart(target_sd, type);
		clif_tradestart(sd, type);
		if (type == 4) { // Cancel
			sd->state.deal_locked = 0;
			sd->trade_partner = 0;
			target_sd->state.deal_locked = 0;
			target_sd->trade_partner = 0;
		}

		if (type == 3) { //Initiate trade
			sd->state.trading = 1;
			target_sd->state.trading = 1;
			memset(&sd->deal, 0, sizeof(sd->deal));
			memset(&target_sd->deal, 0, sizeof(target_sd->deal));
		}
		
		if (sd->npc_id != 0)
			npc_event_dequeue(sd);
		if (target_sd->npc_id != 0)
			npc_event_dequeue(target_sd);

		//close STORAGE window if it's open. It protects from spooffing packets [Lupus]
		if (sd->state.storage_flag == 1)
			storage_storageclose(sd);
		else if (sd->state.storage_flag == 2)
			storage_guild_storageclose(sd);
	}
}
Esempio n. 2
0
File: trade.cpp Progetto: mrktj/tmwa
/*==========================================
 * 取引要請
 *------------------------------------------
 */
void trade_tradeack(dumb_ptr<map_session_data> sd, int type)
{
    dumb_ptr<map_session_data> target_sd;
    nullpo_retv(sd);

    if ((target_sd = map_id2sd(account_to_block(sd->trade_partner))) != nullptr)
    {
        clif_tradestart(target_sd, type);
        clif_tradestart(sd, type);
        if (type == 4)
        {                       // Cancel
            sd->deal_locked = 0;
            sd->trade_partner = AccountId();
            target_sd->deal_locked = 0;
            target_sd->trade_partner = AccountId();
        }
        if (sd->npc_id)
            npc_event_dequeue(sd);
        if (target_sd->npc_id)
            npc_event_dequeue(target_sd);

        //close STORAGE window if it's open. It protects from spooffing packets [Lupus]
        if (sd->state.storage_open)
            storage_storageclose(sd);
    }
}
Esempio n. 3
0
File: trade.cpp Progetto: mrktj/tmwa
/*==========================================
 * 取引要請を相手に送る
 *------------------------------------------
 */
void trade_traderequest(dumb_ptr<map_session_data> sd, BlockId target_id)
{
    dumb_ptr<map_session_data> target_sd;

    nullpo_retv(sd);

    if ((target_sd = map_id2sd(target_id)) != nullptr)
    {
        if (!battle_config.invite_request_check)
        {
            if (target_sd->party_invite)
            {
                clif_tradestart(sd, 2);    // 相手はPT要請中かGuild要請中
                return;
            }
        }
        if (target_sd->npc_id)
        {
            //Trade fails if you are using an NPC.
            clif_tradestart(sd, 2);
            return;
        }
        if ((target_sd->trade_partner) || (sd->trade_partner))
        {
            trade_tradecancel(sd); //person is in another trade
        }
        else
        {
            if (sd->bl_m != target_sd->bl_m
                || (sd->bl_x - target_sd->bl_x <= -5
                    || sd->bl_x - target_sd->bl_x >= 5)
                || (sd->bl_y - target_sd->bl_y <= -5
                    || sd->bl_y - target_sd->bl_y >= 5))
            {
                clif_tradestart(sd, 0);    //too far
            }
            else if (sd != target_sd)
            {
                target_sd->trade_partner = sd->status_key.account_id;
                sd->trade_partner = target_sd->status_key.account_id;
                clif_traderequest(target_sd, sd->status_key.name);
            }
        }
    }
    else
    {
        clif_tradestart(sd, 1);    //character does not exist
    }
}
Esempio n. 4
0
/*==========================================
 * Initiates a trade request.
 *------------------------------------------
 */
void trade_traderequest(struct map_session_data *sd, struct map_session_data *target_sd) {
	int level;

	nullpo_retv(sd);

	if (map[sd->bl.m].flag.notrade) {
		clif_displaymessage (sd->fd, msg_txt(272));
		return; //Can't trade in notrade mapflag maps.
	}

	if (target_sd == NULL || sd == target_sd) {
		clif_tradestart(sd, 1); // character does not exist
		return;
	}
	
	if (!battle_config.invite_request_check) {
		if (target_sd->guild_invite > 0 || target_sd->party_invite > 0) {
			clif_tradestart(sd, 2);
			return;
		}
	}

	if ((target_sd->trade_partner != 0) || (sd->trade_partner != 0)) {
		trade_tradecancel(sd); // person is in another trade
		return;
	}

	level = pc_isGM(sd);
	if ( pc_can_give_items(level) || pc_can_give_items(pc_isGM(target_sd)) ) //check if both GMs are allowed to trade
	{
		clif_displaymessage(sd->fd, msg_txt(246));
		trade_tradecancel(sd); // GM is not allowed to trade
		return;
	} 
	
	//Fixed. Only real GMs can request trade from far away! [Lupus] 
	if (level < lowest_gm_level && (sd->bl.m != target_sd->bl.m ||
		!check_distance_bl(&sd->bl, &target_sd->bl, TRADE_DISTANCE)
	)) {
		clif_tradestart(sd, 0); // too far
		return ;
	}
	
	target_sd->trade_partner = sd->status.account_id;
	sd->trade_partner = target_sd->status.account_id;
	clif_traderequest(target_sd, sd->status.name);
}
Esempio n. 5
0
/*==========================================
 * 取引要請
 *------------------------------------------
 */
void trade_tradeack(struct map_session_data *sd, unsigned char type)
{
	struct map_session_data *target_sd;

	nullpo_retv(sd);

	// possible types: 3: trade ok., 4: trade canceled.
	if (type != 3 && type != 4)
		return;

	if(sd->npc_id != 0)
		npc_event_dequeue(sd);

	target_sd = map_id2sd(sd->trade.partner);
	if(target_sd && target_sd->bl.prev) {
		if(sd->bl.m != target_sd->bl.m || unit_distance(&sd->bl, &target_sd->bl) > 2) {
			trade_tradecancel(sd);
			return;
		}
		if(sd->state.storage_flag || target_sd->state.storage_flag) {
			trade_tradecancel(target_sd);
			trade_tradecancel(sd);
			return;
		}
		clif_tradestart(target_sd,type);
		clif_tradestart(sd,type);
		if(type == 4) {	// Cancel
			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;
		} else {
			sd->state.deal_mode        = 1;
			target_sd->state.deal_mode = 1;
		}
	}

	return;
}
Esempio n. 6
0
/*==========================================
 * 取引要請を相手に送る
 *------------------------------------------
 */
void trade_traderequest(struct map_session_data *sd, int target_id) {
	struct map_session_data *target_sd;
	int level;

	nullpo_retv(sd);

	if (map[sd->bl.m].flag.notrade) {
		clif_displaymessage (sd->fd, msg_txt(272));
		return; //Can't trade in notrade mapflag maps.
	}

	if ((target_sd = map_id2sd(target_id)) != NULL) {
		if (!battle_config.invite_request_check) {
			if (target_sd->guild_invite > 0 || target_sd->party_invite > 0) {
				clif_tradestart(sd, 2); // 相手はPT要請中かGuild要請中
				return;
			}
		}
		level = pc_isGM(sd);
		if ( pc_can_give_items(level) || pc_can_give_items(pc_isGM(target_sd)) ) //check if both GMs are allowed to trade
		{
			clif_displaymessage(sd->fd, msg_txt(246));
			trade_tradecancel(sd); // GM is not allowed to trade
		} else if ((target_sd->trade_partner != 0) || (sd->trade_partner != 0)) {
			trade_tradecancel(sd); // person is in another trade
		} else {
			//Fixed. Only real GMs can request trade from far away! [Lupus] 
			if (level < lowest_gm_level && (sd->bl.m != target_sd->bl.m ||
			    (sd->bl.x - target_sd->bl.x <= -5 || sd->bl.x - target_sd->bl.x >= 5) ||
			    (sd->bl.y - target_sd->bl.y <= -5 || sd->bl.y - target_sd->bl.y >= 5))) {
				clif_tradestart(sd, 0); // too far
			} else if (sd != target_sd) {
				target_sd->trade_partner = sd->status.account_id;
				sd->trade_partner = target_sd->status.account_id;
				clif_traderequest(target_sd, sd->status.name);
			}
		}
	} else {
		clif_tradestart(sd, 1); // character does not exist
	}
}
Esempio n. 7
0
/*==========================================
 * Initiates a trade request.
 *------------------------------------------*/
void trade_traderequest(struct map_session_data *sd, struct map_session_data *target_sd)
{
	nullpo_retv(sd);

	if (map[sd->bl.m].flag.notrade) {
		clif_displaymessage (sd->fd, msg_txt(272));
		return; //Can't trade in notrade mapflag maps.
	}

	if (target_sd == NULL || sd == target_sd) {
		clif_tradestart(sd, 1); // character does not exist
		return;
	}

	if (target_sd->npc_id)
	{	//Trade fails if you are using an NPC.
		clif_tradestart(sd, 2);
		return;
	}

	if (!battle_config.invite_request_check) {
		if (target_sd->guild_invite > 0 || target_sd->party_invite > 0 || target_sd->adopt_invite) {
			clif_tradestart(sd, 2);
			return;
		}
	}

	if ( sd->trade_partner != 0 ) { // If a character tries to trade to another one then cancel the previous one
		struct map_session_data *previous_sd = map_id2sd(sd->trade_partner);
		if( previous_sd ){
			previous_sd->trade_partner = 0;
			clif_tradecancelled(previous_sd);
		} // Once cancelled then continue to the new one.
		sd->trade_partner = 0;
		clif_tradecancelled(sd);
	}

	if (target_sd->trade_partner != 0) {
		clif_tradestart(sd, 2); // person is in another trade
		return;
	}

	if (!pc_can_give_items(sd) || !pc_can_give_items(target_sd)) //check if both GMs are allowed to trade
	{
		clif_displaymessage(sd->fd, msg_txt(246));
		clif_tradestart(sd, 2); // GM is not allowed to trade
		return;
	} 
	
	// Players can not request trade from far away, unless they are allowed to use @trade.
	if (!pc_can_use_command(sd, "trade", COMMAND_ATCOMMAND) &&
	    (sd->bl.m != target_sd->bl.m || !check_distance_bl(&sd->bl, &target_sd->bl, TRADE_DISTANCE))) {
		clif_tradestart(sd, 0); // too far
		return ;
	}
	
	target_sd->trade_partner = sd->status.account_id;
	sd->trade_partner = target_sd->status.account_id;
	clif_traderequest(target_sd, sd->status.name);
}
Esempio n. 8
0
/*==========================================
 * 取引要請を相手に送る
 *------------------------------------------
 */
void trade_traderequest(struct map_session_data *sd,int target_id)
{
	// clif_tradestart flag: 0: You are too far away from the person to trade., 1: This Character is not currently online or does not exist, 2: The person is in another trade., 3: (trade ok->open the trade window)., 4: The deal has been rejected.
	struct map_session_data *target_sd;

	nullpo_retv(sd);

	if(sd->npc_id)
		npc_event_dequeue(sd);

	target_sd = map_id2sd(target_id);
	if(target_sd && target_sd->bl.prev && sd != target_sd) { // check same player to avoid hack
		if(target_sd->state.storage_flag) {
			clif_tradestart(sd, 5);
			return;
		}
		if(target_sd->state.store || target_sd->state.mail_appending) {
			clif_tradestart(sd, 4);
			return;
		}
		if(!battle_config.invite_request_check) {
			if(target_sd->guild_invite > 0 || target_sd->party_invite > 0 || target_sd->adopt_invite) {
				clif_tradestart(sd,2);	// 相手はPT要請中かGuild要請中か養子要請中
				return;
			}
		}
		if(target_sd->trade.partner != 0) {
			clif_tradestart(sd, 2);
		} else if(sd->bl.m != target_sd->bl.m || unit_distance(&sd->bl, &target_sd->bl) > 2) {
			clif_tradestart(sd, 0);
		} else if(battle_config.gvg_trade_request_refused && map[sd->bl.m].flag.gvg &&
		          target_sd->status.guild_id > 0 && sd->status.guild_id != target_sd->status.guild_id) {
				// if on a gvg map and not in same guild (that can block other player when WoE)
				clif_tradestart(sd, 4);
		} else if(battle_config.pvp_trade_request_refused && map[sd->bl.m].flag.pvp) {
			// Same on PVP map
			clif_tradestart(sd, 4);
		} else {
			target_sd->trade.partner = sd->status.account_id;
			sd->trade.partner = target_sd->status.account_id;
			clif_traderequest(target_sd,sd->status.name);
		}
	} else {
		clif_tradestart(sd, 1);
	}

	return;
}
Esempio n. 9
0
/*==========================================
 * Reply to a trade-request.
 * Type values:
 * 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);
	sd->state.can_tradeack = 0;

	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);
}
Esempio n. 10
0
/*==========================================
 * Reply to a trade-request.
 * Type values:
 * 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);
		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?

	//Copied here as well since the original character could had warped.
	if (pc_isGM(tsd) < battle_config.lowest_gm_level && (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->vender_id || sd->state.storage_flag ||
		tsd->npc_id || tsd->vender_id || 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);
}
Esempio n. 11
0
/*==========================================
 * Initiates a trade request.
 *------------------------------------------*/
void trade_traderequest(struct map_session_data *sd, struct map_session_data *target_sd)
{
	int level;

	nullpo_retv(sd);

	if (map[sd->bl.m].flag.notrade) {
		clif_displaymessage (sd->fd, msg_txt(272));
		return; //Can't trade in notrade mapflag maps.
	}

	if( sd->state.secure_items ) {
		clif_displaymessage(sd->fd, "You can't trade. Blocked with @security");
		return;
	}

	if (target_sd == NULL || sd == target_sd) {
		clif_tradestart(sd, 1); // character does not exist
		return;
	}

	if( target_sd->state.secure_items ) {
		clif_displaymessage(sd->fd, "Target can't trade. Blocked with @security");
		return;
	}

	if( !battle_config.faction_allow_trade && sd->status.faction_id != target_sd->status.faction_id )
	{
		clif_displaymessage(sd->fd,"You cannot trade with other faction members.");
		return;
	}

	if( target_sd->npc_id || target_sd->buyer_id )
	{	//Trade fails if you are using an NPC.
		clif_tradestart(sd, 2);
		return;
	}

	if (!battle_config.invite_request_check) {
		if (target_sd->guild_invite > 0 || target_sd->party_invite > 0 || target_sd->adopt_invite) {
			clif_tradestart(sd, 2);
			return;
		}
	}

	if (target_sd->trade_partner != 0) {
		clif_tradestart(sd, 2); // person is in another trade
		return;
	}

	level = pc_isGM(sd);
	if ( !pc_can_give_items(level) || !pc_can_give_items(pc_isGM(target_sd)) ) //check if both GMs are allowed to trade
	{
		clif_displaymessage(sd->fd, msg_txt(246));
		clif_tradestart(sd, 2); // GM is not allowed to trade
		return;
	} 
	
	//Fixed. Only real GMs can request trade from far away! [Lupus] 
	if (level < battle_config.lowest_gm_level && (sd->bl.m != target_sd->bl.m ||
		!check_distance_bl(&sd->bl, &target_sd->bl, TRADE_DISTANCE)
	)) {
		clif_tradestart(sd, 0); // too far
		return ;
	}
	
	target_sd->trade_partner = sd->status.account_id;
	sd->trade_partner = target_sd->status.account_id;
	clif_traderequest(target_sd, sd->status.name);
}