From 95c375db8b813406db03a3f7754525198c696cc1 Mon Sep 17 00:00:00 2001 From: gepard1984 Date: Sat, 17 Mar 2012 23:20:07 +0000 Subject: - Reverted r15701 and r15702 to restore ERS for guild exp cache. - Readded another fix for bugreport:5458 (crash caused by guild exp cache code freeing wrong memory area, since r15682). git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@15705 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/map/guild.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'src/map/guild.c') diff --git a/src/map/guild.c b/src/map/guild.c index 8aad02cdc..47f5ee478 100644 --- a/src/map/guild.c +++ b/src/map/guild.c @@ -49,6 +49,7 @@ struct guild_expcache { int guild_id, account_id, char_id; uint64 exp; }; +static struct eri *expcache_ers; //For handling of guild exp payment. #define MAX_GUILD_SKILL_REQUIRE 5 struct{ @@ -297,7 +298,7 @@ int guild_payexp_timer_sub(DBKey key, DBData *data, va_list ap) (g = guild_search(c->guild_id)) == NULL || (i = guild_getindex(g, c->account_id, c->char_id)) < 0 ) { - db_remove(guild_expcache_db, db_i2key(c->char_id)); + ers_free(expcache_ers, c); return 0; } @@ -310,7 +311,7 @@ int guild_payexp_timer_sub(DBKey key, DBData *data, va_list ap) GMI_EXP,&g->member[i].exp,sizeof(g->member[i].exp)); c->exp=0; - db_remove(guild_expcache_db, db_i2key(c->char_id)); + ers_free(expcache_ers, c); return 0; } @@ -1133,17 +1134,16 @@ int guild_emblem_changed(int len,int guild_id,int emblem_id,const char *data) /** * @see DBCreateData */ -static DBData create_expcache(DBKey key, va_list args) { +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*); - CREATE(c, struct guild_expcache, 1); - + c = ers_alloc(expcache_ers, struct guild_expcache); c->guild_id = sd->status.guild_id; c->account_id = sd->status.account_id; c->char_id = sd->status.char_id; c->exp = 0; - return db_ptr2data(c); } @@ -1189,7 +1189,6 @@ int guild_getexp(struct map_session_data *sd,int exp) return 0; 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 @@ -1935,6 +1934,15 @@ static int eventlist_db_final(DBKey key, DBData *data, va_list ap) return 0; } +/** + * @see DBApply + */ +static int guild_expcache_db_final(DBKey key, DBData *data, va_list ap) +{ + ers_free(expcache_ers, db_data2ptr(data)); + return 0; +} + /** * @see DBApply */ @@ -1951,8 +1959,9 @@ void do_init_guild(void) { guild_db=idb_alloc(DB_OPT_RELEASE_DATA); castle_db=idb_alloc(DB_OPT_BASE); - guild_expcache_db=idb_alloc(DB_OPT_RELEASE_DATA); + guild_expcache_db=idb_alloc(DB_OPT_BASE); guild_infoevent_db=idb_alloc(DB_OPT_BASE); + expcache_ers = ers_new(sizeof(struct guild_expcache)); sv_readdb(db_path, "castle_db.txt", ',', 4, 5, -1, &guild_read_castledb); @@ -1965,9 +1974,11 @@ void do_init_guild(void) add_timer_interval(gettick()+GUILD_SEND_XY_INVERVAL,guild_send_xy_timer,0,0,GUILD_SEND_XY_INVERVAL); } -void do_final_guild(void) { +void do_final_guild(void) +{ db_destroy(guild_db); castle_db->destroy(castle_db,guild_castle_db_final); - db_destroy(guild_expcache_db); + guild_expcache_db->destroy(guild_expcache_db,guild_expcache_db_final); guild_infoevent_db->destroy(guild_infoevent_db,eventlist_db_final); + ers_destroy(expcache_ers); } -- cgit v1.2.3-70-g09d2