diff options
-rw-r--r-- | src/map/HPMmap.c | 51 | ||||
-rw-r--r-- | src/map/HPMmap.h | 6 | ||||
-rw-r--r-- | src/map/atcommand.c | 55 | ||||
-rw-r--r-- | src/map/atcommand.h | 1 | ||||
-rw-r--r-- | src/map/map.c | 2 |
5 files changed, 87 insertions, 28 deletions
diff --git a/src/map/HPMmap.c b/src/map/HPMmap.c index 3ba9ae725..ca4a7a2e8 100644 --- a/src/map/HPMmap.c +++ b/src/map/HPMmap.c @@ -11,6 +11,7 @@ #include "map.h" // +#include "atcommand.h" #include "chat.h" #include "chrif.h" #include "duel.h" @@ -33,6 +34,18 @@ #include <string.h> #include <time.h> +struct HPM_atcommand_list { + //tracking currently not enabled + // - requires modifying how plugins calls atcommand creation + // - needs load/unload during runtime support + //unsigned int pID;/* plugin id */ + char name[ATCOMMAND_LENGTH]; + AtCommandFunc func; +}; + +struct HPM_atcommand_list *atcommand_list = NULL; +unsigned int atcommand_list_items = 0; + void HPM_map_addToMSD(struct map_session_data *sd, void *data, unsigned int id, unsigned int type, bool autofree) { struct HPluginData *HPData; unsigned int i; @@ -103,4 +116,40 @@ void HPM_map_plugin_load_sub(struct hplugin *plugin) { plugin->hpi->addToMSD = HPM->import_symbol("addToMSD",plugin->idx); plugin->hpi->getFromMSD = HPM->import_symbol("getFromMSD",plugin->idx); plugin->hpi->removeFromMSD = HPM->import_symbol("removeFromMSD",plugin->idx); -}
\ No newline at end of file +} + +bool HPM_map_add_atcommand(char *name, AtCommandFunc func) { + unsigned int i = 0; + + for(i = 0; i < atcommand_list_items; i++) { + if( !strcmpi(atcommand_list[i].name,name) ) { + ShowDebug("HPM_map_add_atcommand: duplicate command '%s', skipping...\n", name); + return false; + } + } + + i = atcommand_list_items; + + RECREATE(atcommand_list, struct HPM_atcommand_list , ++atcommand_list_items); + + safestrncpy(atcommand_list[i].name, name, sizeof(atcommand_list[i].name)); + atcommand_list[i].func = func; + + return true; +} + +void HPM_map_atcommands(void) { + unsigned int i; + + for(i = 0; i < atcommand_list_items; i++) { + if( !atcommand->add(atcommand_list[i].name,atcommand_list[i].func) ) { + ShowDebug("HPM_map_atcommands: duplicate command '%s', skipping...\n", atcommand_list[i].name); + continue; + } + } +} + +void HPM_map_do_final(void) { + if( atcommand_list ) + aFree(atcommand_list); +} diff --git a/src/map/HPMmap.h b/src/map/HPMmap.h index a6cac4ace..96515772b 100644 --- a/src/map/HPMmap.h +++ b/src/map/HPMmap.h @@ -5,6 +5,7 @@ #define _HPM_MAP_ #include "../common/cbasetypes.h" +#include "../map/atcommand.h" struct hplugin; struct map_session_data; @@ -13,6 +14,11 @@ void HPM_map_addToMSD(struct map_session_data *sd, void *data, unsigned int id, void *HPM_map_getFromMSD(struct map_session_data *sd, unsigned int id, unsigned int type); void HPM_map_removeFromMSD(struct map_session_data *sd, unsigned int id, unsigned int type); +bool HPM_map_add_atcommand(char *name, AtCommandFunc func); +void HPM_map_atcommands(void); + void HPM_map_plugin_load_sub(struct hplugin *plugin); +void HPM_map_do_final(void); + #endif /* _HPM_MAP_ */ diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 0fe0aabb5..19128083d 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -45,6 +45,7 @@ #include "mapreg.h" #include "quest.h" #include "searchstore.h" +#include "HPMmap.h" #include <stdio.h> #include <stdlib.h> @@ -9445,24 +9446,39 @@ void atcommand_basecommands(void) { ACMD_DEF(costume), ACMD_DEF(skdebug), }; - AtCommandInfo* cmd; int i; for( i = 0; i < ARRAYLENGTH(atcommand_base); i++ ) { - if(atcommand->exists(atcommand_base[i].command)) { // Should not happen if atcommand_base[] array is OK + if(!atcommand->add(atcommand_base[i].command,atcommand_base[i].func)) { // Should not happen if atcommand_base[] array is OK ShowDebug("atcommand_basecommands: duplicate ACMD_DEF for '%s'.\n", atcommand_base[i].command); continue; } - CREATE(cmd, AtCommandInfo, 1); - safestrncpy(cmd->command, atcommand_base[i].command, sizeof(cmd->command)); - cmd->func = atcommand_base[i].func; - cmd->help = NULL;/* start as null dear */ - cmd->log = true; - strdb_put(atcommand->db, cmd->command, cmd); } + + /* @commands from plugins */ + HPM_map_atcommands(); + return; } +bool atcommand_add(char *name,AtCommandFunc func) { + AtCommandInfo* cmd; + + if(atcommand->exists(name)) //caller will handle/display on false + return false; + + CREATE(cmd, AtCommandInfo, 1); + + safestrncpy(cmd->command, name, sizeof(cmd->command)); + cmd->func = func; + cmd->help = NULL; + cmd->log = true; + + strdb_put(atcommand->db, cmd->command, cmd); + + return true; +} + /*========================================== * Command lookup functions *------------------------------------------*/ @@ -9971,30 +9987,14 @@ bool atcommand_can_use2(struct map_session_data *sd, const char *command, AtComm return false; } bool atcommand_hp_add(char *name, AtCommandFunc func) { - AtCommandInfo* cmd; - + /* if commands are added after group permissions are thrown in, they end up with no permissions */ + /* so we restrict commands to be linked in during boot */ if( runflag == MAPSERVER_ST_RUNNING ) { ShowDebug("atcommand_hp_add: Commands can't be added after server is ready, skipping '%s'...\n",name); return false; } - if( atcommand->db == NULL ) - atcommand->db = stridb_alloc(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA, ATCOMMAND_LENGTH); - - if( atcommand->exists(name) ) { - ShowDebug("atcommand_hp_add: duplicate command '%s', skipping...\n", name); - return false; - } - - CREATE(cmd, AtCommandInfo, 1); - - safestrncpy(cmd->command, name, sizeof(cmd->command)); - cmd->func = func; - cmd->help = NULL;/* start as null dear */ - cmd->log = true; - - strdb_put(atcommand->db, cmd->command, cmd); - return true; + return HPM_map_add_atcommand(name,func); } /** @@ -10080,4 +10080,5 @@ void atcommand_defaults(void) { atcommand->cmd_db_clear_sub = atcommand_db_clear_sub; atcommand->doload = atcommand_doload; atcommand->base_commands = atcommand_basecommands; + atcommand->add = atcommand_add; } diff --git a/src/map/atcommand.h b/src/map/atcommand.h index 603abc0cc..63c38e4d1 100644 --- a/src/map/atcommand.h +++ b/src/map/atcommand.h @@ -110,6 +110,7 @@ struct atcommand_interface { int (*cmd_db_clear_sub) (DBKey key, DBData *data, va_list args); void (*doload) (void); void (*base_commands) (void); + bool (*add) (char *name, AtCommandFunc func); }; struct atcommand_interface *atcommand; diff --git a/src/map/map.c b/src/map/map.c index 91871e58f..749b9de81 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -5087,6 +5087,8 @@ void do_final(void) map->list_final(); vending->final(); + HPM_map_do_final(); + map->map_db->destroy(map->map_db, map->db_final); mapindex_final(); |