From dc5babf8c3fb943a22c440f5afd6957b121926c5 Mon Sep 17 00:00:00 2001 From: gepard1984 Date: Tue, 13 Mar 2012 14:46:28 +0000 Subject: Enhanced `DBMap` implementation to allow storing integer type data in addition to void pointers. - Added enum for data: `int`, `unsigned int` and `void*` - Replaced generic `void*` data with `DBData` struct to hold `int`, `unsigned int` or `void*` (member of `DBNode`) - Added `db_i2data`, `db_ui2data` and `db_ptr2data` functions to cast from `int`/`uint`/`void*` to `DBData` (used in `DBMap::put()`) - Added `db_data2i`, `db_data2ui` and `db_data2ptr` functions to get `int`/`uint`/`void*` from `DBData` - Enabled statistics for new functions in `db_stats` struct - `DBCreateData` functions (used in `DBMap::ensure()`) now return `DBData` instead of `void*` - `DBApply` functions (used in `DBMap::foreach()` and `DBMap::destroy()`) now take `DBData*` as a parameter instead of `void*` - `DBMatcher` functions (used in `DBMap::getall()`) now take `DBData` as a parameter instead of `void*` - `DBReleaser` functions now take `DBData` as parameter instead of `void*` - Default releasers release data if it is `void*` (`DB_DATA_PTR`) type - `DBIterator` functions: `first()`, `last()`, `next()` and `prev()` now return `DBData*` instead of `void*` - `DBIterator::remove()` now returns `int` (1 if node was found and removed, 0 otherwise) instead of `void*` and takes an extra `DBData*` parameter for the data of removed entry - `DBMap::get()` and `DBMap::ensure()` now return `DBData*` instead of `void*` - `DBMap::remove()` and `DBMap::put()` now return `int` (1 if node already existed, 0 otherwise) instead of `void*` and take an extra `DBData*` parameter for the data of removed entry - `DBMap::put()` now takes `DBData` as parameter instead of `void*` - `DBMap::getall()` now puts data into `DBData**` buffer instead of `void**` buffer - Updated macros: - (`i`/`ui`/`str`)`db_get` and (`i`/`ui`/`str`)`db_ensure` were wrapped with `db_data2ptr` to extract data from `DBData*` that is now returned by `DBMap::get()` - added (`i`/`ui`/`str`)`db_iget` and (`i`/`ui`/`str`)`db_uiget` that get `DBData` from `DBMap` and extract `int`/`unsigned int` from it (with `db_data2i`/`db_data2ui`) - `db_put`, `idb_put`, `uidb_put` and `strdb_put` data params were wrapped with `db_ptr2data` to match new signature of `DBMap::put()` (`DBData` instead of `void*`) - added (`i`/`ui`/`str`)`db_iput` and (`i`/`ui`/`str`)`db_uiput` that put `int`/`unsigned int` into `DBMap` (first wrapping it with `DBData`) - added `NULL` in place of extra parameter for removed data in `db_remove` macros - `dbi_first`, `dbi_last`, `dbi_next` and `dbi_prev` were wrapped with `db_data2ptr` to extract data from `DBData*` that is now returned by these `DBIterator` functions - Updated `DBMap` documentation, and fixed a dozen of typos in it. - Updated rest of rA code to reflect `DBMap` changes (mostly required signature changes of `DBCreateData` and `DBApply` functions). - Fixed a bug where `DBMap::put()` would return data of a deleted entry. - Removed some unnecessary pointer casts. - Increased `showmsg.c` static buffer size to fit entire DBMap stats report. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@15682 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/map/battleground.c | 7 +++-- src/map/chrif.c | 25 ++++++++++----- src/map/guild.c | 84 +++++++++++++++++++++++++++++++++----------------- src/map/itemdb.c | 41 ++++++++++++++---------- src/map/map.c | 56 +++++++++++++++++++++------------ src/map/mapreg_sql.c | 6 ++-- src/map/npc.c | 45 ++++++++++++++++----------- src/map/script.c | 10 ++++-- src/map/skill.c | 10 +++--- src/map/storage.c | 23 ++++++++------ 10 files changed, 195 insertions(+), 112 deletions(-) (limited to 'src/map') diff --git a/src/map/battleground.c b/src/map/battleground.c index b456a868a..7b605066d 100644 --- a/src/map/battleground.c +++ b/src/map/battleground.c @@ -216,9 +216,12 @@ int bg_send_message(struct map_session_data *sd, const char *mes, int len) return 0; } -int bg_send_xy_timer_sub(DBKey key, void *data, va_list ap) +/** + * @see DBApply + */ +int bg_send_xy_timer_sub(DBKey key, DBData *data, va_list ap) { - struct battleground_data *bg = (struct battleground_data *)data; + struct battleground_data *bg = db_data2ptr(data); struct map_session_data *sd; int i; nullpo_ret(bg); diff --git a/src/map/chrif.c b/src/map/chrif.c index 26c7b10cc..c4ff4b662 100644 --- a/src/map/chrif.c +++ b/src/map/chrif.c @@ -463,9 +463,13 @@ int chrif_connectack(int fd) return 0; } -static int chrif_reconnect(DBKey key,void *data,va_list ap) + +/** + * @see DBApply + */ +static int chrif_reconnect(DBKey key, DBData *data, va_list ap) { - struct auth_node *node=(struct auth_node*)data; + struct auth_node *node = db_data2ptr(data); switch (node->state) { case ST_LOGIN: if (node->sd && node->char_dat == NULL) @@ -669,10 +673,13 @@ void chrif_authfail(int fd) } -//This can still happen (client times out while waiting for char to confirm auth data) -int auth_db_cleanup_sub(DBKey key,void *data,va_list ap) +/** + * This can still happen (client times out while waiting for char to confirm auth data) + * @see DBApply + */ +int auth_db_cleanup_sub(DBKey key, DBData *data, va_list ap) { - struct auth_node *node=(struct auth_node*)data; + struct auth_node *node = db_data2ptr(data); const char* states[] = { "Login", "Logout", "Map change" }; if(DIFF_TICK(gettick(),node->node_created)>60000) { switch (node->state) @@ -1558,10 +1565,12 @@ int chrif_removefriend(int char_id, int friend_id) { return 0; } - -int auth_db_final(DBKey k,void *d,va_list ap) +/** + * @see DBApply + */ +int auth_db_final(DBKey key, DBData *data, va_list ap) { - struct auth_node *node=(struct auth_node*)d; + struct auth_node *node = db_data2ptr(data); if (node->char_dat) aFree(node->char_dat); if (node->sd) diff --git a/src/map/guild.c b/src/map/guild.c index deb603473..528560ee8 100644 --- a/src/map/guild.c +++ b/src/map/guild.c @@ -282,14 +282,17 @@ void guild_makemember(struct guild_member *m,struct map_session_data *sd) return; } -// ギルドのEXPキャッシュをinter鯖にフラッシュする -int guild_payexp_timer_sub(DBKey dataid, void *data, va_list ap) +/** + * ギルドのEXPキャッシュをinter鯖にフラッシュする + * @see DBApply + */ +int guild_payexp_timer_sub(DBKey key, DBData *data, va_list ap) { int i; struct guild_expcache *c; struct guild *g; - c = (struct guild_expcache *)data; + c = db_data2ptr(data); if ( (g = guild_search(c->guild_id)) == NULL || @@ -318,10 +321,13 @@ int guild_payexp_timer(int tid, unsigned int tick, int id, intptr_t data) return 0; } -//Taken from party_send_xy_timer_sub. [Skotlex] -int guild_send_xy_timer_sub(DBKey key,void *data,va_list ap) +/** + * Taken from party_send_xy_timer_sub. [Skotlex] + * @see DBApply + */ +int guild_send_xy_timer_sub(DBKey key, DBData *data, va_list ap) { - struct guild *g=(struct guild *)data; + struct guild *g = db_data2ptr(data); int i; nullpo_ret(g); @@ -425,11 +431,13 @@ int guild_npc_request_info(int guild_id,const char *event) if( event && *event ) { - struct eventlist* ev; + struct eventlist *ev; + DBData prev; ev=(struct eventlist *)aCalloc(sizeof(struct eventlist),1); memcpy(ev->name,event,strlen(event)); - //The one in the db becomes the next event from this. - ev->next = (struct eventlist*)idb_put(guild_infoevent_db,guild_id,ev); + //The one in the db (if present) becomes the next event from this. + if (guild_infoevent_db->put(guild_infoevent_db, db_i2key(guild_id), db_ptr2data(ev), &prev)) + ev->next = db_data2ptr(&prev); } return guild_request_info(guild_id); @@ -484,7 +492,7 @@ int guild_recv_info(struct guild *sg) { struct guild *g,before; int i,bm,m; - struct eventlist *ev,*ev2; + DBData data; struct map_session_data *sd; bool guild_new = false; @@ -558,8 +566,9 @@ int guild_recv_info(struct guild *sg) } // イベントの発生 - if( (ev = (struct eventlist*)idb_remove(guild_infoevent_db,sg->guild_id))!=NULL ) + if (guild_infoevent_db->remove(guild_infoevent_db, db_i2key(sg->guild_id), &data)) { + struct eventlist *ev = db_data2ptr(&data), *ev2; while(ev){ npc_event_do(ev->name); ev2=ev->next; @@ -1122,7 +1131,10 @@ int guild_emblem_changed(int len,int guild_id,int emblem_id,const char *data) return 0; } -static void* create_expcache(DBKey key, va_list args) +/** + * @see DBCreateData + */ +static DBData create_expcache(DBKey key, va_list args) { struct guild_expcache *c; struct map_session_data *sd = va_arg(args, struct map_session_data*); @@ -1132,7 +1144,7 @@ static void* create_expcache(DBKey key, va_list args) c->account_id = sd->status.account_id; c->char_id = sd->status.char_id; c->exp = 0; - return c; + return db_ptr2data(c); } // ギルドのEXP上納 @@ -1157,7 +1169,7 @@ unsigned int guild_payexp(struct map_session_data *sd,unsigned int exp) exp = exp * per / 100; //Otherwise tax everything. - c = (struct guild_expcache*)guild_expcache_db->ensure(guild_expcache_db, db_i2key(sd->status.char_id), create_expcache, sd); + c = db_data2ptr(guild_expcache_db->ensure(guild_expcache_db, db_i2key(sd->status.char_id), create_expcache, sd)); if (c->exp > UINT64_MAX - exp) c->exp = UINT64_MAX; @@ -1176,7 +1188,7 @@ int guild_getexp(struct map_session_data *sd,int exp) if (sd->status.guild_id == 0 || guild_search(sd->status.guild_id) == NULL) return 0; - c = (struct guild_expcache*)guild_expcache_db->ensure(guild_expcache_db, db_i2key(sd->status.char_id), create_expcache, sd); + c = db_data2ptr(guild_expcache_db->ensure(guild_expcache_db, db_i2key(sd->status.char_id), create_expcache, sd)); if (c->exp > UINT64_MAX - exp) c->exp = UINT64_MAX; else @@ -1507,10 +1519,14 @@ int guild_allianceack(int guild_id1,int guild_id2,int account_id1,int account_id } return 0; } -// ギルド解散通知用 -int guild_broken_sub(DBKey key,void *data,va_list ap) + +/** + * ギルド解散通知用 + * @see DBApply + */ +int guild_broken_sub(DBKey key, DBData *data, va_list ap) { - struct guild *g=(struct guild *)data; + struct guild *g = db_data2ptr(data); int guild_id=va_arg(ap,int); int i,j; struct map_session_data *sd=NULL; @@ -1529,11 +1545,14 @@ int guild_broken_sub(DBKey key,void *data,va_list ap) return 0; } -//Invoked on Castles when a guild is broken. [Skotlex] -int castle_guild_broken_sub(DBKey key, void *data, va_list ap) +/** + * Invoked on Castles when a guild is broken. [Skotlex] + * @see DBApply + */ +int castle_guild_broken_sub(DBKey key, DBData *data, va_list ap) { char name[EVENT_NAME_LENGTH]; - struct guild_castle *gc = data; + struct guild_castle *gc = db_data2ptr(data); int guild_id = va_arg(ap, int); nullpo_ret(gc); @@ -1900,10 +1919,13 @@ bool guild_isallied(int guild_id, int guild_id2) return( i < MAX_GUILDALLIANCE && g->alliance[i].opposition == 0 ); } -static int eventlist_db_final(DBKey key,void *data,va_list ap) +/** + * @see DBApply + */ +static int eventlist_db_final(DBKey key, DBData *data, va_list ap) { struct eventlist *next = NULL; - struct eventlist *current = data; + struct eventlist *current = db_data2ptr(data); while (current != NULL) { next = current->next; aFree(current); @@ -1912,18 +1934,24 @@ static int eventlist_db_final(DBKey key,void *data,va_list ap) return 0; } -static int guild_expcache_db_final(DBKey key,void *data,va_list ap) +/** + * @see DBApply + */ +static int guild_expcache_db_final(DBKey key, DBData *data, va_list ap) { - ers_free(expcache_ers, data); + ers_free(expcache_ers, db_data2ptr(data)); return 0; } -static int guild_castle_db_final(DBKey key, void* data,va_list ap) +/** + * @see DBApply + */ +static int guild_castle_db_final(DBKey key, DBData *data, va_list ap) { - struct guild_castle* gc = (struct guild_castle*)data; + struct guild_castle* gc = db_data2ptr(data); if( gc->temp_guardians ) aFree(gc->temp_guardians); - aFree(data); + aFree(gc); return 0; } diff --git a/src/map/itemdb.c b/src/map/itemdb.c index e25c50a40..8da198c59 100644 --- a/src/map/itemdb.c +++ b/src/map/itemdb.c @@ -23,13 +23,14 @@ static struct item_group itemgroup_db[MAX_ITEMGROUP]; struct item_data dummy_item; //This is the default dummy item used for non-existant items. [Skotlex] -/*========================================== +/** * 名前で検索用 - *------------------------------------------*/ -// name = item alias, so we should find items aliases first. if not found then look for "jname" (full name) -static int itemdb_searchname_sub(DBKey key,void *data,va_list ap) + * name = item alias, so we should find items aliases first. if not found then look for "jname" (full name) + * @see DBApply + */ +static int itemdb_searchname_sub(DBKey key, DBData *data, va_list ap) { - struct item_data *item=(struct item_data *)data,**dst,**dst2; + struct item_data *item = db_data2ptr(data), **dst, **dst2; char *str; str=va_arg(ap,char *); dst=va_arg(ap,struct item_data **); @@ -77,9 +78,12 @@ struct item_data* itemdb_searchname(const char *str) return item?item:item2; } -static int itemdb_searchname_array_sub(DBKey key,void * data,va_list ap) +/** + * @see DBMatcher + */ +static int itemdb_searchname_array_sub(DBKey key, DBData data, va_list ap) { - struct item_data *item=(struct item_data *)data; + struct item_data *item = db_data2ptr(&data); char *str; str=va_arg(ap,char *); if (item == &dummy_item) @@ -116,17 +120,17 @@ int itemdb_searchname_array(struct item_data** data, int size, const char *str) } // search in the db - if( count >= size ) + if( count < size ) { - data = NULL; - size = 0; - } - else - { - data -= count; + DBData *db_data[MAX_SEARCH]; + int db_count = 0; size -= count; + db_count = itemdb_other->getall(itemdb_other, (DBData**)&db_data, size, itemdb_searchname_array_sub, str); + for (i = 0; i < db_count; i++) + data[count++] = db_data2ptr(db_data[i]); + count += db_count; } - return count + itemdb_other->getall(itemdb_other,(void**)data,size,itemdb_searchname_array_sub,str); + return count; } @@ -1075,9 +1079,12 @@ static void destroy_item_data(struct item_data* self, int free_self) aFree(self); } -static int itemdb_final_sub(DBKey key,void *data,va_list ap) +/** + * @see DBApply + */ +static int itemdb_final_sub(DBKey key, DBData *data, va_list ap) { - struct item_data *id = (struct item_data *)data; + struct item_data *id = db_data2ptr(data); if( id != &dummy_item ) destroy_item_data(id, 1); diff --git a/src/map/map.c b/src/map/map.c index 73a9445ef..172f921ea 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -1472,11 +1472,14 @@ int map_addflooritem(struct item *item_data,int amount,int m,int x,int y,int fir return fitem->bl.id; } -static void* create_charid2nick(DBKey key, va_list args) +/** + * @see DBCreateData + */ +static DBData create_charid2nick(DBKey key, va_list args) { struct charid2nick *p; CREATE(p, struct charid2nick, 1); - return p; + return db_ptr2data(p); } /// Adds(or replaces) the nick of charid to nick_db and fullfils pending requests. @@ -1490,7 +1493,7 @@ void map_addnickdb(int charid, const char* nick) if( map_charid2sd(charid) ) return;// already online - p = (struct charid2nick*)idb_ensure(nick_db, charid, create_charid2nick); + p = idb_ensure(nick_db, charid, create_charid2nick); safestrncpy(p->nick, nick, sizeof(p->nick)); while( p->requests ) @@ -1511,8 +1514,10 @@ void map_delnickdb(int charid, const char* name) struct charid2nick* p; struct charid_request* req; struct map_session_data* sd; + DBData data; - p = (struct charid2nick*)idb_remove(nick_db, charid); + nick_db->remove(nick_db, db_i2key(charid), &data); + p = db_data2ptr(&data); if( p == NULL ) return; @@ -1546,7 +1551,7 @@ void map_reqnickdb(struct map_session_data * sd, int charid) return; } - p = (struct charid2nick*)idb_ensure(nick_db, charid, create_charid2nick); + p = idb_ensure(nick_db, charid, create_charid2nick); if( *p->nick ) { clif_solved_charname(sd->fd, charid, p->nick); @@ -1765,7 +1770,7 @@ const char* map_charid2nick(int charid) if( sd ) return sd->status.name;// character is online, return it's name - p = (struct charid2nick*)idb_ensure(nick_db, charid, create_charid2nick); + p = idb_ensure(nick_db, charid, create_charid2nick); if( *p->nick ) return p->nick;// name in nick_db @@ -2662,14 +2667,17 @@ void map_iwall_remove(const char *wall_name) strdb_remove(iwall_db, iwall->wall_name); } -static void* create_map_data_other_server(DBKey key, va_list args) +/** + * @see DBCreateData + */ +static DBData create_map_data_other_server(DBKey key, va_list args) { struct map_data_other_server *mdos; unsigned short mapindex = (unsigned short)key.ui; mdos=(struct map_data_other_server *)aCalloc(1,sizeof(struct map_data_other_server)); mdos->index = mapindex; memcpy(mdos->name, mapindex_id2name(mapindex), MAP_NAME_LENGTH); - return mdos; + return db_ptr2data(mdos); } /*========================================== @@ -2679,7 +2687,7 @@ int map_setipport(unsigned short mapindex, uint32 ip, uint16 port) { struct map_data_other_server *mdos=NULL; - mdos=(struct map_data_other_server *)uidb_ensure(map_db,(unsigned int)mapindex, create_map_data_other_server); + mdos= uidb_ensure(map_db,(unsigned int)mapindex, create_map_data_other_server); if(mdos->cell) //Local map,Do nothing. Give priority to our own local maps over ones from another server. [Skotlex] return 0; @@ -2693,12 +2701,13 @@ int map_setipport(unsigned short mapindex, uint32 ip, uint16 port) return 1; } -/*========================================== +/** * 他鯖管理のマップを全て削除 - *------------------------------------------*/ -int map_eraseallipport_sub(DBKey key,void *data,va_list va) + * @see DBApply + */ +int map_eraseallipport_sub(DBKey key, DBData *data, va_list va) { - struct map_data_other_server *mdos = (struct map_data_other_server*)data; + struct map_data_other_server *mdos = db_data2ptr(data); if(mdos->cell == NULL) { db_remove(map_db,key); aFree(mdos); @@ -3425,17 +3434,23 @@ int log_sql_init(void) return 0; } -int map_db_final(DBKey k,void *d,va_list ap) +/** + * @see DBApply + */ +int map_db_final(DBKey key, DBData *data, va_list ap) { - struct map_data_other_server *mdos = (struct map_data_other_server*)d; + struct map_data_other_server *mdos = db_data2ptr(data); if(mdos && mdos->cell == NULL) aFree(mdos); return 0; } -int nick_db_final(DBKey key, void *data, va_list args) +/** + * @see DBApply + */ +int nick_db_final(DBKey key, DBData *data, va_list args) { - struct charid2nick* p = (struct charid2nick*)data; + struct charid2nick* p = db_data2ptr(data); struct charid_request* req; if( p == NULL ) @@ -3478,9 +3493,12 @@ int cleanup_sub(struct block_list *bl, va_list ap) return 1; } -static int cleanup_db_sub(DBKey key,void *data,va_list va) +/** + * @see DBApply + */ +static int cleanup_db_sub(DBKey key, DBData *data, va_list va) { - return cleanup_sub((struct block_list*)data, va); + return cleanup_sub(db_data2ptr(data), va); } /*========================================== diff --git a/src/map/mapreg_sql.c b/src/map/mapreg_sql.c index 365fdc8ce..c8b177c7e 100644 --- a/src/map/mapreg_sql.c +++ b/src/map/mapreg_sql.c @@ -146,7 +146,7 @@ static void script_load_mapreg(void) static void script_save_mapreg(void) { DBIterator* iter; - void* data; + DBData *data; DBKey key; iter = db_iterator(mapreg_db); @@ -159,7 +159,7 @@ static void script_save_mapreg(void) if( name[1] == '@' ) continue; - if( SQL_ERROR == Sql_Query(mmysql_handle, "UPDATE `%s` SET `value`='%d' WHERE `varname`='%s' AND `index`='%d'", mapreg_table, (int)data, name, i) ) + if( SQL_ERROR == Sql_Query(mmysql_handle, "UPDATE `%s` SET `value`='%d' WHERE `varname`='%s' AND `index`='%d'", mapreg_table, (int)db_data2ptr(data), name, i) ) Sql_ShowDebug(mmysql_handle); } dbi_destroy(iter); @@ -175,7 +175,7 @@ static void script_save_mapreg(void) if( name[1] == '@' ) continue; - Sql_EscapeStringLen(mmysql_handle, tmp_str2, (char*)data, safestrnlen((char*)data, 255)); + 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); } diff --git a/src/map/npc.c b/src/map/npc.c index 86d649cde..fb806cdd2 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -284,17 +284,19 @@ static int npc_event_export(struct npc_data *nd, int i) CREATE(ev, struct event_data, 1); ev->nd = nd; ev->pos = pos; - if (strdb_put(ev_db, buf, ev) != NULL) // There was already another event of the same name? + if (strdb_put(ev_db, buf, ev)) // There was already another event of the same name? return 1; } return 0; } int npc_event_sub(struct map_session_data* sd, struct event_data* ev, const char* eventname); //[Lance] -/*========================================== + +/** * 全てのNPCのOn*イベント実行 - *------------------------------------------*/ -int npc_event_doall_sub(DBKey key, void* data, va_list ap) + * @see DBApply + */ +int npc_event_doall_sub(DBKey key, DBData *data, va_list ap) { const char* p = key.str; struct event_data* ev; @@ -302,7 +304,7 @@ int npc_event_doall_sub(DBKey key, void* data, va_list ap) const char* name; int rid; - nullpo_ret(ev = (struct event_data *)data); + nullpo_ret(ev = db_data2ptr(data)); nullpo_ret(c = va_arg(ap, int *)); nullpo_ret(name = va_arg(ap, const char *)); rid = va_arg(ap, int); @@ -320,14 +322,17 @@ int npc_event_doall_sub(DBKey key, void* data, va_list ap) return 0; } -static int npc_event_do_sub(DBKey key, void* data, va_list ap) +/** + * @see DBApply + */ +static int npc_event_do_sub(DBKey key, DBData *data, va_list ap) { const char* p = key.str; struct event_data* ev; int* c; const char* name; - nullpo_ret(ev = (struct event_data *)data); + nullpo_ret(ev = db_data2ptr(data)); nullpo_ret(c = va_arg(ap, int *)); nullpo_ret(name = va_arg(ap, const char *)); @@ -1675,9 +1680,12 @@ int npc_remove_map(struct npc_data* nd) return 0; } -static int npc_unload_ev(DBKey key, void* data, va_list ap) +/** + * @see DBApply + */ +static int npc_unload_ev(DBKey key, DBData *data, va_list ap) { - struct event_data* ev = (struct event_data *)data; + struct event_data* ev = db_data2ptr(data); char* npcname = va_arg(ap, char *); if(strcmp(ev->nd->exname,npcname)==0){ @@ -2133,13 +2141,14 @@ static const char* npc_parse_shop(char* w1, char* w2, char* w3, char* w4, const return strchr(start,'\n');// continue } -/*========================================== +/** * NPCのラベルデータコンバート - *------------------------------------------*/ -int npc_convertlabel_db(DBKey key, void* data, va_list ap) + * @see DBApply + */ +int npc_convertlabel_db(DBKey key, DBData *data, va_list ap) { const char* lname = (const char*)key.str; - int lpos = (int)data; + int lpos = (int)db_data2ptr(data); struct npc_label_list** label_list; int* label_list_num; const char* filepath; @@ -2709,8 +2718,8 @@ void npc_setclass(struct npc_data* nd, short class_) static const char* npc_parse_function(char* w1, char* w2, char* w3, char* w4, const char* start, const char* buffer, const char* filepath) { DBMap* func_db; + DBData old_data; struct script_code *script; - struct script_code *oldscript; const char* end; const char* script_start; @@ -2732,9 +2741,9 @@ static const char* npc_parse_function(char* w1, char* w2, char* w3, char* w4, co return end; func_db = script_get_userfunc_db(); - oldscript = (struct script_code*)strdb_put(func_db, w3, script); - if( oldscript != NULL ) + if (func_db->put(func_db, db_str2key(w3), db_ptr2data(script), &old_data)) { + struct script_code *oldscript = db_data2ptr(&old_data); ShowInfo("npc_parse_function: Overwriting user function [%s] (%s:%d)\n", w3, filepath, strline(buffer,start-buffer)); script_free_vars(&oldscript->script_vars); aFree(oldscript->script_buf); @@ -3358,7 +3367,7 @@ void npc_read_event_script(void) { DBIterator* iter; DBKey key; - void* data; + DBData *data; char name[64]="::"; strncpy(name+2,config[i].event_name,62); @@ -3368,7 +3377,7 @@ void npc_read_event_script(void) for( data = iter->first(iter,&key); iter->exists(iter); data = iter->next(iter,&key) ) { const char* p = key.str; - struct event_data* ed = (struct event_data*) data; + struct event_data* ed = db_data2ptr(data); unsigned char count = script_event[i].event_count; if( count >= ARRAYLENGTH(script_event[i].event) ) diff --git a/src/map/script.c b/src/map/script.c index 3fa32d681..d2ff334bf 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -3634,10 +3634,14 @@ int script_config_read(char *cfgName) return 0; } -static int db_script_free_code_sub(DBKey key, void *data, va_list ap) +/** + * @see DBApply + */ +static int db_script_free_code_sub(DBKey key, DBData *data, va_list ap) { - if (data) - script_free_code(data); + struct script_code *code = db_data2ptr(data); + if (code) + script_free_code(code); return 0; } diff --git a/src/map/skill.c b/src/map/skill.c index b06a6f84c..1f18d2474 100644 --- a/src/map/skill.c +++ b/src/map/skill.c @@ -13579,12 +13579,12 @@ int skill_unit_timer_sub_onplace (struct block_list* bl, va_list ap) return 1; } -/*========================================== - * - *------------------------------------------*/ -static int skill_unit_timer_sub (DBKey key, void* data, va_list ap) +/** + * @see DBApply + */ +static int skill_unit_timer_sub(DBKey key, DBData *data, va_list ap) { - struct skill_unit* unit = (struct skill_unit*)data; + struct skill_unit* unit = db_data2ptr(data); struct skill_unit_group* group = unit->group; unsigned int tick = va_arg(ap,unsigned int); bool dissonance; diff --git a/src/map/storage.c b/src/map/storage.c index eed454c7c..d9ab0312f 100644 --- a/src/map/storage.c +++ b/src/map/storage.c @@ -66,11 +66,13 @@ void do_final_storage(void) // by [MC Cameri] guild_storage_db->destroy(guild_storage_db,NULL); } - -static int storage_reconnect_sub(DBKey key,void *data,va_list ap) -{ //Parses storage and saves 'dirty' ones upon reconnect. [Skotlex] - - struct guild_storage* stor = (struct guild_storage*) data; +/** + * Parses storage and saves 'dirty' ones upon reconnect. [Skotlex] + * @see DBApply + */ +static int storage_reconnect_sub(DBKey key, DBData *data, va_list ap) +{ + struct guild_storage *stor = db_data2ptr(data); if (stor->dirty && stor->storage_status == 0) //Save closed storages. storage_guild_storagesave(0, stor->guild_id,0); @@ -318,19 +320,22 @@ void storage_storage_quit(struct map_session_data* sd, int flag) sd->state.storage_flag = 0; } - -static void* create_guildstorage(DBKey key, va_list args) +/** + * @see DBCreateData + */ +static DBData create_guildstorage(DBKey key, va_list args) { struct guild_storage *gs = NULL; gs = (struct guild_storage *) aCalloc(sizeof(struct guild_storage), 1); gs->guild_id=key.i; - return gs; + return db_ptr2data(gs); } + struct guild_storage *guild2storage(int guild_id) { struct guild_storage *gs = NULL; if(guild_search(guild_id) != NULL) - gs=(struct guild_storage *) idb_ensure(guild_storage_db,guild_id,create_guildstorage); + gs = idb_ensure(guild_storage_db,guild_id,create_guildstorage); return gs; } -- cgit v1.2.3-70-g09d2