summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/HPM.c219
-rw-r--r--src/common/HPM.h26
-rw-r--r--src/common/HPMi.h106
-rw-r--r--src/common/mmo.h4
-rw-r--r--src/common/socket.c3
-rw-r--r--src/common/socket.h3
6 files changed, 209 insertions, 152 deletions
diff --git a/src/common/HPM.c b/src/common/HPM.c
index ce3d769ca..578e90bbc 100644
--- a/src/common/HPM.c
+++ b/src/common/HPM.c
@@ -168,120 +168,158 @@ bool hplugins_addpacket(unsigned short cmd, unsigned short length, void (*receiv
return true;
}
-bool hplugin_data_store_validate(enum HPluginDataTypes type, struct hplugin_data_store **store)
+/**
+ * Validates and if necessary initializes a plugin data store.
+ *
+ * @param type[in] The data store type.
+ * @param storeptr[in,out] A pointer to the store.
+ * @param initialize Whether the store should be initialized in case it isn't.
+ * @retval false if the store is an invalid or mismatching type.
+ * @retval true if the store is a valid type.
+ *
+ * @remark
+ * If \c storeptr is a pointer to a NULL pointer (\c storeptr itself can't
+ * be NULL), two things may happen, depending on the \c initialize value:
+ * if false, then \c storeptr isn't changed; if true, then \c storeptr is
+ * initialized through \c HPM->data_store_create() and ownership is passed
+ * to the caller.
+ */
+bool hplugin_data_store_validate(enum HPluginDataTypes type, struct hplugin_data_store **storeptr, bool initialize)
{
- nullpo_retr(false, store);
+ struct hplugin_data_store *store;
+ nullpo_retr(false, storeptr);
+ store = *storeptr;
+ if (!initialize && store == NULL)
+ return true;
switch (type) {
/* core-handled */
case HPDT_SESSION:
- if (!*store) {
- *store = HPM->data_store_create();
- }
- return true;
- /* goes to sub */
+ break;
default:
+ if (HPM->data_store_validate_sub == NULL) {
+ ShowError("HPM:validateHPData failed, type %d needs sub-handler!\n",type);
+ return false;
+ }
+ if (!HPM->data_store_validate_sub(type, storeptr, initialize)) {
+ ShowError("HPM:HPM:validateHPData failed, unknown type %d!\n",type);
+ return false;
+ }
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);
+ if (initialize && (!store || store->type == HPDT_UNKNOWN)) {
+ HPM->data_store_create(storeptr, type);
+ store = *storeptr;
}
- return false;
+ if (store->type != type) {
+ ShowError("HPM:HPM:validateHPData failed, store type mismatch %d != %d.\n",store->type, type);
+ return false;
+ }
+ return true;
}
-void hplugins_addToHPData(enum HPluginDataTypes type, unsigned int pluginID, struct hplugin_data_store **storeptr, void *data, unsigned int index, bool autofree)
+/**
+ * Adds an entry to a plugin data store.
+ *
+ * @param type[in] The store type.
+ * @param pluginID[in] The plugin identifier.
+ * @param storeptr[in,out] A pointer to the store. The store will be initialized if necessary.
+ * @param data[in] The data entry to add.
+ * @param classid[in] The entry class identifier.
+ * @param autofree[in] Whether the entry should be automatically freed when removed.
+ */
+void hplugins_addToHPData(enum HPluginDataTypes type, uint32 pluginID, struct hplugin_data_store **storeptr, void *data, uint32 classid, bool autofree)
{
- struct hplugin_data_entry *HPData;
- unsigned int i;
struct hplugin_data_store *store;
+ struct hplugin_data_entry *entry;
+ int i;
+ nullpo_retv(storeptr);
- if (!HPM->data_store_validate(type, storeptr)) {
+ if (!HPM->data_store_validate(type, storeptr, true)) {
/* woo it failed! */
- ShowError("HPM:addToHPData:%s: failed, type %d (%u|%u)\n",HPM->pid2name(pluginID),type,pluginID,index);
+ ShowError("HPM:addToHPData:%s: failed, type %d (%u|%u)\n", HPM->pid2name(pluginID), type, pluginID, classid);
return;
}
store = *storeptr;
/* duplicate check */
- 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;
- }
+ ARR_FIND(0, VECTOR_LENGTH(store->entries), i, VECTOR_INDEX(store->entries, i)->pluginID == pluginID && VECTOR_INDEX(store->entries, i)->classid == classid);
+ if (i != VECTOR_LENGTH(store->entries)) {
+ ShowError("HPM:addToHPData:%s: error! attempting to insert duplicate struct of id %u and classid %u\n", HPM->pid2name(pluginID), pluginID, classid);
+ return;
}
/* 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);
+ CREATE(entry, struct hplugin_data_entry, 1);
/* input */
- HPData->pluginID = pluginID;
- HPData->type = index;
- HPData->flag.free = autofree ? 1 : 0;
- HPData->data = data;
-
- /* resize */
- RECREATE(store->array, struct hplugin_data_entry *, ++store->count);
+ entry->pluginID = pluginID;
+ entry->classid = classid;
+ entry->flag.free = autofree ? 1 : 0;
+ entry->data = data;
- store->array[store->count - 1] = HPData;
+ VECTOR_ENSURE(store->entries, 1, 1);
+ VECTOR_PUSH(store->entries, entry);
}
-void *hplugins_getFromHPData(enum HPluginDataTypes type, unsigned int pluginID, struct hplugin_data_store **storeptr, unsigned int index)
+/**
+ * Retrieves an entry from a plugin data store.
+ *
+ * @param type[in] The store type.
+ * @param pluginID[in] The plugin identifier.
+ * @param store[in] The store.
+ * @param classid[in] The entry class identifier.
+ *
+ * @return The retrieved entry, or NULL.
+ */
+void *hplugins_getFromHPData(enum HPluginDataTypes type, uint32 pluginID, struct hplugin_data_store *store, uint32 classid)
{
- unsigned int i;
- struct hplugin_data_store *store;
+ int i;
- if (!HPM->data_store_validate(type, storeptr)) {
+ if (!HPM->data_store_validate(type, &store, false)) {
/* woo it failed! */
- ShowError("HPM:getFromHPData:%s: failed, type %d (%u|%u)\n",HPM->pid2name(pluginID),type,pluginID,index);
+ ShowError("HPM:getFromHPData:%s: failed, type %d (%u|%u)\n", HPM->pid2name(pluginID), type, pluginID, classid);
return NULL;
}
- store = *storeptr;
+ if (!store)
+ return NULL;
- for (i = 0; i < store->count; i++) {
- if (store->array[i]->pluginID == pluginID && store->array[i]->type == index)
- return store->array[i]->data;
- }
+ ARR_FIND(0, VECTOR_LENGTH(store->entries), i, VECTOR_INDEX(store->entries, i)->pluginID == pluginID && VECTOR_INDEX(store->entries, i)->classid == classid);
+ if (i != VECTOR_LENGTH(store->entries))
+ return VECTOR_INDEX(store->entries, i)->data;
return NULL;
}
-void hplugins_removeFromHPData(enum HPluginDataTypes type, unsigned int pluginID, struct hplugin_data_store **storeptr, unsigned int index)
+/**
+ * Removes an entry from a plugin data store.
+ *
+ * @param type[in] The store type.
+ * @param pluginID[in] The plugin identifier.
+ * @param store[in] The store.
+ * @param classid[in] The entry class identifier.
+ */
+void hplugins_removeFromHPData(enum HPluginDataTypes type, uint32 pluginID, struct hplugin_data_store *store, uint32 classid)
{
- unsigned int i;
- struct hplugin_data_store *store;
+ struct hplugin_data_entry *entry;
+ int i;
- if (!HPM->data_store_validate(type, storeptr)) {
+ if (!HPM->data_store_validate(type, &store, false)) {
/* woo it failed! */
- ShowError("HPM:removeFromHPData:%s: failed, type %d (%u|%u)\n",HPM->pid2name(pluginID),type,pluginID,index);
+ ShowError("HPM:removeFromHPData:%s: failed, type %d (%u|%u)\n", HPM->pid2name(pluginID), type, pluginID, classid);
return;
}
- store = *storeptr;
-
- for (i = 0; i < store->count; i++) {
- if (store->array[i]->pluginID == pluginID && store->array[i]->type == index)
- break;
- }
-
- if (i != store->count) {
- unsigned int cursor;
+ if (!store)
+ return;
- aFree(store->array[i]->data);/* when its removed we delete it regardless of autofree */
- aFree(store->array[i]);
- store->array[i] = NULL;
+ ARR_FIND(0, VECTOR_LENGTH(store->entries), i, VECTOR_INDEX(store->entries, i)->pluginID == pluginID && VECTOR_INDEX(store->entries, i)->classid == classid);
+ if (i == VECTOR_LENGTH(store->entries))
+ return;
- for (i = 0, cursor = 0; i < store->count; i++) {
- if (store->array[i] == NULL)
- continue;
- if (i != cursor)
- store->array[cursor] = store->array[i];
- cursor++;
- }
- store->count = cursor;
- }
+ entry = VECTOR_INDEX(store->entries, i);
+ VECTOR_ERASE(store->entries, i); // Erase and compact
+ aFree(entry->data); // when it's removed we delete it regardless of autofree
+ aFree(entry);
}
/* TODO: add ability for tracking using pID for the upcoming runtime load/unload support. */
@@ -765,25 +803,30 @@ bool hplugins_parse_conf(const char *w1, const char *w2, enum HPluginConfType po
}
/**
- * Helper to destroy and release an interface's hplugin_data store.
+ * Helper to destroy an interface's hplugin_data store and release any owned memory.
*
- * @param hdata The hplugin_data store. The pointer will be freed.
+ * The pointer will be cleared.
+ *
+ * @param storeptr[in,out] A pointer to the plugin data store.
*/
-void hplugin_data_store_destroy(struct hplugin_data_store *store)
+void hplugin_data_store_destroy(struct hplugin_data_store **storeptr)
{
- unsigned int i;
-
- if (!store)
+ struct hplugin_data_store *store;
+ nullpo_retv(storeptr);
+ store = *storeptr;
+ if (store == NULL)
return;
- for (i = 0; i < store->count; i++) {
- if (store->array[i]->flag.free) {
- aFree(store->array[i]->data);
+ while (VECTOR_LENGTH(store->entries) > 0) {
+ struct hplugin_data_entry *entry = VECTOR_POP(store->entries);
+ if (entry->flag.free) {
+ aFree(entry->data);
}
- aFree(store->array[i]);
+ aFree(entry);
}
- aFree(store->array);
+ VECTOR_CLEAR(store->entries);
aFree(store);
+ *storeptr = NULL;
}
/**
@@ -792,13 +835,21 @@ void hplugin_data_store_destroy(struct hplugin_data_store *store)
* The store is owned by the caller, and it should be eventually destroyed by
* \c hdata_destroy.
*
- * @return An initialized hplugin_data store.
+ * @param storeptr[in,out] A pointer to the data store to initialize.
+ * @param type[in] The store type.
*/
-struct hplugin_data_store *hplugin_data_store_create(void)
+void hplugin_data_store_create(struct hplugin_data_store **storeptr, enum HPluginDataTypes type)
{
struct hplugin_data_store *store;
- CREATE(store, struct hplugin_data_store, 1);
- return store;
+ nullpo_retv(storeptr);
+
+ if (*storeptr == NULL) {
+ CREATE(*storeptr, struct hplugin_data_store, 1);
+ }
+ store = *storeptr;
+
+ store->type = type;
+ VECTOR_INIT(store->entries);
}
/**
diff --git a/src/common/HPM.h b/src/common/HPM.h
index 1d13a178f..5420e5300 100644
--- a/src/common/HPM.h
+++ b/src/common/HPM.h
@@ -65,18 +65,24 @@ struct hpm_symbol {
void *ptr; ///< The symbol value
};
+/**
+ * A plugin custom data, to be injected in various interfaces and objects.
+ */
struct hplugin_data_entry {
- unsigned int pluginID;
- unsigned int type;
+ uint32 pluginID; ///< The owner plugin identifier.
+ uint32 classid; ///< The entry's object type, managed by the plugin (for plugins that need more than one entry).
struct {
- unsigned int free : 1;
+ unsigned int free : 1; ///< Whether the entry data should be automatically cleared by the HPM.
} flag;
- void *data;
+ void *data; ///< The entry data.
};
+/**
+ * A store for plugin custom data entries.
+ */
struct hplugin_data_store {
- struct hplugin_data_entry **array;
- unsigned int count;
+ enum HPluginDataTypes type; ///< The store type.
+ VECTOR_DECL(struct hplugin_data_entry *) entries; ///< The store entries.
};
struct HPluginPacket {
@@ -144,11 +150,11 @@ struct HPM_interface {
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);
+ void (*data_store_create) (struct hplugin_data_store **storeptr, enum HPluginDataTypes type);
+ void (*data_store_destroy) (struct hplugin_data_store **storeptr);
+ bool (*data_store_validate) (enum HPluginDataTypes type, struct hplugin_data_store **storeptr, bool initialize);
/* for server-specific HPData e.g. map_session_data */
- bool (*data_store_validate_sub) (enum HPluginDataTypes type, struct hplugin_data_store **store);
+ bool (*data_store_validate_sub) (enum HPluginDataTypes type, struct hplugin_data_store **storeptr, bool initialize);
};
CMDLINEARG(loadplugin);
diff --git a/src/common/HPMi.h b/src/common/HPMi.h
index d92503a91..9a61dd256 100644
--- a/src/common/HPMi.h
+++ b/src/common/HPMi.h
@@ -60,19 +60,23 @@ enum HPluginHookType {
HOOK_TYPE_POST,
};
+/**
+ * Data types for plugin custom data.
+ */
enum HPluginDataTypes {
- HPDT_SESSION,
- HPDT_MSD,
- HPDT_NPCD,
- HPDT_MAP,
- HPDT_INSTANCE,
- HPDT_GUILD,
- HPDT_PARTY,
- HPDT_MOBDB,
- HPDT_MOBDATA,
- HPDT_ITEMDATA,
- HPDT_BGDATA,
- HPDT_AUTOTRADE_VEND,
+ HPDT_UNKNOWN, ///< Unknown type (such as an uninitialized store).
+ HPDT_SESSION, ///< For struct socket_data.
+ HPDT_MSD, ///< For struct map_session_data.
+ HPDT_NPCD, ///< For struct npc_data.
+ HPDT_MAP, ///< For struct map_data.
+ HPDT_INSTANCE, ///< For struct instance_data.
+ HPDT_GUILD, ///< For struct guild.
+ HPDT_PARTY, ///< For struct party_data.
+ HPDT_MOBDB, ///< For struct mob_db.
+ HPDT_MOBDATA, ///< For struct mob_data.
+ HPDT_ITEMDATA, ///< For struct item_data.
+ HPDT_BGDATA, ///< For struct battleground_data.
+ HPDT_AUTOTRADE_VEND, ///< For struct autotrade_vending.
};
/* used in macros and conf storage */
@@ -97,53 +101,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)->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)))
+#define addToSession(ptr,data,classid,autofree) (HPMi->addToHPData(HPDT_SESSION,HPMi->pid,&(ptr)->hdata,(data),(classid),(autofree)))
+#define getFromSession(ptr,classid) (HPMi->getFromHPData(HPDT_SESSION,HPMi->pid,(ptr)->hdata,(classid)))
+#define removeFromSession(ptr,classid) (HPMi->removeFromHPData(HPDT_SESSION,HPMi->pid,(ptr)->hdata,(classid)))
/* map_session_data */
-#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)))
+#define addToMSD(ptr,data,classid,autofree) (HPMi->addToHPData(HPDT_MSD,HPMi->pid,&(ptr)->hdata,(data),(classid),(autofree)))
+#define getFromMSD(ptr,classid) (HPMi->getFromHPData(HPDT_MSD,HPMi->pid,(ptr)->hdata,(classid)))
+#define removeFromMSD(ptr,classid) (HPMi->removeFromHPData(HPDT_MSD,HPMi->pid,(ptr)->hdata,(classid)))
/* npc_data */
-#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)))
+#define addToNPCD(ptr,data,classid,autofree) (HPMi->addToHPData(HPDT_NPCD,HPMi->pid,&(ptr)->hdata,(data),(classid),(autofree)))
+#define getFromNPCD(ptr,classid) (HPMi->getFromHPData(HPDT_NPCD,HPMi->pid,(ptr)->hdata,(classid)))
+#define removeFromNPCD(ptr,classid) (HPMi->removeFromHPData(HPDT_NPCD,HPMi->pid,(ptr)->hdata,(classid)))
/* map_data */
-#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)))
+#define addToMAPD(ptr,data,classid,autofree) (HPMi->addToHPData(HPDT_MAP,HPMi->pid,&(ptr)->hdata,(data),(classid),(autofree)))
+#define getFromMAPD(ptr,classid) (HPMi->getFromHPData(HPDT_MAP,HPMi->pid,(ptr)->hdata,(classid)))
+#define removeFromMAPD(ptr,classid) (HPMi->removeFromHPData(HPDT_MAP,HPMi->pid,(ptr)->hdata,(classid)))
/* party_data */
-#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)))
+#define addToPAD(ptr,data,classid,autofree) (HPMi->addToHPData(HPDT_PARTY,HPMi->pid,&(ptr)->hdata,(data),(classid),(autofree)))
+#define getFromPAD(ptr,classid) (HPMi->getFromHPData(HPDT_PARTY,HPMi->pid,(ptr)->hdata,(classid)))
+#define removeFromPAD(ptr,classid) (HPMi->removeFromHPData(HPDT_PARTY,HPMi->pid,(ptr)->hdata,(classid)))
/* guild */
-#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)))
+#define addToGLD(ptr,data,classid,autofree) (HPMi->addToHPData(HPDT_GUILD,HPMi->pid,&(ptr)->hdata,(data),(classid),(autofree)))
+#define getFromGLD(ptr,classid) (HPMi->getFromHPData(HPDT_GUILD,HPMi->pid,(ptr)->hdata,(classid)))
+#define removeFromGLD(ptr,classid) (HPMi->removeFromHPData(HPDT_GUILD,HPMi->pid,(ptr)->hdata,(classid)))
/* instance_data */
-#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)))
+#define addToINSTD(ptr,data,classid,autofree) (HPMi->addToHPData(HPDT_INSTANCE,HPMi->pid,&(ptr)->hdata,(data),(classid),(autofree)))
+#define getFromINSTD(ptr,classid) (HPMi->getFromHPData(HPDT_INSTANCE,HPMi->pid,(ptr)->hdata,(classid)))
+#define removeFromINSTD(ptr,classid) (HPMi->removeFromHPData(HPDT_INSTANCE,HPMi->pid,(ptr)->hdata,(classid)))
/* mob_db */
-#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)))
+#define addToMOBDB(ptr,data,classid,autofree) (HPMi->addToHPData(HPDT_MOBDB,HPMi->pid,&(ptr)->hdata,(data),(classid),(autofree)))
+#define getFromMOBDB(ptr,classid) (HPMi->getFromHPData(HPDT_MOBDB,HPMi->pid,(ptr)->hdata,(classid)))
+#define removeFromMOBDB(ptr,classid) (HPMi->removeFromHPData(HPDT_MOBDB,HPMi->pid,(ptr)->hdata,(classid)))
/* mob_data */
-#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)))
+#define addToMOBDATA(ptr,data,classid,autofree) (HPMi->addToHPData(HPDT_MOBDATA,HPMi->pid,&(ptr)->hdata,(data),(classid),(autofree)))
+#define getFromMOBDATA(ptr,classid) (HPMi->getFromHPData(HPDT_MOBDATA,HPMi->pid,(ptr)->hdata,(classid)))
+#define removeFromMOBDATA(ptr,classid) (HPMi->removeFromHPData(HPDT_MOBDATA,HPMi->pid,(ptr)->hdata,(classid)))
/* item_data */
-#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)))
+#define addToITEMDATA(ptr,data,classid,autofree) (HPMi->addToHPData(HPDT_ITEMDATA,HPMi->pid,&(ptr)->hdata,(data),(classid),(autofree)))
+#define getFromITEMDATA(ptr,classid) (HPMi->getFromHPData(HPDT_ITEMDATA,HPMi->pid,(ptr)->hdata,(classid)))
+#define removeFromITEMDATA(ptr,classid) (HPMi->removeFromHPData(HPDT_ITEMDATA,HPMi->pid,(ptr)->hdata,(classid)))
/* battleground_data */
-#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)))
+#define addToBGDATA(ptr,data,classid,autofree) (HPMi->addToHPData(HPDT_BGDATA,HPMi->pid,&(ptr)->hdata,(data),(classid),(autofree)))
+#define getFromBGDATA(ptr,classid) (HPMi->getFromHPData(HPDT_BGDATA,HPMi->pid,(ptr)->hdata,(classid)))
+#define removeFromBGDATA(ptr,classid) (HPMi->removeFromHPData(HPDT_BGDATA,HPMi->pid,(ptr)->hdata,(classid)))
/* autotrade_vending */
-#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)))
+#define addToATVEND(ptr,data,classid,autofree) (HPMi->addToHPData(HPDT_AUTOTRADE_VEND,HPMi->pid,&(ptr)->hdata,(data),(classid),(autofree)))
+#define getFromATVEND(ptr,classid) (HPMi->getFromHPData(HPDT_AUTOTRADE_VEND,HPMi->pid,(ptr)->hdata,(classid)))
+#define removeFromATVEND(ptr,classid) (HPMi->removeFromHPData(HPDT_AUTOTRADE_VEND,HPMi->pid,(ptr)->hdata,(classid)))
/// HPMi->addCommand
#define addAtcommand(cname,funcname) do { \
@@ -206,9 +210,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, 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);
+ void (*addToHPData) (enum HPluginDataTypes type, uint32 pluginID, struct hplugin_data_store **storeptr, void *data, uint32 classid, bool autofree);
+ void *(*getFromHPData) (enum HPluginDataTypes type, uint32 pluginID, struct hplugin_data_store *store, uint32 classid);
+ void (*removeFromHPData) (enum HPluginDataTypes type, uint32 pluginID, struct hplugin_data_store *store, uint32 classid);
/* 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 cbda0e91b..73d4510a1 100644
--- a/src/common/mmo.h
+++ b/src/common/mmo.h
@@ -661,9 +661,7 @@ struct guild {
unsigned short instances;
struct channel_data *channel;
-
- /* HPM Custom Struct */
- struct hplugin_data_store *hdata;
+ struct hplugin_data_store *hdata; ///< HPM Plugin Data Store
};
struct guild_castle {
diff --git a/src/common/socket.c b/src/common/socket.c
index 842f9ba87..a26873b67 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -637,8 +637,7 @@ static void delete_session(int fd)
aFree(sockt->session[fd]->wdata);
if( sockt->session[fd]->session_data )
aFree(sockt->session[fd]->session_data);
- HPM->data_store_destroy(sockt->session[fd]->hdata);
- sockt->session[fd]->hdata = NULL;
+ HPM->data_store_destroy(&sockt->session[fd]->hdata);
aFree(sockt->session[fd]);
sockt->session[fd] = NULL;
}
diff --git a/src/common/socket.h b/src/common/socket.h
index 510eac575..a2dea8b74 100644
--- a/src/common/socket.h
+++ b/src/common/socket.h
@@ -104,8 +104,7 @@ struct socket_data {
ParseFunc func_parse;
void* session_data; // stores application-specific data related to the session
-
- struct hplugin_data_store *hdata;
+ struct hplugin_data_store *hdata; ///< HPM Plugin Data Store.
};
struct hSockOpt {