• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ db_iterator函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中db_iterator函数的典型用法代码示例。如果您正苦于以下问题:C++ db_iterator函数的具体用法?C++ db_iterator怎么用?C++ db_iterator使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了db_iterator函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: party_send_xy_timer

int party_send_xy_timer(int tid, unsigned int tick, int id, intptr_t data)
{
	struct party_data *p;

	DBIterator *iter = db_iterator(party_db);
	//For each existing party
	for( p = (struct party_data *)dbi_first(iter); dbi_exists(iter); p = (struct party_data *)dbi_next(iter) ) {
		int i;

		if( !p->party.count ) //No online party members so do not iterate
			continue;

		//For each member of this party
		for( i = 0; i < MAX_PARTY; i++ ) {
			struct map_session_data *sd = p->data[i].sd;

			if( !sd )
				continue;

			if( p->data[i].x != sd->bl.x || p->data[i].y != sd->bl.y ) { //Perform position update
				clif_party_xy(sd);
				p->data[i].x = sd->bl.x;
				p->data[i].y = sd->bl.y;
			}
			if( battle_config.party_hp_mode && p->data[i].hp != sd->battle_status.hp ) { //Perform hp update
				clif_party_hp(sd);
				p->data[i].hp = sd->battle_status.hp;
			}
		}
	}
	dbi_destroy(iter);

	return 0;
}
开发者ID:SamuelHercules,项目名称:idathena,代码行数:34,代码来源:party.c


示例2: channel_delete

/**
 * Deletes a chat channel.
 *
 * @param chan The channel to delete
 */
void channel_delete(struct channel_data *chan)
{
	nullpo_retv(chan);

	if (db_size(chan->users) && !channel->config->closing) {
		struct map_session_data *sd;
		struct DBIterator *iter = db_iterator(chan->users);
		for (sd = dbi_first(iter); dbi_exists(iter); sd = dbi_next(iter)) {
			channel->leave_sub(chan, sd);
		}
		dbi_destroy(iter);
	}
	if (chan->banned) {
		db_destroy(chan->banned);
		chan->banned = NULL;
	}
	db_destroy(chan->users);
	if (chan->m) {
		map->list[chan->m].channel = NULL;
		aFree(chan);
	} else if (chan->type == HCS_TYPE_ALLY) {
		aFree(chan);
	} else if (!channel->config->closing) {
		strdb_remove(channel->db, chan->name);
	}
}
开发者ID:xdgimf,项目名称:Renewal,代码行数:31,代码来源:channel.c


示例3: assert

db_iterator Database::dirs_begin() const
{
    Dbc* pCursor = nullptr;
	dbDirs_.cursor(NULL, &pCursor, 0);
	assert(pCursor);
	
    RecordID id;
    Dbt key;
    Dbt data;
    
    key.set_flags(DB_DBT_USERMEM);
    key.set_data(id.data());
    key.set_ulen(id.size());
    
    const int err = pCursor->get(&key, &data, DB_FIRST);
    
    if (err)
    {
        pCursor->close();
        
        if (err != DB_NOTFOUND)
        {
            throw DbException("Failed to obtain first directory record", err);
        }
        
        return dirs_end();
    }
    
    return db_iterator(pCursor, make_Record(std::move(id), RecordData(data)));
}
开发者ID:sgomin,项目名称:ddb_medialib,代码行数:30,代码来源:database.cpp


示例4: channel_close

void channel_close(struct channel_data *cd)
{
	int j;
	char output[128];
	struct map_session_data *pl_sd;
	DBIterator* iter;

	if( cd == NULL || cd->type != CHN_USER )
		return;
	
	sprintf(output, msg_txt(804), cd->name);
	clif_channel_message(cd, output, -1);

	iter = db_iterator(cd->users_db);
	for( pl_sd = (struct map_session_data *)dbi_first(iter); dbi_exists(iter); pl_sd = (struct map_session_data *)dbi_next(iter) )
	{
		idb_remove(cd->users_db, pl_sd->bl.id);
		ARR_FIND(0, MAX_USER_CHANNELS, j, pl_sd->cd[j] == cd);
		if( j == MAX_USER_CHANNELS )
			continue;
		
		pl_sd->cd[j] = NULL;
	}
	dbi_destroy(iter);
	
	db_destroy(cd->users_db);
	strdb_remove(channel_db, cd->name);
}
开发者ID:Chocolate31,项目名称:eamod,代码行数:28,代码来源:channel.c


示例5: party_booking_search

void party_booking_search(struct map_session_data *sd, short level, short mapid, short job, unsigned long lastindex, short resultcount)
{
	struct party_booking_ad_info *pb_ad;
	int i, count = 0;
	struct party_booking_ad_info *result_list[PARTY_BOOKING_RESULTS];
	bool more_result = false;
	DBIterator *iter = db_iterator(party_booking_db);

	memset(result_list, 0, sizeof(result_list));

	for (pb_ad = dbi_first(iter); dbi_exists(iter); pb_ad = dbi_next(iter)) {
		if (pb_ad->index < lastindex || (level && (pb_ad->p_detail.level < level - 15 || pb_ad->p_detail.level > level)))
			continue;
		if (count >= PARTY_BOOKING_RESULTS) {
			more_result = true;
			break;
		}
		if (mapid == 0 && job == -1)
			result_list[count] = pb_ad;
		else if (mapid == 0) {
			for(i = 0; i < PARTY_BOOKING_JOBS; i++)
				if (pb_ad->p_detail.job[i] == job && job != -1)
					result_list[count] = pb_ad;
		} else if (job == -1) {
			if (pb_ad->p_detail.mapid == mapid)
				result_list[count] = pb_ad;
		}
		if (result_list[count])
			count++;
	}
	dbi_destroy(iter);
	clif_PartyBookingSearchAck(sd->fd, result_list, count, more_result);
}
开发者ID:SamuelHercules,项目名称:idathena,代码行数:33,代码来源:party.c


示例6: db_iterator

cConfMySQL::db_iterator &cConfMySQL::db_begin(cQuery &Query)
{
	if ((-1 == this->StartQuery(Query)) || (Load(Query) < 0))
		mDBBegin = NULL;
	else
		mDBBegin = db_iterator(this, &Query);

	return mDBBegin;
}
开发者ID:Verlihub,项目名称:verlihub,代码行数:9,代码来源:cconfmysql.cpp


示例7: script_save_mapreg

/// Saves permanent variables to database
static void script_save_mapreg(void)
{
	DBIterator* iter;
	DBData *data;
	DBKey key;

	iter = db_iterator(mapreg_db);
	for( data = iter->first(iter,&key); iter->exists(iter); data = iter->next(iter,&key) )
	{
		int num = (key.i & 0x00ffffff);
		int i   = (key.i & 0xff000000) >> 24;
		const char* name = get_str(num);

		if( name[1] == '@' )
			continue;

		if( SQL_ERROR == Sql_Query(mmysql_handle, "UPDATE `%s` SET `value`='%d' WHERE `varname`='%s' AND `index`='%d'", mapreg_table, db_data2i(data), name, i) )
			Sql_ShowDebug(mmysql_handle);
	}
	dbi_destroy(iter);

	iter = db_iterator(mapregstr_db);
	for( data = iter->first(iter,&key); iter->exists(iter); data = iter->next(iter,&key) )
	{
		int num = (key.i & 0x00ffffff);
		int i   = (key.i & 0xff000000) >> 24;
		const char* name = get_str(num);
		char tmp_str2[2*255+1];

		if( name[1] == '@' )
			continue;

		Sql_EscapeStringLen(mmysql_handle, tmp_str2, db_data2ptr(data), safestrnlen(db_data2ptr(data), 255));
		if( SQL_ERROR == Sql_Query(mmysql_handle, "UPDATE `%s` SET `value`='%s' WHERE `varname`='%s' AND `index`='%d'", mapreg_table, tmp_str2, name, i) )
			Sql_ShowDebug(mmysql_handle);
	}
	dbi_destroy(iter);

	mapreg_dirty = false;
}
开发者ID:Chocolate31,项目名称:eamod,代码行数:41,代码来源:mapreg.c


示例8: clan_searchname

struct clan* clan_searchname( const char* name ){
	struct clan* c;

	DBIterator *iter = db_iterator(clan_db);
	for( c = (struct clan*)dbi_first(iter); dbi_exists(iter); c = (struct clan*)dbi_next(iter) ){
		if( strncmpi( c->name, name, NAME_LENGTH ) == 0 ){
			break;
		}
	}
	dbi_destroy(iter);

	return c;
}
开发者ID:AtlantisRO,项目名称:rathena,代码行数:13,代码来源:clan.c


示例9: party_searchname

/// Party data lookup using party name.
struct party_data* party_searchname(const char* str)
{
	struct party_data* p;

	DBIterator *iter = db_iterator(party_db);
	for( p = (struct party_data*)dbi_first(iter); dbi_exists(iter); p = (struct party_data*)dbi_next(iter) ) {
		if( strncmpi(p->party.name,str,NAME_LENGTH) == 0 )
			break;
	}
	dbi_destroy(iter);

	return p;
}
开发者ID:julius5,项目名称:rathena,代码行数:14,代码来源:party.c


示例10: mapif_parse_PartyShareLevel

//Used to update party share level range in run time
int mapif_parse_PartyShareLevel(int fd,unsigned int share_lvl)
{
	struct party_data *p;
	DBIterator* iter = db_iterator(party_db_);

	party_share_level = share_lvl;

	for(p = dbi_first(iter); dbi_exists(iter); p = dbi_next(iter)) { //Update online parties
		if(p->party.count > 1)
			int_party_calc_state(p);
	}
	dbi_destroy(iter);

	return 1;
}
开发者ID:BlazingSpear,项目名称:rathena,代码行数:16,代码来源:int_party.c


示例11: auction_count

static int auction_count(int char_id, bool buy)
{
	int i = 0;
	struct auction_data *auction;
	DBIterator *iter = db_iterator(auction_db_);

	for( auction = dbi_first(iter); dbi_exists(iter); auction = dbi_next(iter) )
	{
		if( (buy && auction->buyer_id == char_id) || (!buy && auction->seller_id == char_id) )
			i++;
	}
	dbi_destroy(iter);

	return i;
}
开发者ID:Boooo,项目名称:i-aint-quitting,代码行数:15,代码来源:int_auction.c


示例12: account_db_txt_iterator

/// Returns a new forward iterator.
static AccountDBIterator* account_db_txt_iterator(AccountDB* self)
{
	AccountDB_TXT* db = (AccountDB_TXT*)self;
	DBMap* accounts = db->accounts;
	AccountDBIterator_TXT* iter = (AccountDBIterator_TXT*)aCalloc(1, sizeof(AccountDBIterator_TXT));

	// set up the vtable
	iter->vtable.destroy = &account_db_txt_iter_destroy;
	iter->vtable.next    = &account_db_txt_iter_next;

	// fill data
	iter->iter = db_iterator(accounts);

	return &iter->vtable;
}
开发者ID:KimKyung-wook,项目名称:ilathena-project,代码行数:16,代码来源:account_txt.c


示例13: raconf_destroy

void raconf_destroy(raconf rc){
	DBIterator *iter;
	struct conf_value *v;
	
	// Clear all entrys in db.
	iter = db_iterator(rc->db);
	for( v = (struct conf_value*)dbi_first(iter);  dbi_exists(iter);  v = (struct conf_value*)dbi_next(iter) ){
		aFree(v);
	}
	dbi_destroy(iter);

	db_destroy(rc->db);
	
	aFree(rc);	
	
}//end: raconf_destroy()
开发者ID:Abunay01,项目名称:Cronus,代码行数:16,代码来源:raconf.c


示例14: mapif_parse_PartyShareLevel

int mapif_parse_PartyShareLevel(int fd,unsigned int share_lvl)
{
	struct party_data *p;
	DBIterator* iter = db_iterator(party_db_);

	party_share_level = share_lvl;

	for(p = dbi_first(iter); dbi_exists(iter); p = dbi_next(iter)) { //Update online parties
		if(p->party.count > 1)
			int_party_calc_state(p);
		else if(!p->party.count) //Remove parties from memory that have no players online
			idb_remove(party_db_, p->party.party_id);
	}
	dbi_destroy(iter);

	return 1;
}
开发者ID:SNDBXIE,项目名称:myway-eathena,代码行数:17,代码来源:int_party.c


示例15: mapif_parse_Auction_requestlist

static void mapif_parse_Auction_requestlist(int fd)
{
	char searchtext[NAME_LENGTH];
	int char_id = RFIFOL(fd,4), len = sizeof(struct auction_data);
	int price = RFIFOL(fd,10);
	short type = RFIFOW(fd,8), page = max(1,RFIFOW(fd,14));
	unsigned char buf[5 * sizeof(struct auction_data)];
	DBIterator *iter = db_iterator(auction_db_);
	struct auction_data *auction;
	short i = 0, j = 0, pages = 1;

	memcpy(searchtext, RFIFOP(fd,16), NAME_LENGTH);

	for( auction = dbi_first(iter); dbi_exists(iter); auction = dbi_next(iter) )
	{
		if( (type == 0 && auction->type != IT_ARMOR && auction->type != IT_PETARMOR) || 
			(type == 1 && auction->type != IT_WEAPON) ||
			(type == 2 && auction->type != IT_CARD) ||
			(type == 3 && auction->type != IT_ETC) ||
			(type == 4 && !strstr(auction->item_name, searchtext)) ||
			(type == 5 && auction->price > price) ||
			(type == 6 && auction->seller_id != char_id) ||
			(type == 7 && auction->buyer_id != char_id) )
			continue;

		i++;
		if( i > 5 )
		{ // Counting Pages of Total Results (5 Results per Page)
			pages++;
			i = 1; // First Result of This Page
		}

		if( page != pages )
			continue; // This is not the requested Page

		memcpy(WBUFP(buf, j * len), auction, len);
		j++; // Found Results
	}
	dbi_destroy(iter);

	mapif_Auction_sendlist(fd, char_id, j, pages, buf);
}
开发者ID:Boooo,项目名称:i-aint-quitting,代码行数:42,代码来源:int_auction.c


示例16: channel_delete

/**
 * Delete a channel
 * - Checks if there is any user in channel and make them quit
 * @param channel: Channel data
 * @param force: Forcefully remove channel
 * @return
 *   0: Success
 *  -1: Invalid channel
 *  -2: Can't delete now
 */
int channel_delete(struct Channel *channel, bool force) {
	if(!channel)
		return -1;
	if(!force && channel->type == CHAN_TYPE_PUBLIC && runflag == MAPSERVER_ST_RUNNING) //only delete those serv stop
		return -2;
	if( db_size(channel->users)) {
		struct map_session_data *sd;
		DBIterator *iter = db_iterator(channel->users);
		for( sd = (struct map_session_data *)dbi_first(iter); dbi_exists(iter); sd = (struct map_session_data *)dbi_next(iter) ) { //for all users
			channel_clean(channel,sd,1); //make all quit
		}
		dbi_destroy(iter);
	}
	if (battle_config.etc_log)
		ShowInfo("Deleting channel %s alias %s type %d\n",channel->name,channel->alias,channel->type);
	db_destroy(channel->users);
	db_destroy(channel->banned);
	if (channel->groups)
		aFree(channel->groups);
	channel->groups = NULL;
	channel->group_count = 0;
	switch(channel->type){
	case CHAN_TYPE_MAP:
		map_getmapdata(channel->m)->channel = NULL;
		aFree(channel);
		break;
	case CHAN_TYPE_ALLY: {
		struct guild *g = guild_search(channel->gid);
		if(g) g->channel = NULL;
		aFree(channel);
		break;
	}
	default:
		strdb_remove(channel_db, channel->name);
		break;
	}
	return 0;
}
开发者ID:Atemo,项目名称:rathena,代码行数:48,代码来源:channel.cpp


示例17: do_init_buyingstore_autotrade

/**
* Initializing autotraders from table
*/
void do_init_buyingstore_autotrade( void ) {
	if(battle_config.feature_autotrade) {
		if (Sql_Query(mmysql_handle,
			"SELECT `id`, `account_id`, `char_id`, `sex`, `title`, `limit`, `body_direction`, `head_direction`, `sit` "
			"FROM `%s` "
			"WHERE `autotrade` = 1 AND `limit` > 0 AND (SELECT COUNT(`buyingstore_id`) FROM `%s` WHERE `buyingstore_id` = `id`) > 0 "
			"ORDER BY `id`;",
			buyingstores_table, buyingstore_items_table ) != SQL_SUCCESS )
		{
			Sql_ShowDebug(mmysql_handle);
			return;
		}

		if( Sql_NumRows(mmysql_handle) > 0 ) {
			uint16 items = 0;
			DBIterator *iter = NULL;
			struct s_autotrader *at = NULL;

			// Init each autotrader data
			while (SQL_SUCCESS == Sql_NextRow(mmysql_handle)) {
				size_t len;
				char* data;

				at = NULL;
				CREATE(at, struct s_autotrader, 1);
				Sql_GetData(mmysql_handle, 0, &data, NULL); at->id = atoi(data);
				Sql_GetData(mmysql_handle, 1, &data, NULL); at->account_id = atoi(data);
				Sql_GetData(mmysql_handle, 2, &data, NULL); at->char_id = atoi(data);
				Sql_GetData(mmysql_handle, 3, &data, NULL); at->sex = (data[0] == 'F') ? 0 : 1;
				Sql_GetData(mmysql_handle, 4, &data, &len); safestrncpy(at->title, data, zmin(len + 1, MESSAGE_SIZE));
				Sql_GetData(mmysql_handle, 5, &data, NULL); at->limit = atoi(data);
				Sql_GetData(mmysql_handle, 6, &data, NULL); at->dir = atoi(data);
				Sql_GetData(mmysql_handle, 7, &data, NULL); at->head_dir = atoi(data);
				Sql_GetData(mmysql_handle, 8, &data, NULL); at->sit = atoi(data);
				at->count = 0;

				if (battle_config.feature_autotrade_direction >= 0)
					at->dir = battle_config.feature_autotrade_direction;
				if (battle_config.feature_autotrade_head_direction >= 0)
					at->head_dir = battle_config.feature_autotrade_head_direction;
				if (battle_config.feature_autotrade_sit >= 0)
					at->sit = battle_config.feature_autotrade_sit;

				// initialize player
				CREATE(at->sd, struct map_session_data, 1);
				pc_setnewpc(at->sd, at->account_id, at->char_id, 0, gettick(), at->sex, 0);
				at->sd->state.autotrade = 1|4;
				at->sd->state.monster_ignore = (battle_config.autotrade_monsterignore);
				chrif_authreq(at->sd, true);
				uidb_put(buyingstore_autotrader_db, at->char_id, at);
			}
			Sql_FreeResult(mmysql_handle);
			
			// Init items for each autotraders
			iter = db_iterator(buyingstore_autotrader_db);
			for (at = (struct s_autotrader *)dbi_first(iter); dbi_exists(iter); at = (struct s_autotrader *)dbi_next(iter)) {
				uint16 j = 0;

				if (SQL_ERROR == Sql_Query(mmysql_handle,
					"SELECT `item_id`, `amount`, `price` "
					"FROM `%s` "
					"WHERE `buyingstore_id` = %d "
					"ORDER BY `index` ASC;",
					buyingstore_items_table, at->id ) )
				{
					Sql_ShowDebug(mmysql_handle);
					continue;
				}

				if (!(at->count = (uint16)Sql_NumRows(mmysql_handle))) {
					map_quit(at->sd);
					buyingstore_autotrader_remove(at, true);
					continue;
				}
			
				//Init the list
				CREATE(at->entries, struct s_autotrade_entry *,at->count);

				//Add the item into list
				j = 0;
				while (SQL_SUCCESS == Sql_NextRow(mmysql_handle) && j < at->count) {
					char *data;
					CREATE(at->entries[j], struct s_autotrade_entry, 1);
					Sql_GetData(mmysql_handle, 0, &data, NULL); at->entries[j]->item_id = atoi(data);
					Sql_GetData(mmysql_handle, 1, &data, NULL); at->entries[j]->amount = atoi(data);
					Sql_GetData(mmysql_handle, 2, &data, NULL); at->entries[j]->price = atoi(data);
					j++;
				}
				items += j;
				Sql_FreeResult(mmysql_handle);
			}
			dbi_destroy(iter);

			ShowStatus("Done loading '"CL_WHITE"%d"CL_RESET"' buyingstore autotraders with '"CL_WHITE"%d"CL_RESET"' items.\n", db_size(buyingstore_autotrader_db), items);
		}
	}
开发者ID:Tenefer,项目名称:DLRO_Trunk,代码行数:99,代码来源:buyingstore.c


示例18: itemdb_readdb


//.........这里部分代码省略.........
				continue;// empty line
			for( i = 0; i < 19; ++i )
			{
				str[i] = p;
				p = strchr(p,',');
				if( p == NULL )
					break;// comma not found
				*p = '\0';
				++p;
			}

			if( p == NULL )
			{
				ShowError("itemdb_readdb: Insufficient columns in line %d of \"%s\" (item with id %d), skipping.\n", lines, path, atoi(str[0]));
				continue;
			}

			// Script
			if( *p != '{' )
			{
				ShowError("itemdb_readdb: Invalid format (Script column) in line %d of \"%s\" (item with id %d), skipping.\n", lines, path, atoi(str[0]));
				continue;
			}
			str[19] = p;
			p = strstr(p+1,"},");
			if( p == NULL )
			{
				ShowError("itemdb_readdb: Invalid format (Script column) in line %d of \"%s\" (item with id %d), skipping.\n", lines, path, atoi(str[0]));
				continue;
			}
			p[1] = '\0';
			p += 2;

			// OnEquip_Script
			if( *p != '{' )
			{
				ShowError("itemdb_readdb: Invalid format (OnEquip_Script column) in line %d of \"%s\" (item with id %d), skipping.\n", lines, path, atoi(str[0]));
				continue;
			}
			str[20] = p;
			p = strstr(p+1,"},");
			if( p == NULL )
			{
				ShowError("itemdb_readdb: Invalid format (OnEquip_Script column) in line %d of \"%s\" (item with id %d), skipping.\n", lines, path, atoi(str[0]));
				continue;
			}
			p[1] = '\0';
			p += 2;

			// OnUnequip_Script (last column)
			if( *p != '{' )
			{
				ShowError("itemdb_readdb: Invalid format (OnUnequip_Script column) in line %d of \"%s\" (item with id %d), skipping.\n", lines, path, atoi(str[0]));
				continue;
			}
			str[21] = p;

			p = strstr(p+1,"}");
			if ( strchr(p,',') != NULL )
			{
				ShowError("itemdb_readdb: Extra columns in line %d of \"%s\" (item with id %d), skipping.\n", lines, path, atoi(str[0]));
				continue;
			}

			if ((ic = idb_get(item_combo_db, atoi(str[0])))) {
				script2 = ic->script;
			}
			
			if (!itemdb_parse_dbrow(str, path, lines, 0, script2))
				continue;

			if( script2 != NULL )
				idb_remove(item_combo_db,atoi(str[0]));
			
			count++;
		}

		fclose(fp);

		ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, filename[fi]);
	}

	if( db_size(item_combo_db) ) {
		DBIterator * iter = db_iterator(item_combo_db);
		struct item_combo * ic = NULL;
		int icount = 1;
		/* non-processed entries */
		ShowWarning("item_combo_db: There are %d unused entries in the file (combo(s) with non-available item IDs)\n",db_size(item_combo_db));
		
		for( ic = dbi_first(iter); dbi_exists(iter); ic = dbi_next(iter) ) {
			ShowWarning("item_combo_db(%d): (ID:%d) \"%s\" combo unused\n",icount++,ic->nameid,ic->script);
		}

		dbi_destroy(iter);
	}
	
	db_destroy(item_combo_db);

	return 0;
}
开发者ID:SorayaAguiar,项目名称:Traducoes,代码行数:101,代码来源:itemdb.c


示例19: db_iterator

db_iterator Database::dirs_end() const
{
    return db_iterator(nullptr, make_Record(NULL_RECORD_ID, RecordData()));
}
开发者ID:sgomin,项目名称:ddb_medialib,代码行数:4,代码来源:database.cpp


示例20: searchstore_query

void searchstore_query(struct map_session_data* sd, unsigned char type, unsigned int min_price, unsigned int max_price, const unsigned short* itemlist, unsigned int item_count, const unsigned short* cardlist, unsigned int card_count)
{
	unsigned int i;
	struct map_session_data* pl_sd;
	struct DBIterator *iter;
	struct s_search_store_search s;
	searchstore_searchall_t store_searchall;
	time_t querytime;
	DBMap *vending_db = vending_getdb();

	if( !battle_config.feature_search_stores ) {
		return;
	}

	if( !sd->searchstore.open ) {
		return;
	}

	if( ( store_searchall = searchstore_getsearchallfunc(type) ) == NULL ) {
		ShowError("searchstore_query: Unknown search type %u (account_id=%d).\n", (unsigned int)type, sd->bl.id);
		return;
	}

	time(&querytime);

	if( sd->searchstore.nextquerytime > querytime ) {
		clif_search_store_info_failed(sd, SSI_FAILED_LIMIT_SEARCH_TIME);
		return;
	}

	if( !sd->searchstore.uses ) {
		clif_search_store_info_failed(sd, SSI_FAILED_SEARCH_CNT);
		return;
	}

	// validate lists
	for( i = 0; i < item_count; i++ ) {
		if( !itemdb_exists(itemlist[i]) ) {
			ShowWarning("searchstore_query: Client resolved item %hu is not known.\n", itemlist[i]);
			clif_search_store_info_failed(sd, SSI_FAILED_NOTHING_SEARCH_ITEM);
			return;
		}
	}
	for( i = 0; i < card_count; i++ ) {
		if( !itemdb_exists(cardlist[i]) ) {
			ShowWarning("searchstore_query: Client resolved card %hu is not known.\n", cardlist[i]);
			clif_search_store_info_failed(sd, SSI_FAILED_NOTHING_SEARCH_ITEM);
			return;
		}
	}

	if( max_price < min_price ) {
		swap(min_price, max_price);
	}

	sd->searchstore.uses--;
	sd->searchstore.type = type;
	sd->searchstore.nextquerytime = querytime+battle_config.searchstore_querydelay;

	// drop previous results
	searchstore_clear(sd);

	// allocate max. amount of results
	sd->searchstore.items = (struct s_search_store_info_item*)aMalloc(sizeof(struct s_search_store_info_item)*battle_config.searchstore_maxresults);

	// search
	s.search_sd  = sd;
	s.itemlist   = itemlist;
	s.cardlist   = cardlist;
	s.item_count = item_count;
	s.card_count = card_count;
	s.min_price  = min_price;
	s.max_price  = max_price;
	iter         = db_iterator(vending_db);

	for( pl_sd = dbi_first(iter); dbi_exists(iter);  pl_sd = dbi_next(iter) ) {
		if( sd == pl_sd ) {// skip own shop, if any
			continue;
		}

		if( !store_searchall(pl_sd, &s) ) {// exceeded result size
			clif_search_store_info_failed(sd, SSI_FAILED_OVER_MAXCOUNT);
			break;
		}
	}

	dbi_destroy(iter);

	if( sd->searchstore.count ) {
		// reclaim unused memory
		sd->searchstore.items = (struct s_search_store_info_item*)aRealloc(sd->searchstore.items, sizeof(struct s_search_store_info_item)*sd->searchstore.count);

		// present results
		clif_search_store_info_ack(sd);

		// one page displayed
		sd->searchstore.pages++;
	} else {
		// cleanup
		searchstore_clear(sd);
//.........这里部分代码省略.........
开发者ID:BlazingSpear,项目名称:rathena,代码行数:101,代码来源:searchstore.c



注:本文中的db_iterator函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ db_lock函数代码示例发布时间:2022-05-30
下一篇:
C++ db_init_string函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap