summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2015-09-17 01:21:28 +0200
committerHaru <haru@dotalux.com>2015-10-11 00:24:22 +0200
commit70265291d62280c525adc317158e9f531e0147ff (patch)
tree8beae9d0edc99a38bc678b86f2709780314ad327 /src/map
parent502703d2b632125b35a2b8d341a90a13d7445f02 (diff)
downloadhercules-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/map')
-rw-r--r--src/map/HPMmap.c54
-rw-r--r--src/map/HPMmap.h2
-rw-r--r--src/map/battleground.c15
-rw-r--r--src/map/battleground.h5
-rw-r--r--src/map/guild.c25
-rw-r--r--src/map/instance.c13
-rw-r--r--src/map/instance.h5
-rw-r--r--src/map/itemdb.c13
-rw-r--r--src/map/itemdb.h4
-rw-r--r--src/map/map.c12
-rw-r--r--src/map/map.h4
-rw-r--r--src/map/mob.c12
-rw-r--r--src/map/mob.h9
-rw-r--r--src/map/npc.c12
-rw-r--r--src/map/npc.h5
-rw-r--r--src/map/party.c25
-rw-r--r--src/map/party.h5
-rw-r--r--src/map/pc.c22
-rw-r--r--src/map/pc.h6
-rw-r--r--src/map/unit.c27
20 files changed, 66 insertions, 209 deletions
diff --git a/src/map/HPMmap.c b/src/map/HPMmap.c
index ac78e8c84..ddffb5519 100644
--- a/src/map/HPMmap.c
+++ b/src/map/HPMmap.c
@@ -85,57 +85,33 @@ struct HPM_atcommand_list {
struct HPM_atcommand_list *atcommand_list = NULL;
unsigned int atcommand_list_items = 0;
-bool HPM_map_grabHPData(struct HPDataOperationStorage *ret, enum HPluginDataTypes type, void *ptr) {
- /* record address */
- switch( type ) {
+/**
+ * HPM plugin data store validator sub-handler (map-server)
+ *
+ * @see HPM_interface::data_store_validate
+ */
+bool HPM_map_data_store_validate(enum HPluginDataTypes type, struct hplugin_data_store **store)
+{
+ switch (type) {
case HPDT_MSD:
- ret->HPDataSRCPtr = (void**)(&((struct map_session_data *)ptr)->hdata);
- ret->hdatac = &((struct map_session_data *)ptr)->hdatac;
- break;
case HPDT_NPCD:
- 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;
case HPDT_MOBDB:
- ret->HPDataSRCPtr = (void**)(&((struct mob_db *)ptr)->hdata);
- ret->hdatac = &((struct mob_db *)ptr)->hdatac;
- break;
case HPDT_MOBDATA:
- ret->HPDataSRCPtr = (void**)(&((struct mob_data *)ptr)->hdata);
- ret->hdatac = &((struct mob_data *)ptr)->hdatac;
- break;
case HPDT_ITEMDATA:
- ret->HPDataSRCPtr = (void**)(&((struct item_data *)ptr)->hdata);
- ret->hdatac = &((struct item_data *)ptr)->hdatac;
- break;
case HPDT_BGDATA:
- ret->HPDataSRCPtr = (void**)(&((struct battleground_data *)ptr)->hdata);
- ret->hdatac = &((struct battleground_data *)ptr)->hdatac;
- break;
case HPDT_AUTOTRADE_VEND:
- ret->HPDataSRCPtr = (void**)(&((struct autotrade_vending *)ptr)->hdata);
- ret->hdatac = &((struct autotrade_vending *)ptr)->hdatac;
- break;
+ if (!*store) {
+ *store = HPM->data_store_create();
+ }
+ return true;
default:
- return false;
+ break;
}
- return true;
+ return false;
}
void HPM_map_plugin_load_sub(struct hplugin *plugin) {
@@ -188,7 +164,7 @@ void HPM_map_add_group_permission(unsigned int pluginID, char *name, unsigned in
void HPM_map_do_init(void) {
HPM->load_sub = HPM_map_plugin_load_sub;
- HPM->grabHPDataSub = HPM_map_grabHPData;
+ HPM->data_store_validate_sub = HPM_map_data_store_validate;
HPM->datacheck_init(HPMDataCheck, HPMDataCheckLen, HPMDataCheckVer);
HPM_shared_symbols(SERVER_TYPE_MAP);
}
diff --git a/src/map/HPMmap.h b/src/map/HPMmap.h
index 00a8f43c3..10bdf0ba7 100644
--- a/src/map/HPMmap.h
+++ b/src/map/HPMmap.h
@@ -15,7 +15,7 @@
struct hplugin;
struct map_session_data;
-bool HPM_map_grabHPData(struct HPDataOperationStorage *ret, enum HPluginDataTypes type, void *ptr);
+bool HPM_map_data_store_validate(enum HPluginDataTypes type, struct hplugin_data_store **store);
bool HPM_map_add_atcommand(char *name, AtCommandFunc func);
void HPM_map_atcommands(void);
diff --git a/src/map/battleground.c b/src/map/battleground.c
index 5df05d301..46d695272 100644
--- a/src/map/battleground.c
+++ b/src/map/battleground.c
@@ -880,17 +880,10 @@ void do_init_battleground(bool minimal) {
*/
int bg_team_db_final(DBKey key, DBData *data, va_list ap) {
struct battleground_data* bgd = DB->data2ptr(data);
- int i;
- nullpo_ret(bgd);
- for(i = 0; i < bgd->hdatac; i++ ) {
- if( bgd->hdata[i]->flag.free ) {
- aFree(bgd->hdata[i]->data);
- }
- aFree(bgd->hdata[i]);
- }
- if( bgd->hdata )
- aFree(bgd->hdata);
-
+
+ HPM->data_store_destroy(bgd->hdata);
+ bgd->hdata = NULL;
+
return 0;
}
diff --git a/src/map/battleground.h b/src/map/battleground.h
index 094037f43..0280407a2 100644
--- a/src/map/battleground.h
+++ b/src/map/battleground.h
@@ -10,7 +10,7 @@
#include "common/db.h"
#include "common/mmo.h" // struct party
-struct HPluginData;
+struct hplugin_data_store;
struct block_list;
struct map_session_data;
@@ -54,8 +54,7 @@ struct battleground_data {
char logout_event[EVENT_NAME_LENGTH];
char die_event[EVENT_NAME_LENGTH];
/* HPM Custom Struct */
- struct HPluginData **hdata;
- unsigned int hdatac;
+ struct hplugin_data_store *hdata;
};
struct bg_arena {
diff --git a/src/map/guild.c b/src/map/guild.c
index 7a187b625..2dca97502 100644
--- a/src/map/guild.c
+++ b/src/map/guild.c
@@ -1763,16 +1763,8 @@ int guild_broken(int guild_id,int flag)
if( g->instance )
aFree(g->instance);
- if( g->hdata )
- {
- for( i = 0; i < g->hdatac; i++ ) {
- if( g->hdata[i]->flag.free ) {
- aFree(g->hdata[i]->data);
- }
- aFree(g->hdata[i]);
- }
- aFree(g->hdata);
- }
+ HPM->data_store_destroy(g->hdata);
+ g->hdata = NULL;
idb_remove(guild->db,guild_id);
return 0;
@@ -2250,7 +2242,6 @@ 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 )
@@ -2259,16 +2250,8 @@ void do_final_guild(void) {
aFree(g->instance);
g->instance = NULL;
}
- if( g->hdata )
- {
- for( i = 0; i < g->hdatac; i++ ) {
- if( g->hdata[i]->flag.free ) {
- aFree(g->hdata[i]->data);
- }
- aFree(g->hdata[i]);
- }
- aFree(g->hdata);
- }
+ HPM->data_store_destroy(g->hdata);
+ g->hdata = NULL;
}
dbi_destroy(iter);
diff --git a/src/map/instance.c b/src/map/instance.c
index 300247fe7..7213c43a1 100644
--- a/src/map/instance.c
+++ b/src/map/instance.c
@@ -588,19 +588,8 @@ void instance_destroy(int instance_id) {
instance->list[instance_id].state = INSTANCE_FREE;
instance->list[instance_id].num_map = 0;
- if (instance->list[instance_id].hdata)
- {
- 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]);
- }
- aFree(instance->list[instance_id].hdata);
- }
-
+ HPM->data_store_destroy(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 589e1a511..f879195ef 100644
--- a/src/map/instance.h
+++ b/src/map/instance.h
@@ -9,7 +9,7 @@
#include "common/hercules.h"
#include "common/mmo.h" // struct point
-struct HPluginData;
+struct hplugin_data_store;
struct block_list;
struct map_session_data;
@@ -54,8 +54,7 @@ struct instance_data {
struct point respawn; ///< reload spawn
/** HPM Custom Struct */
- struct HPluginData **hdata;
- unsigned int hdatac;
+ struct hplugin_data_store *hdata;
};
struct instance_interface {
diff --git a/src/map/itemdb.c b/src/map/itemdb.c
index ccedee72a..c531a4d7a 100644
--- a/src/map/itemdb.c
+++ b/src/map/itemdb.c
@@ -2100,17 +2100,8 @@ void destroy_item_data(struct item_data* self, int free_self)
script->free_code(self->unequip_script);
if( self->combos )
aFree(self->combos);
- if (self->hdata)
- {
- int i;
- for (i = 0; i < self->hdatac; i++ ) {
- if (self->hdata[i]->flag.free ) {
- aFree(self->hdata[i]->data);
- }
- aFree(self->hdata[i]);
- }
- aFree(self->hdata);
- }
+ HPM->data_store_destroy(self->hdata);
+ self->hdata = NULL;
#if defined(DEBUG)
// trash item
memset(self, 0xDD, sizeof(struct item_data));
diff --git a/src/map/itemdb.h b/src/map/itemdb.h
index a3edd451e..de9770aab 100644
--- a/src/map/itemdb.h
+++ b/src/map/itemdb.h
@@ -13,6 +13,7 @@
#include "common/sql.h"
struct script_code;
+struct hplugin_data_store;
/**
* Defines
@@ -490,8 +491,7 @@ struct item_data {
struct item_package *package;
/* HPM Custom Struct */
- struct HPluginData **hdata;
- unsigned int hdatac;
+ struct hplugin_data_store *hdata;
};
#define itemdb_name(n) (itemdb->search(n)->name)
diff --git a/src/map/map.c b/src/map/map.c
index e01a25366..0ed7072d2 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -3239,16 +3239,8 @@ void do_final_maps(void) {
if( map->list[i].qi_data )
aFree(map->list[i].qi_data);
- if( map->list[i].hdata )
- {
- 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]);
- }
- aFree(map->list[i].hdata);
- }
+ HPM->data_store_destroy(map->list[i].hdata);
+ map->list[i].hdata = NULL;
}
map->zone_db_clear();
diff --git a/src/map/map.h b/src/map/map.h
index 3ac39e54f..c3e426bb6 100644
--- a/src/map/map.h
+++ b/src/map/map.h
@@ -19,6 +19,7 @@
struct mob_data;
struct npc_data;
struct channel_data;
+struct hplugin_data_store;
enum E_MAPSERVER_ST {
MAPSERVER_ST_RUNNING = CORE_ST_LAST,
@@ -738,8 +739,7 @@ struct map_data {
unsigned short hpmeter_visible;
/* HPM Custom Struct */
- struct HPluginData **hdata;
- unsigned int hdatac;
+ struct hplugin_data_store *hdata;
};
/// Stores information about a remote map (for multi-mapserver setups).
diff --git a/src/map/mob.c b/src/map/mob.c
index 2fe9fe8fb..174d2e49f 100644
--- a/src/map/mob.c
+++ b/src/map/mob.c
@@ -4708,16 +4708,8 @@ int do_init_mob(bool minimal) {
void mob_destroy_mob_db(int index)
{
struct mob_db *data = mob->db_data[index];
- if (data->hdata) {
- int i;
- for (i = 0; i < data->hdatac; i++) {
- if (data->hdata[i]->flag.free ) {
- aFree(data->hdata[i]->data);
- }
- aFree(data->hdata[i]);
- }
- aFree(data->hdata);
- }
+ HPM->data_store_destroy(data->hdata);
+ data->hdata = NULL;
aFree(data);
mob->db_data[index] = NULL;
}
diff --git a/src/map/mob.h b/src/map/mob.h
index 4b8a054b5..1142502f4 100644
--- a/src/map/mob.h
+++ b/src/map/mob.h
@@ -11,6 +11,8 @@
#include "common/hercules.h"
#include "common/mmo.h" // struct item
+struct hplugin_data_store;
+
#define MAX_RANDOMMONSTER 5
// Change this to increase the table size in your mob_db to accommodate a larger mob database.
@@ -140,8 +142,7 @@ struct mob_db {
struct spawn_info spawn[10];
/* HPM Custom Struct */
- struct HPluginData **hdata;
- unsigned int hdatac;
+ struct hplugin_data_store *hdata;
};
struct mob_data {
@@ -210,12 +211,10 @@ struct mob_data {
int tomb_nid;
/* HPM Custom Struct */
- struct HPluginData **hdata;
- unsigned int hdatac;
+ struct hplugin_data_store *hdata;
};
-
enum {
MST_TARGET = 0,
MST_RANDOM, //Random Target!
diff --git a/src/map/npc.c b/src/map/npc.c
index a0c14a058..85de5301b 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -2321,16 +2321,8 @@ int npc_unload(struct npc_data* nd, bool single)
nd->ud = NULL;
}
- if (nd->hdata) {
- unsigned int i;
- for (i = 0; i < nd->hdatac; i++) {
- if (nd->hdata[i]->flag.free) {
- aFree(nd->hdata[i]->data);
- }
- aFree(nd->hdata[i]);
- }
- aFree(nd->hdata);
- }
+ HPM->data_store_destroy(nd->hdata);
+ nd->hdata = NULL;
aFree(nd);
diff --git a/src/map/npc.h b/src/map/npc.h
index 14b89d128..06aee3f93 100644
--- a/src/map/npc.h
+++ b/src/map/npc.h
@@ -11,7 +11,7 @@
#include "common/hercules.h"
#include "common/db.h"
-struct HPluginData;
+struct hplugin_data_store;
struct view_data;
enum npc_parse_options {
@@ -103,8 +103,7 @@ struct npc_data {
} tomb;
} u;
/* HPData Support for npc_data */
- struct HPluginData **hdata;
- unsigned int hdatac;
+ struct hplugin_data_store *hdata;
};
diff --git a/src/map/party.c b/src/map/party.c
index db285a4b4..4735dfc42 100644
--- a/src/map/party.c
+++ b/src/map/party.c
@@ -103,16 +103,8 @@ int party_db_final(DBKey key, DBData *data, va_list ap) {
if (p->instance)
aFree(p->instance);
- if (p->hdata) {
- int i;
- for (i = 0; i < p->hdatac; i++) {
- if (p->hdata[i]->flag.free) {
- aFree(p->hdata[i]->data);
- }
- aFree(p->hdata[i]);
- }
- aFree(p->hdata);
- }
+ HPM->data_store_destroy(p->hdata);
+ p->hdata = NULL;
}
return 0;
}
@@ -608,16 +600,9 @@ int party_broken(int party_id)
if( p->instance )
aFree(p->instance);
- if( p->hdata )
- {
- for( j = 0; j < p->hdatac; j++ ) {
- if( p->hdata[j]->flag.free ) {
- aFree(p->hdata[j]->data);
- }
- aFree(p->hdata[j]);
- }
- aFree(p->hdata);
- }
+ HPM->data_store_destroy(p->hdata);
+ p->hdata = NULL;
+
idb_remove(party->db,party_id);
return 0;
}
diff --git a/src/map/party.h b/src/map/party.h
index c7893add2..960e6da08 100644
--- a/src/map/party.h
+++ b/src/map/party.h
@@ -15,7 +15,7 @@
#define PARTY_BOOKING_JOBS 6
#define PARTY_BOOKING_RESULTS 10
-struct HPluginData;
+struct hplugin_data_store;
struct party_member_data {
struct map_session_data *sd;
@@ -37,8 +37,7 @@ struct party_data {
} state;
/* HPM Custom Struct */
- struct HPluginData **hdata;
- unsigned int hdatac;
+ struct hplugin_data_store *hdata;
};
#define PB_NOTICE_LENGTH (36 + 1)
diff --git a/src/map/pc.c b/src/map/pc.c
index dc7014701..fee41deff 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -11332,14 +11332,8 @@ void pc_autotrade_populate(struct map_session_data *sd) {
pc->autotrade_update(sd,PAUC_START);
- for(i = 0; i < data->hdatac; i++ ) {
- if( data->hdata[i]->flag.free ) {
- aFree(data->hdata[i]->data);
- }
- aFree(data->hdata[i]);
- }
- if( data->hdata )
- aFree(data->hdata);
+ HPM->data_store_destroy(data->hdata);
+ data->hdata = NULL;
idb_remove(pc->at_db, sd->status.char_id);
}
@@ -11349,16 +11343,8 @@ void pc_autotrade_populate(struct map_session_data *sd) {
*/
int pc_autotrade_final(DBKey key, DBData *data, va_list ap) {
struct autotrade_vending* at_v = DB->data2ptr(data);
- int i;
- for(i = 0; i < at_v->hdatac; i++ ) {
- if( at_v->hdata[i]->flag.free ) {
- aFree(at_v->hdata[i]->data);
- }
- aFree(at_v->hdata[i]);
- }
- if( at_v->hdata )
- aFree(at_v->hdata);
-
+ HPM->data_store_destroy(at_v->hdata);
+ at_v->hdata = NULL;
return 0;
}
diff --git a/src/map/pc.h b/src/map/pc.h
index e6e95978d..a74bc6c80 100644
--- a/src/map/pc.h
+++ b/src/map/pc.h
@@ -541,8 +541,7 @@ END_ZEROED_BLOCK;
unsigned char delayed_damage;//ref. counter bugreport:7307 [Ind/Hercules]
/* HPM Custom Struct */
- struct HPluginData **hdata;
- unsigned int hdatac;
+ struct hplugin_data_store *hdata;
/* expiration_time timer id */
int expiration_tid;
@@ -758,8 +757,7 @@ struct autotrade_vending {
struct s_vending vending[MAX_VENDING];
unsigned char vend_num;
/* HPM Custom Struct */
- struct HPluginData **hdata;
- unsigned int hdatac;
+ struct hplugin_data_store *hdata;
};
/*=====================================
diff --git a/src/map/unit.c b/src/map/unit.c
index 04a8befc2..0f8a9d7e6 100644
--- a/src/map/unit.c
+++ b/src/map/unit.c
@@ -2655,16 +2655,9 @@ int unit_free(struct block_list *bl, clr_type clrtype) {
sd->num_quests = sd->avail_quests = 0;
}
- if (sd->hdata) {
- unsigned int k;
- for( k = 0; k < sd->hdatac; k++ ) {
- if( sd->hdata[k]->flag.free ) {
- aFree(sd->hdata[k]->data);
- }
- aFree(sd->hdata[k]);
- }
- aFree(sd->hdata);
- }
+ HPM->data_store_destroy(sd->hdata);
+ sd->hdata = NULL;
+
break;
}
case BL_PET:
@@ -2775,17 +2768,9 @@ int unit_free(struct block_list *bl, clr_type clrtype) {
if( md->tomb_nid )
mob->mvptomb_destroy(md);
- if (md->hdata)
- {
- unsigned int k;
- for (k = 0; k < md->hdatac; k++) {
- if( md->hdata[k]->flag.free ) {
- aFree(md->hdata[k]->data);
- }
- aFree(md->hdata[k]);
- }
- aFree(md->hdata);
- }
+ HPM->data_store_destroy(md->hdata);
+ md->hdata = NULL;
+
break;
}
case BL_HOM: