Ejemplo n.º 1
0
/*
 * Btw don't touch beacuse here is hack that change bs->cmp func on the fly 
 * so if you don't know what are you doing, don't do it :-)
 * Hack is needed cause parser sys is bs (array) of bs (arrays) and we want
 * to optimize cascade searching.
 */
int
parser_add(struct ctx_t *dst, struct parser_t *parser)
{
	int i = -1;
	struct store_t *sys;
	struct store_t *pbs;

	log(dst,2,"parser add [%s]\n", parser->name);

	sys = parser_sys_init(dst);

	if(NULL == sys)
		return -1;
	
	/* cmp between parser_t and store_t of parsers */
	sys->cmp = parserbscmp;

	i = store_search(sys, parser);

	if(i >= 0)
	{
		pbs = store_idx_get(sys, i);

		if(store_insert(pbs, parser)<0)
			log(dst,4,"Unable to insert!\n");

		print_parsers(dst); 
	}
	else
	{
		pbs = store_new(2, sizeof(struct parser_t), priocmp);

		if(NULL == pbs)
			return -1;
			
		if(store_idx_set(pbs, parser, 0) < 0)
			log(dst,4,"Unable to store parser!\n");

		/* Cmp between parser arrays (store_t) */
		sys->cmp = pbscmp;

		if(store_idx_set(sys, pbs, sys->last) < 0)
			log(dst,4,"Unable to insert!\n");

		store_sort(sys);
		i = store_search(sys, pbs); 
	}

	sys->cmp = pbscmp;
	return i;
}
Ejemplo n.º 2
0
/**
 * Process the actions (click) for the Search Store window.
 * @param sd : player requesting
 * @param account_id : account ID of owner's shop
 * @param store_id : store ID created by client
 * @param nameid : item being searched
 */
void searchstore_click(struct map_session_data* sd, uint32 account_id, int store_id, unsigned short nameid)
{
	unsigned int i;
	struct map_session_data* pl_sd;
	searchstore_search_t store_search;

	if( !battle_config.feature_search_stores || !sd->searchstore.open || !sd->searchstore.count )
		return;

	searchstore_clearremote(sd);

	ARR_FIND( 0, sd->searchstore.count, i,  sd->searchstore.items[i].store_id == store_id && sd->searchstore.items[i].account_id == account_id && sd->searchstore.items[i].nameid == nameid );
	if( i == sd->searchstore.count ) { // no such result, crafted
		ShowWarning("searchstore_click: Received request with item %hu of account %d, which is not part of current result set (account_id=%d, char_id=%d).\n", nameid, account_id, sd->bl.id, sd->status.char_id);
		clif_search_store_info_failed(sd, SSI_FAILED_SSILIST_CLICK_TO_OPEN_STORE);
		return;
	}

	if( ( pl_sd = map_id2sd(account_id) ) == NULL ) { // no longer online
		clif_search_store_info_failed(sd, SSI_FAILED_SSILIST_CLICK_TO_OPEN_STORE);
		return;
	}

	if( !searchstore_hasstore(pl_sd, sd->searchstore.type) || searchstore_getstoreid(pl_sd, sd->searchstore.type) != store_id ) { // no longer vending/buying or not same shop
		clif_search_store_info_failed(sd, SSI_FAILED_SSILIST_CLICK_TO_OPEN_STORE);
		return;
	}

	store_search = searchstore_getsearchfunc(sd->searchstore.type);

	if( !store_search(pl_sd, nameid) ) {// item no longer being sold/bought
		clif_search_store_info_failed(sd, SSI_FAILED_SSILIST_CLICK_TO_OPEN_STORE);
		return;
	}

	switch( sd->searchstore.effect ) {
		case EFFECTTYPE_NORMAL:
			// display coords
			if( sd->bl.m != pl_sd->bl.m ) // not on same map, wipe previous marker
				clif_search_store_info_click_ack(sd, -1, -1);
			else
				clif_search_store_info_click_ack(sd, pl_sd->bl.x, pl_sd->bl.y);
			break;
		case EFFECTTYPE_CASH:
			// open remotely
			// to bypass range checks
			sd->searchstore.remote_id = account_id;

			switch( sd->searchstore.type ) {
				case SEARCHTYPE_VENDING:      vending_vendinglistreq(sd, account_id); break;
				case SEARCHTYPE_BUYING_STORE: buyingstore_open(sd, account_id);       break;
			}
			break;
		default:
			// unknown
			ShowError("searchstore_click: Unknown search store effect %u (account_id=%d).\n", (unsigned int)sd->searchstore.effect, sd->bl.id);
	}
}
Ejemplo n.º 3
0
void searchstore_click(struct map_session_data* sd, int account_id, int store_id, unsigned short nameid) {
	unsigned int i;
	struct map_session_data* pl_sd;
	searchstore_search_t store_search;

	if( !battle_config.feature_search_stores || !sd->searchstore.open || !sd->searchstore.count ) {
		return;
	}

	searchstore->clearremote(sd);

	ARR_FIND( 0, sd->searchstore.count, i,  sd->searchstore.items[i].store_id == store_id && sd->searchstore.items[i].account_id == account_id && sd->searchstore.items[i].nameid == nameid );
	if( i == sd->searchstore.count ) {// no such result, crafted
		ShowWarning("searchstore_click: Pedido recebido do item %hu da conta %d, que nao faz parte do conjunto de resultados atual (account_id=%d, char_id=%d).\n", nameid, account_id, sd->bl.id, sd->status.char_id);
		clif->search_store_info_failed(sd, SSI_FAILED_SSILIST_CLICK_TO_OPEN_STORE);
		return;
	}

	if( ( pl_sd = map->id2sd(account_id) ) == NULL ) {// no longer online
		clif->search_store_info_failed(sd, SSI_FAILED_SSILIST_CLICK_TO_OPEN_STORE);
		return;
	}

	if( !searchstore_hasstore(pl_sd, sd->searchstore.type) || searchstore_getstoreid(pl_sd, sd->searchstore.type) != store_id ) {
		// no longer vending/buying or not same shop
		clif->search_store_info_failed(sd, SSI_FAILED_SSILIST_CLICK_TO_OPEN_STORE);
		return;
	}

	store_search = searchstore_getsearchfunc(sd->searchstore.type);

	if( !store_search(pl_sd, nameid) ) {// item no longer being sold/bought
		clif->search_store_info_failed(sd, SSI_FAILED_SSILIST_CLICK_TO_OPEN_STORE);
		return;
	}

	switch( sd->searchstore.effect ) {
		case EFFECTTYPE_NORMAL:
			// display coords

			if( sd->bl.m != pl_sd->bl.m ) {// not on same map, wipe previous marker
				clif->search_store_info_click_ack(sd, -1, -1);
			} else {
				clif->search_store_info_click_ack(sd, pl_sd->bl.x, pl_sd->bl.y);
			}

			break;
		case EFFECTTYPE_CASH:
			// open remotely

			// to bypass range checks
			sd->searchstore.remote_id = account_id;

			switch( sd->searchstore.type ) {
				case SEARCHTYPE_VENDING:      vending->list(sd, account_id); break;
				case SEARCHTYPE_BUYING_STORE: buyingstore->open(sd, account_id);       break;
			}

			break;
		default:
			// unknown
			ShowError("searchstore_click: Efeito de procura de loja desconhecido %u (account_id=%d).\n", (unsigned int)sd->searchstore.effect, sd->bl.id);
	}
}