summaryrefslogtreecommitdiff
path: root/src/map/HPMmap.c
diff options
context:
space:
mode:
authorshennetsind <ind@henn.et>2014-02-02 15:02:14 -0200
committershennetsind <ind@henn.et>2014-02-02 15:02:14 -0200
commitd33469689ea8e671fa0d525d54bce6932dfe9107 (patch)
treef6fc609df3a6d723f6390a69c8e8174e6a242b72 /src/map/HPMmap.c
parent8a05e611a71168cccac282777aa1719a46f574d0 (diff)
downloadhercules-d33469689ea8e671fa0d525d54bce6932dfe9107.tar.gz
hercules-d33469689ea8e671fa0d525d54bce6932dfe9107.tar.bz2
hercules-d33469689ea8e671fa0d525d54bce6932dfe9107.tar.xz
hercules-d33469689ea8e671fa0d525d54bce6932dfe9107.zip
Introducing HPM Datacheck
http://hercules.ws/board/topic/4283-introducing-hpm-datacheck/ Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src/map/HPMmap.c')
-rw-r--r--src/map/HPMmap.c71
1 files changed, 59 insertions, 12 deletions
diff --git a/src/map/HPMmap.c b/src/map/HPMmap.c
index 4b1338b8d..1688f37ce 100644
--- a/src/map/HPMmap.c
+++ b/src/map/HPMmap.c
@@ -34,6 +34,8 @@
#include <string.h>
#include <time.h>
+#include "../plugins/HPMDataCheck.h"
+
struct HPM_atcommand_list {
//tracking currently not enabled
// - requires modifying how plugins calls atcommand creation
@@ -46,6 +48,11 @@ struct HPM_atcommand_list {
struct HPM_atcommand_list *atcommand_list = NULL;
unsigned int atcommand_list_items = 0;
+/**
+ * (char*) data name -> (unsigned int) HPMDataCheck[] index
+ **/
+DBMap *datacheck_db;
+
bool HPM_map_grabHPData(struct HPDataOperationStorage *ret, enum HPluginDataTypes type, void *ptr) {
/* record address */
switch( type ) {
@@ -113,20 +120,28 @@ void HPM_map_atcommands(void) {
}
}
-void HPM_map_do_final(void) {
- unsigned char i;
+/**
+ * Called by HPM->DataCheck on a plugins incoming data, ensures data structs in use are matching!
+ **/
+bool HPM_map_DataCheck (struct s_HPMDataCheck *src, unsigned int size, char *name) {
+ unsigned int i, j;
- if( atcommand_list )
- aFree(atcommand_list);
- /**
- * why is pcg->HPM being cleared here? because PCG's do_final is not final,
- * is used on reload, and would thus cause plugin-provided permissions to go away
- **/
- for( i = 0; i < pcg->HPMpermissions_count; i++ ) {
- aFree(pcg->HPMpermissions[i].name);
+ for(i = 0; i < size; i++) {
+
+ if( !strdb_exists(datacheck_db, src[i].name) ) {
+ ShowError("HPMDataCheck:%s: '%s' was not found\n",name,src[i].name);
+ return false;
+ } else {
+ j = strdb_uiget(datacheck_db, src[i].name);/* not double lookup; exists sets cache to found data */
+ ShowDebug("Testing[%s/%s] %u vs %u\n",src[i].name,HPMDataCheck[j].name,src[i].size,HPMDataCheck[j].size);
+ if( src[i].size != HPMDataCheck[j].size ) {
+ ShowWarning("HPMDataCheck:%s: '%s' size mismatch %u != %u\n",name,src[i].name,src[i].size,HPMDataCheck[j].size);
+ return false;
+ }
+ }
}
- if( pcg->HPMpermissions )
- aFree(pcg->HPMpermissions);
+
+ return true;
}
/**
@@ -141,3 +156,35 @@ void HPM_map_add_group_permission(unsigned int pluginID, char *name, unsigned in
pcg->HPMpermissions[index].name = aStrdup(name);
pcg->HPMpermissions[index].mask = mask;
}
+
+void HPM_map_do_init(void) {
+ unsigned int i;
+
+ /**
+ * Populates datacheck_db for easy lookup later on
+ **/
+ datacheck_db = strdb_alloc(DB_OPT_BASE,0);
+
+ for(i = 0; i < HPMDataCheckLen; i++) {
+ strdb_uiput(datacheck_db, HPMDataCheck[i].name, i);
+ }
+
+}
+
+void HPM_map_do_final(void) {
+ unsigned char i;
+
+ if( atcommand_list )
+ aFree(atcommand_list);
+ /**
+ * why is pcg->HPM being cleared here? because PCG's do_final is not final,
+ * is used on reload, and would thus cause plugin-provided permissions to go away
+ **/
+ for( i = 0; i < pcg->HPMpermissions_count; i++ ) {
+ aFree(pcg->HPMpermissions[i].name);
+ }
+ if( pcg->HPMpermissions )
+ aFree(pcg->HPMpermissions);
+
+ db_destroy(datacheck_db);
+}