From acc992ac2838f6380ebf2b2f8a514e86c2b750d9 Mon Sep 17 00:00:00 2001 From: shennetsind Date: Sun, 19 Jan 2014 02:58:36 -0200 Subject: HPM Custom Data Struct Expansion: map/instance/party/guild As requested by the community in http://hercules.ws/board/topic/3832-hpm-custom-data-struct-for-instance-data-guild-data-and-party-data/ Signed-off-by: shennetsind --- src/map/HPMmap.c | 23 +++++++++++++++++++---- src/map/HPMmap.h | 2 +- src/map/guild.c | 20 ++++++++++++++++++++ src/map/instance.c | 13 +++++++++++++ src/map/instance.h | 4 ++++ src/map/map.c | 8 ++++++++ src/map/map.h | 4 ++++ src/map/npc.h | 1 + src/map/party.c | 27 +++++++++++++++++++++++++-- src/map/party.h | 6 ++++++ 10 files changed, 101 insertions(+), 7 deletions(-) (limited to 'src/map') diff --git a/src/map/HPMmap.c b/src/map/HPMmap.c index 9c09a7ad1..4b1338b8d 100644 --- a/src/map/HPMmap.c +++ b/src/map/HPMmap.c @@ -46,7 +46,7 @@ struct HPM_atcommand_list { struct HPM_atcommand_list *atcommand_list = NULL; unsigned int atcommand_list_items = 0; -void HPM_map_grabHPData(struct HPDataOperationStorage *ret, enum HPluginDataTypes type, void *ptr) { +bool HPM_map_grabHPData(struct HPDataOperationStorage *ret, enum HPluginDataTypes type, void *ptr) { /* record address */ switch( type ) { case HPDT_MSD: @@ -57,11 +57,26 @@ void HPM_map_grabHPData(struct HPDataOperationStorage *ret, enum HPluginDataType ret->HPDataSRCPtr = (void**)(&((struct npc_data *)ptr)->hdata); ret->hdatac = &((struct npc_data *)ptr)->hdatac; break; + case HPDT_MAP: + ret->HPDataSRCPtr = (void**)(&((struct map_data *)ptr)->hdata); + ret->hdatac = &((struct map_data *)ptr)->hdatac; + break; + case HPDT_PARTY: + ret->HPDataSRCPtr = (void**)(&((struct party_data *)ptr)->hdata); + ret->hdatac = &((struct party_data *)ptr)->hdatac; + break; + case HPDT_GUILD: + ret->HPDataSRCPtr = (void**)(&((struct guild *)ptr)->hdata); + ret->hdatac = &((struct guild *)ptr)->hdatac; + break; + case HPDT_INSTANCE: + ret->HPDataSRCPtr = (void**)(&((struct instance_data *)ptr)->hdata); + ret->hdatac = &((struct instance_data *)ptr)->hdatac; + break; default: - ret->HPDataSRCPtr = NULL; - ret->hdatac = NULL; - return; + return false; } + return true; } void HPM_map_plugin_load_sub(struct hplugin *plugin) { diff --git a/src/map/HPMmap.h b/src/map/HPMmap.h index f86f02eb9..ff8cf4c74 100644 --- a/src/map/HPMmap.h +++ b/src/map/HPMmap.h @@ -11,7 +11,7 @@ struct hplugin; struct map_session_data; -void HPM_map_grabHPData(struct HPDataOperationStorage *ret, enum HPluginDataTypes type, void *ptr); +bool HPM_map_grabHPData(struct HPDataOperationStorage *ret, enum HPluginDataTypes type, void *ptr); bool HPM_map_add_atcommand(char *name, AtCommandFunc func); void HPM_map_atcommands(void); diff --git a/src/map/guild.c b/src/map/guild.c index 909c360a8..d13c681bb 100644 --- a/src/map/guild.c +++ b/src/map/guild.c @@ -11,6 +11,7 @@ #include "../common/ers.h" #include "../common/strlib.h" #include "../common/utils.h" +#include "../common/HPM.h" #include "map.h" #include "guild.h" @@ -1758,6 +1759,16 @@ int guild_broken(int guild_id,int flag) } if( g->instance ) aFree(g->instance); + + for( i = 0; i < g->hdatac; i++ ) { + if( g->hdata[i]->flag.free ) { + aFree(g->hdata[i]->data); + } + aFree(g->hdata[i]); + } + if( g->hdata ) + aFree(g->hdata); + idb_remove(guild->db,guild_id); return 0; } @@ -2228,6 +2239,7 @@ void do_init_guild(bool minimal) { void do_final_guild(void) { DBIterator *iter = db_iterator(guild->db); struct guild *g; + int i; for( g = dbi_first(iter); dbi_exists(iter); g = dbi_next(iter) ) { if( g->channel != NULL ) @@ -2236,6 +2248,14 @@ void do_final_guild(void) { aFree(g->instance); g->instance = NULL; } + for( i = 0; i < g->hdatac; i++ ) { + if( g->hdata[i]->flag.free ) { + aFree(g->hdata[i]->data); + } + aFree(g->hdata[i]); + } + if( g->hdata ) + aFree(g->hdata); } dbi_destroy(iter); diff --git a/src/map/instance.c b/src/map/instance.c index 7c092e6cb..a111751d0 100644 --- a/src/map/instance.c +++ b/src/map/instance.c @@ -11,6 +11,7 @@ #include "../common/strlib.h" #include "../common/utils.h" #include "../common/db.h" +#include "../common/HPM.h" #include "clif.h" #include "instance.h" @@ -568,6 +569,18 @@ void instance_destroy(int instance_id) { instance->list[instance_id].map = NULL; instance->list[instance_id].state = INSTANCE_FREE; instance->list[instance_id].num_map = 0; + + for( j = 0; j < instance->list[instance_id].hdatac; j++ ) { + if( instance->list[instance_id].hdata[j]->flag.free ) { + aFree(instance->list[instance_id].hdata[j]->data); + } + aFree(instance->list[instance_id].hdata[j]); + } + if( instance->list[instance_id].hdata ) + aFree(instance->list[instance_id].hdata); + + instance->list[instance_id].hdata = NULL; + instance->list[instance_id].hdatac = 0; } /*-------------------------------------- diff --git a/src/map/instance.h b/src/map/instance.h index ddca3e36b..764a55b2b 100644 --- a/src/map/instance.h +++ b/src/map/instance.h @@ -45,6 +45,10 @@ struct instance_data { unsigned int original_progress_timeout; struct point respawn;/* reload spawn */ + + /* HPM Custom Struct */ + struct HPluginData **hdata; + unsigned int hdatac; }; struct instance_interface { diff --git a/src/map/map.c b/src/map/map.c index bb9e53cdb..07881ea56 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -3116,6 +3116,14 @@ void do_final_maps(void) { if( map->list[i].qi_data ) aFree(map->list[i].qi_data); + for( v = 0; v < map->list[i].hdatac; v++ ) { + if( map->list[i].hdata[v]->flag.free ) { + aFree(map->list[i].hdata[v]->data); + } + aFree(map->list[i].hdata[v]); + } + if( map->list[i].hdata ) + aFree(map->list[i].hdata); } map->zone_db_clear(); diff --git a/src/map/map.h b/src/map/map.h index a39cc7f86..130b181da 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -712,6 +712,10 @@ struct map_data { /* speeds up clif_updatestatus processing by causing hpmeter to run only when someone with the permission can view it */ unsigned short hpmeter_visible; + + /* HPM Custom Struct */ + struct HPluginData **hdata; + unsigned int hdatac; }; /// Stores information about a remote map (for multi-mapserver setups). diff --git a/src/map/npc.h b/src/map/npc.h index df3c1729b..266d174fb 100644 --- a/src/map/npc.h +++ b/src/map/npc.h @@ -326,6 +326,7 @@ struct npc_chat_interface *npc_chat; /** * pcre interface (libpcre) * so that plugins may share and take advantage of the core's pcre + * should be moved into core/perhaps its own file once hpm is enhanced for login/char **/ struct pcre_interface { pcre *(*compile) (const char *pattern, int options, const char **errptr, int *erroffset, const unsigned char *tableptr); diff --git a/src/map/party.c b/src/map/party.c index 7af6acff5..9f144297d 100644 --- a/src/map/party.c +++ b/src/map/party.c @@ -11,6 +11,7 @@ #include "../common/showmsg.h" #include "../common/utils.h" #include "../common/strlib.h" +#include "../common/HPM.h" #include "party.h" #include "atcommand.h" //msg_txt() @@ -94,8 +95,21 @@ TBL_PC* party_sd_check(int party_id, int account_id, int char_id) { int party_db_final(DBKey key, DBData *data, va_list ap) { struct party_data *p; - if( ( p = DB->data2ptr(data) ) && p->instance ) - aFree(p->instance); + if( ( p = DB->data2ptr(data) ) ) { + int j; + + if( p->instance ) + aFree(p->instance); + + for( j = 0; j < p->hdatac; j++ ) { + if( p->hdata[j]->flag.free ) { + aFree(p->hdata[j]->data); + } + aFree(p->hdata[j]); + } + if( p->hdata ) + aFree(p->hdata); + } return 0; } @@ -591,6 +605,15 @@ int party_broken(int party_id) if( p->instance ) aFree(p->instance); + + for( j = 0; j < p->hdatac; j++ ) { + if( p->hdata[j]->flag.free ) { + aFree(p->hdata[j]->data); + } + aFree(p->hdata[j]); + } + if( p->hdata ) + aFree(p->hdata); idb_remove(party->db,party_id); return 0; diff --git a/src/map/party.h b/src/map/party.h index 0041b1462..051c98af2 100644 --- a/src/map/party.h +++ b/src/map/party.h @@ -14,6 +14,8 @@ #define PARTY_BOOKING_JOBS 6 #define PARTY_BOOKING_RESULTS 10 +struct HPluginData; + struct party_member_data { struct map_session_data *sd; unsigned int hp; //For HP,x,y refreshing. @@ -32,6 +34,10 @@ struct party_data { unsigned snovice :1; //There's a Super Novice unsigned tk : 1; //There's a taekwon } state; + + /* HPM Custom Struct */ + struct HPluginData **hdata; + unsigned int hdatac; }; #define PB_NOTICE_LENGTH (36 + 1) -- cgit v1.2.3-60-g2f50