diff options
author | Haru <haru@dotalux.com> | 2015-09-17 01:21:28 +0200 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2015-10-11 00:24:22 +0200 |
commit | 70265291d62280c525adc317158e9f531e0147ff (patch) | |
tree | 8beae9d0edc99a38bc678b86f2709780314ad327 /src/common | |
parent | 502703d2b632125b35a2b8d341a90a13d7445f02 (diff) | |
download | hercules-70265291d62280c525adc317158e9f531e0147ff.tar.gz hercules-70265291d62280c525adc317158e9f531e0147ff.tar.bz2 hercules-70265291d62280c525adc317158e9f531e0147ff.tar.xz hercules-70265291d62280c525adc317158e9f531e0147ff.zip |
Cleanup of the HPluginData implementation (First part)
- Several explicit casts are removed, to have a slightly better
type-checking at compile time.
- A destructor function is provided, to remove code duplication.
Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/HPM.c | 168 | ||||
-rw-r--r-- | src/common/HPM.h | 20 | ||||
-rw-r--r-- | src/common/HPMi.h | 79 | ||||
-rw-r--r-- | src/common/mmo.h | 5 | ||||
-rw-r--r-- | src/common/socket.c | 13 | ||||
-rw-r--r-- | src/common/socket.h | 5 |
6 files changed, 154 insertions, 136 deletions
diff --git a/src/common/HPM.c b/src/common/HPM.c index 77c7e3fa2..ce3d769ca 100644 --- a/src/common/HPM.c +++ b/src/common/HPM.c @@ -168,57 +168,54 @@ bool hplugins_addpacket(unsigned short cmd, unsigned short length, void (*receiv return true; } -void hplugins_grabHPData(struct HPDataOperationStorage *ret, enum HPluginDataTypes type, void *ptr) +bool hplugin_data_store_validate(enum HPluginDataTypes type, struct hplugin_data_store **store) { - /* record address */ + nullpo_retr(false, store); + switch (type) { /* core-handled */ case HPDT_SESSION: - ret->HPDataSRCPtr = (void**)(&((struct socket_data *)ptr)->hdata); - ret->hdatac = &((struct socket_data *)ptr)->hdatac; - break; + if (!*store) { + *store = HPM->data_store_create(); + } + return true; /* goes to sub */ default: - if (HPM->grabHPDataSub) { - if (HPM->grabHPDataSub(ret,type,ptr)) - return; - ShowError("HPM:HPM:grabHPData failed, unknown type %d!\n",type); - } else { - ShowError("HPM:grabHPData failed, type %d needs sub-handler!\n",type); - } - ret->HPDataSRCPtr = NULL; - ret->hdatac = NULL; - return; + break; } + if (HPM->data_store_validate_sub) { + if (HPM->data_store_validate_sub(type, store)) + return true; + ShowError("HPM:HPM:validateHPData failed, unknown type %d!\n",type); + } else { + ShowError("HPM:validateHPData failed, type %d needs sub-handler!\n",type); + } + return false; } -void hplugins_addToHPData(enum HPluginDataTypes type, unsigned int pluginID, void *ptr, void *data, unsigned int index, bool autofree) +void hplugins_addToHPData(enum HPluginDataTypes type, unsigned int pluginID, struct hplugin_data_store **storeptr, void *data, unsigned int index, bool autofree) { - struct HPluginData *HPData, **HPDataSRC; - struct HPDataOperationStorage action; - unsigned int i, max; - - HPM->grabHPData(&action,type,ptr); + struct hplugin_data_entry *HPData; + unsigned int i; + struct hplugin_data_store *store; - if (action.hdatac == NULL) { /* woo it failed! */ + if (!HPM->data_store_validate(type, storeptr)) { + /* woo it failed! */ ShowError("HPM:addToHPData:%s: failed, type %d (%u|%u)\n",HPM->pid2name(pluginID),type,pluginID,index); return; } - - /* flag */ - HPDataSRC = *(action.HPDataSRCPtr); - max = *(action.hdatac); + store = *storeptr; /* duplicate check */ - for (i = 0; i < max; i++) { - if (HPDataSRC[i]->pluginID == pluginID && HPDataSRC[i]->type == index) { + for (i = 0; i < store->count; i++) { + if (store->array[i]->pluginID == pluginID && store->array[i]->type == index) { ShowError("HPM:addToHPData:%s: error! attempting to insert duplicate struct of id %u and index %u\n",HPM->pid2name(pluginID),pluginID,index); return; } } - /* HPluginData is always same size, probably better to use the ERS (with reasonable chunk size e.g. 10/25/50) */ - CREATE(HPData, struct HPluginData, 1); + /* hplugin_data_entry is always same size, probably better to use the ERS (with reasonable chunk size e.g. 10/25/50) */ + CREATE(HPData, struct hplugin_data_entry, 1); /* input */ HPData->pluginID = pluginID; @@ -227,76 +224,63 @@ void hplugins_addToHPData(enum HPluginDataTypes type, unsigned int pluginID, voi HPData->data = data; /* resize */ - *(action.hdatac) += 1; - RECREATE(*(action.HPDataSRCPtr),struct HPluginData *,*(action.hdatac)); + RECREATE(store->array, struct hplugin_data_entry *, ++store->count); - /* RECREATE modified the address */ - HPDataSRC = *(action.HPDataSRCPtr); - HPDataSRC[*(action.hdatac) - 1] = HPData; + store->array[store->count - 1] = HPData; } -void *hplugins_getFromHPData(enum HPluginDataTypes type, unsigned int pluginID, void *ptr, unsigned int index) +void *hplugins_getFromHPData(enum HPluginDataTypes type, unsigned int pluginID, struct hplugin_data_store **storeptr, unsigned int index) { - struct HPDataOperationStorage action; - struct HPluginData **HPDataSRC; - unsigned int i, max; - - HPM->grabHPData(&action,type,ptr); + unsigned int i; + struct hplugin_data_store *store; - if (action.hdatac == NULL) { /* woo it failed! */ + if (!HPM->data_store_validate(type, storeptr)) { + /* woo it failed! */ ShowError("HPM:getFromHPData:%s: failed, type %d (%u|%u)\n",HPM->pid2name(pluginID),type,pluginID,index); return NULL; } + store = *storeptr; - /* flag */ - HPDataSRC = *(action.HPDataSRCPtr); - max = *(action.hdatac); - - for (i = 0; i < max; i++) { - if (HPDataSRC[i]->pluginID == pluginID && HPDataSRC[i]->type == index) - return HPDataSRC[i]->data; + for (i = 0; i < store->count; i++) { + if (store->array[i]->pluginID == pluginID && store->array[i]->type == index) + return store->array[i]->data; } return NULL; } -void hplugins_removeFromHPData(enum HPluginDataTypes type, unsigned int pluginID, void *ptr, unsigned int index) +void hplugins_removeFromHPData(enum HPluginDataTypes type, unsigned int pluginID, struct hplugin_data_store **storeptr, unsigned int index) { - struct HPDataOperationStorage action; - struct HPluginData **HPDataSRC; - unsigned int i, max; - - HPM->grabHPData(&action,type,ptr); + unsigned int i; + struct hplugin_data_store *store; - if (action.hdatac == NULL) { /* woo it failed! */ + if (!HPM->data_store_validate(type, storeptr)) { + /* woo it failed! */ ShowError("HPM:removeFromHPData:%s: failed, type %d (%u|%u)\n",HPM->pid2name(pluginID),type,pluginID,index); return; } + store = *storeptr; - /* flag */ - HPDataSRC = *(action.HPDataSRCPtr); - max = *(action.hdatac); - - for (i = 0; i < max; i++) { - if (HPDataSRC[i]->pluginID == pluginID && HPDataSRC[i]->type == index) + for (i = 0; i < store->count; i++) { + if (store->array[i]->pluginID == pluginID && store->array[i]->type == index) break; } - if (i != max) { + if (i != store->count) { unsigned int cursor; - aFree(HPDataSRC[i]->data);/* when its removed we delete it regardless of autofree */ - aFree(HPDataSRC[i]); - HPDataSRC[i] = NULL; + aFree(store->array[i]->data);/* when its removed we delete it regardless of autofree */ + aFree(store->array[i]); + store->array[i] = NULL; - for (i = 0, cursor = 0; i < max; i++) { - if (HPDataSRC[i] == NULL) + for (i = 0, cursor = 0; i < store->count; i++) { + if (store->array[i] == NULL) continue; if (i != cursor) - HPDataSRC[cursor] = HPDataSRC[i]; + store->array[cursor] = store->array[i]; cursor++; } - *(action.hdatac) = cursor; + store->count = cursor; } } @@ -781,6 +765,43 @@ bool hplugins_parse_conf(const char *w1, const char *w2, enum HPluginConfType po } /** + * Helper to destroy and release an interface's hplugin_data store. + * + * @param hdata The hplugin_data store. The pointer will be freed. + */ +void hplugin_data_store_destroy(struct hplugin_data_store *store) +{ + unsigned int i; + + if (!store) + return; + + for (i = 0; i < store->count; i++) { + if (store->array[i]->flag.free) { + aFree(store->array[i]->data); + } + aFree(store->array[i]); + } + aFree(store->array); + aFree(store); +} + +/** + * Helper to create and initialize an interface's hplugin_data store. + * + * The store is owned by the caller, and it should be eventually destroyed by + * \c hdata_destroy. + * + * @return An initialized hplugin_data store. + */ +struct hplugin_data_store *hplugin_data_store_create(void) +{ + struct hplugin_data_store *store; + CREATE(store, struct hplugin_data_store, 1); + return store; +} + +/** * Called by HPM->DataCheck on a plugins incoming data, ensures data structs in use are matching! **/ bool HPM_DataCheck(struct s_HPMDataCheck *src, unsigned int size, int version, char *name) { @@ -947,10 +968,13 @@ void hpm_defaults(void) HPM->parse_packets = hplugins_parse_packets; HPM->load_sub = NULL; HPM->addhook_sub = NULL; - HPM->grabHPData = hplugins_grabHPData; - HPM->grabHPDataSub = NULL; HPM->parseConf = hplugins_parse_conf; HPM->DataCheck = HPM_DataCheck; HPM->datacheck_init = HPM_datacheck_init; HPM->datacheck_final = HPM_datacheck_final; + + HPM->data_store_destroy = hplugin_data_store_destroy; + HPM->data_store_create = hplugin_data_store_create; + HPM->data_store_validate = hplugin_data_store_validate; + HPM->data_store_validate_sub = NULL; } diff --git a/src/common/HPM.h b/src/common/HPM.h index 444829419..1d13a178f 100644 --- a/src/common/HPM.h +++ b/src/common/HPM.h @@ -65,7 +65,7 @@ struct hpm_symbol { void *ptr; ///< The symbol value }; -struct HPluginData { +struct hplugin_data_entry { unsigned int pluginID; unsigned int type; struct { @@ -74,6 +74,11 @@ struct HPluginData { void *data; }; +struct hplugin_data_store { + struct hplugin_data_entry **array; + unsigned int count; +}; + struct HPluginPacket { unsigned int pluginID; unsigned short cmd; @@ -86,10 +91,6 @@ struct HPMFileNameCache { char *name; }; -struct HPDataOperationStorage { - void **HPDataSRCPtr; - unsigned int *hdatac; -}; /* */ struct HPConfListenStorage { unsigned int pluginID; @@ -136,15 +137,18 @@ struct HPM_interface { unsigned char (*parse_packets) (int fd, enum HPluginPacketHookingPoints point); void (*load_sub) (struct hplugin *plugin); bool (*addhook_sub) (enum HPluginHookType type, const char *target, void *hook, unsigned int pID); - void (*grabHPData) (struct HPDataOperationStorage *ret, enum HPluginDataTypes type, void *ptr); - /* for server-specific HPData e.g. map_session_data */ - bool (*grabHPDataSub) (struct HPDataOperationStorage *ret, enum HPluginDataTypes type, void *ptr); /* for custom config parsing */ bool (*parseConf) (const char *w1, const char *w2, enum HPluginConfType point); /* validates plugin data */ bool (*DataCheck) (struct s_HPMDataCheck *src, unsigned int size, int version, char *name); void (*datacheck_init) (const struct s_HPMDataCheck *src, unsigned int length, int version); void (*datacheck_final) (void); + + struct hplugin_data_store *(*data_store_create) (void); + void (*data_store_destroy) (struct hplugin_data_store *store); + bool (*data_store_validate) (enum HPluginDataTypes type, struct hplugin_data_store **store); + /* for server-specific HPData e.g. map_session_data */ + bool (*data_store_validate_sub) (enum HPluginDataTypes type, struct hplugin_data_store **store); }; CMDLINEARG(loadplugin); diff --git a/src/common/HPMi.h b/src/common/HPMi.h index eee713fd9..d92503a91 100644 --- a/src/common/HPMi.h +++ b/src/common/HPMi.h @@ -14,6 +14,7 @@ struct script_state; struct AtCommandInfo; struct socket_data; struct map_session_data; +struct hplugin_data_store; #define HPM_VERSION "1.1" #define HPM_ADDCONF_LENGTH 40 @@ -96,53 +97,53 @@ enum HPluginConfType { #define addArg(name, param,func,help) (HPMi->addArg(HPMi->pid,(name),(param),(cmdline_arg_ ## func),(help))) /* HPData handy redirects */ /* session[] */ -#define addToSession(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_SESSION,HPMi->pid,(ptr),(data),(index),(autofree))) -#define getFromSession(ptr,index) (HPMi->getFromHPData(HPDT_SESSION,HPMi->pid,(ptr),(index))) -#define removeFromSession(ptr,index) (HPMi->removeFromHPData(HPDT_SESSION,HPMi->pid,(ptr),(index))) +#define addToSession(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_SESSION,HPMi->pid,&(ptr)->hdata,(data),(index),(autofree))) +#define getFromSession(ptr,index) (HPMi->getFromHPData(HPDT_SESSION,HPMi->pid,&(ptr)->hdata,(index))) +#define removeFromSession(ptr,index) (HPMi->removeFromHPData(HPDT_SESSION,HPMi->pid,&(ptr)->hdata,(index))) /* map_session_data */ -#define addToMSD(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_MSD,HPMi->pid,(ptr),(data),(index),(autofree))) -#define getFromMSD(ptr,index) (HPMi->getFromHPData(HPDT_MSD,HPMi->pid,(ptr),(index))) -#define removeFromMSD(ptr,index) (HPMi->removeFromHPData(HPDT_MSD,HPMi->pid,(ptr),(index))) +#define addToMSD(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_MSD,HPMi->pid,&(ptr)->hdata,(data),(index),(autofree))) +#define getFromMSD(ptr,index) (HPMi->getFromHPData(HPDT_MSD,HPMi->pid,&(ptr)->hdata,(index))) +#define removeFromMSD(ptr,index) (HPMi->removeFromHPData(HPDT_MSD,HPMi->pid,&(ptr)->hdata,(index))) /* npc_data */ -#define addToNPCD(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_NPCD,HPMi->pid,(ptr),(data),(index),(autofree))) -#define getFromNPCD(ptr,index) (HPMi->getFromHPData(HPDT_NPCD,HPMi->pid,(ptr),(index))) -#define removeFromNPCD(ptr,index) (HPMi->removeFromHPData(HPDT_NPCD,HPMi->pid,(ptr),(index))) +#define addToNPCD(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_NPCD,HPMi->pid,&(ptr)->hdata,(data),(index),(autofree))) +#define getFromNPCD(ptr,index) (HPMi->getFromHPData(HPDT_NPCD,HPMi->pid,&(ptr)->hdata,(index))) +#define removeFromNPCD(ptr,index) (HPMi->removeFromHPData(HPDT_NPCD,HPMi->pid,&(ptr)->hdata,(index))) /* map_data */ -#define addToMAPD(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_MAP,HPMi->pid,(ptr),(data),(index),(autofree))) -#define getFromMAPD(ptr,index) (HPMi->getFromHPData(HPDT_MAP,HPMi->pid,(ptr),(index))) -#define removeFromMAPD(ptr,index) (HPMi->removeFromHPData(HPDT_MAP,HPMi->pid,(ptr),(index))) +#define addToMAPD(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_MAP,HPMi->pid,&(ptr)->hdata,(data),(index),(autofree))) +#define getFromMAPD(ptr,index) (HPMi->getFromHPData(HPDT_MAP,HPMi->pid,&(ptr)->hdata,(index))) +#define removeFromMAPD(ptr,index) (HPMi->removeFromHPData(HPDT_MAP,HPMi->pid,&(ptr)->hdata,(index))) /* party_data */ -#define addToPAD(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_PARTY,HPMi->pid,(ptr),(data),(index),(autofree))) -#define getFromPAD(ptr,index) (HPMi->getFromHPData(HPDT_PARTY,HPMi->pid,(ptr),(index))) -#define removeFromPAD(ptr,index) (HPMi->removeFromHPData(HPDT_PARTY,HPMi->pid,(ptr),(index))) +#define addToPAD(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_PARTY,HPMi->pid,&(ptr)->hdata,(data),(index),(autofree))) +#define getFromPAD(ptr,index) (HPMi->getFromHPData(HPDT_PARTY,HPMi->pid,&(ptr)->hdata,(index))) +#define removeFromPAD(ptr,index) (HPMi->removeFromHPData(HPDT_PARTY,HPMi->pid,&(ptr)->hdata,(index))) /* guild */ -#define addToGLD(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_GUILD,HPMi->pid,(ptr),(data),(index),(autofree))) -#define getFromGLD(ptr,index) (HPMi->getFromHPData(HPDT_GUILD,HPMi->pid,(ptr),(index))) -#define removeFromGLD(ptr,index) (HPMi->removeFromHPData(HPDT_GUILD,HPMi->pid,(ptr),(index))) +#define addToGLD(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_GUILD,HPMi->pid,&(ptr)->hdata,(data),(index),(autofree))) +#define getFromGLD(ptr,index) (HPMi->getFromHPData(HPDT_GUILD,HPMi->pid,&(ptr)->hdata,(index))) +#define removeFromGLD(ptr,index) (HPMi->removeFromHPData(HPDT_GUILD,HPMi->pid,&(ptr)->hdata,(index))) /* instance_data */ -#define addToINSTD(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_INSTANCE,HPMi->pid,(ptr),(data),(index),(autofree))) -#define getFromINSTD(ptr,index) (HPMi->getFromHPData(HPDT_INSTANCE,HPMi->pid,(ptr),(index))) -#define removeFromINSTD(ptr,index) (HPMi->removeFromHPData(HPDT_INSTANCE,HPMi->pid,(ptr),(index))) +#define addToINSTD(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_INSTANCE,HPMi->pid,&(ptr)->hdata,(data),(index),(autofree))) +#define getFromINSTD(ptr,index) (HPMi->getFromHPData(HPDT_INSTANCE,HPMi->pid,&(ptr)->hdata,(index))) +#define removeFromINSTD(ptr,index) (HPMi->removeFromHPData(HPDT_INSTANCE,HPMi->pid,&(ptr)->hdata,(index))) /* mob_db */ -#define addToMOBDB(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_MOBDB,HPMi->pid,(ptr),(data),(index),(autofree))) -#define getFromMOBDB(ptr,index) (HPMi->getFromHPData(HPDT_MOBDB,HPMi->pid,(ptr),(index))) -#define removeFromMOBDB(ptr,index) (HPMi->removeFromHPData(HPDT_MOBDB,HPMi->pid,(ptr),(index))) +#define addToMOBDB(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_MOBDB,HPMi->pid,&(ptr)->hdata,(data),(index),(autofree))) +#define getFromMOBDB(ptr,index) (HPMi->getFromHPData(HPDT_MOBDB,HPMi->pid,&(ptr)->hdata,(index))) +#define removeFromMOBDB(ptr,index) (HPMi->removeFromHPData(HPDT_MOBDB,HPMi->pid,&(ptr)->hdata,(index))) /* mob_data */ -#define addToMOBDATA(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_MOBDATA,HPMi->pid,(ptr),(data),(index),(autofree))) -#define getFromMOBDATA(ptr,index) (HPMi->getFromHPData(HPDT_MOBDATA,HPMi->pid,(ptr),(index))) -#define removeFromMOBDATA(ptr,index) (HPMi->removeFromHPData(HPDT_MOBDATA,HPMi->pid,(ptr),(index))) +#define addToMOBDATA(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_MOBDATA,HPMi->pid,&(ptr)->hdata,(data),(index),(autofree))) +#define getFromMOBDATA(ptr,index) (HPMi->getFromHPData(HPDT_MOBDATA,HPMi->pid,&(ptr)->hdata,(index))) +#define removeFromMOBDATA(ptr,index) (HPMi->removeFromHPData(HPDT_MOBDATA,HPMi->pid,&(ptr)->hdata,(index))) /* item_data */ -#define addToITEMDATA(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_ITEMDATA,HPMi->pid,(ptr),(data),(index),(autofree))) -#define getFromITEMDATA(ptr,index) (HPMi->getFromHPData(HPDT_ITEMDATA,HPMi->pid,(ptr),(index))) -#define removeFromITEMDATA(ptr,index) (HPMi->removeFromHPData(HPDT_ITEMDATA,HPMi->pid,(ptr),(index))) +#define addToITEMDATA(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_ITEMDATA,HPMi->pid,&(ptr)->hdata,(data),(index),(autofree))) +#define getFromITEMDATA(ptr,index) (HPMi->getFromHPData(HPDT_ITEMDATA,HPMi->pid,&(ptr)->hdata,(index))) +#define removeFromITEMDATA(ptr,index) (HPMi->removeFromHPData(HPDT_ITEMDATA,HPMi->pid,&(ptr)->hdata,(index))) /* battleground_data */ -#define addToBGDATA(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_BGDATA,HPMi->pid,(ptr),(data),(index),(autofree))) -#define getFromBGDATA(ptr,index) (HPMi->getFromHPData(HPDT_BGDATA,HPMi->pid,(ptr),(index))) -#define removeFromBGDATA(ptr,index) (HPMi->removeFromHPData(HPDT_BGDATA,HPMi->pid,(ptr),(index))) +#define addToBGDATA(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_BGDATA,HPMi->pid,&(ptr)->hdata,(data),(index),(autofree))) +#define getFromBGDATA(ptr,index) (HPMi->getFromHPData(HPDT_BGDATA,HPMi->pid,&(ptr)->hdata,(index))) +#define removeFromBGDATA(ptr,index) (HPMi->removeFromHPData(HPDT_BGDATA,HPMi->pid,&(ptr)->hdata,(index))) /* autotrade_vending */ -#define addToATVEND(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_AUTOTRADE_VEND,HPMi->pid,(ptr),(data),(index),(autofree))) -#define getFromATVEND(ptr,index) (HPMi->getFromHPData(HPDT_AUTOTRADE_VEND,HPMi->pid,(ptr),(index))) -#define removeFromATVEND(ptr,index) (HPMi->removeFromHPData(HPDT_AUTOTRADE_VEND,HPMi->pid,(ptr),(index))) +#define addToATVEND(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_AUTOTRADE_VEND,HPMi->pid,&(ptr)->hdata,(data),(index),(autofree))) +#define getFromATVEND(ptr,index) (HPMi->getFromHPData(HPDT_AUTOTRADE_VEND,HPMi->pid,&(ptr)->hdata,(index))) +#define removeFromATVEND(ptr,index) (HPMi->removeFromHPData(HPDT_AUTOTRADE_VEND,HPMi->pid,&(ptr)->hdata,(index))) /// HPMi->addCommand #define addAtcommand(cname,funcname) do { \ @@ -205,9 +206,9 @@ struct HPMi_interface { bool (*addScript) (char *name, char *args, bool (*func)(struct script_state *st), bool isDeprecated); void (*addCPCommand) (char *name, CParseFunc func); /* HPM Custom Data */ - void (*addToHPData) (enum HPluginDataTypes type, unsigned int pluginID, void *ptr, void *data, unsigned int index, bool autofree); - void *(*getFromHPData) (enum HPluginDataTypes type, unsigned int pluginID, void *ptr, unsigned int index); - void (*removeFromHPData) (enum HPluginDataTypes type, unsigned int pluginID, void *ptr, unsigned int index); + void (*addToHPData) (enum HPluginDataTypes type, unsigned int pluginID, struct hplugin_data_store **storeptr, void *data, unsigned int index, bool autofree); + void *(*getFromHPData) (enum HPluginDataTypes type, unsigned int pluginID, struct hplugin_data_store **storeptr, unsigned int index); + void (*removeFromHPData) (enum HPluginDataTypes type, unsigned int pluginID, struct hplugin_data_store **storeptr, unsigned int index); /* packet */ bool (*addPacket) (unsigned short cmd, unsigned short length, void (*receive)(int fd), unsigned int point, unsigned int pluginID); /* Hooking */ diff --git a/src/common/mmo.h b/src/common/mmo.h index 012eec935..cbda0e91b 100644 --- a/src/common/mmo.h +++ b/src/common/mmo.h @@ -198,7 +198,7 @@ #define JOBL_BABY 0x2000 //8192 #define JOBL_THIRD 0x4000 //16384 -struct HPluginData; +struct hplugin_data_store; enum item_types { IT_HEALING = 0, @@ -663,8 +663,7 @@ struct guild { struct channel_data *channel; /* HPM Custom Struct */ - struct HPluginData **hdata; - unsigned int hdatac; + struct hplugin_data_store *hdata; }; struct guild_castle { diff --git a/src/common/socket.c b/src/common/socket.c index de8ca4682..842f9ba87 100644 --- a/src/common/socket.c +++ b/src/common/socket.c @@ -623,7 +623,6 @@ static int create_session(int fd, RecvFunc func_recv, SendFunc func_send, ParseF sockt->session[fd]->rdata_tick = sockt->last_tick; sockt->session[fd]->session_data = NULL; sockt->session[fd]->hdata = NULL; - sockt->session[fd]->hdatac = 0; return 0; } @@ -638,16 +637,8 @@ static void delete_session(int fd) aFree(sockt->session[fd]->wdata); if( sockt->session[fd]->session_data ) aFree(sockt->session[fd]->session_data); - if (sockt->session[fd]->hdata) { - unsigned int i; - for(i = 0; i < sockt->session[fd]->hdatac; i++) { - if( sockt->session[fd]->hdata[i]->flag.free ) { - aFree(sockt->session[fd]->hdata[i]->data); - } - aFree(sockt->session[fd]->hdata[i]); - } - aFree(sockt->session[fd]->hdata); - } + HPM->data_store_destroy(sockt->session[fd]->hdata); + sockt->session[fd]->hdata = NULL; aFree(sockt->session[fd]); sockt->session[fd] = NULL; } diff --git a/src/common/socket.h b/src/common/socket.h index a995bffc8..510eac575 100644 --- a/src/common/socket.h +++ b/src/common/socket.h @@ -17,7 +17,7 @@ # include <sys/types.h> #endif -struct HPluginData; +struct hplugin_data_store; #define FIFOSIZE_SERVERLINK 256*1024 @@ -105,8 +105,7 @@ struct socket_data { void* session_data; // stores application-specific data related to the session - struct HPluginData **hdata; - unsigned int hdatac; + struct hplugin_data_store *hdata; }; struct hSockOpt { |