diff options
author | shennetsind <shennetsind@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2012-07-23 19:26:50 +0000 |
---|---|---|
committer | shennetsind <shennetsind@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2012-07-23 19:26:50 +0000 |
commit | 98e833dc83ad9f0642bdbf6b90b239704292f15f (patch) | |
tree | 73194653b1a88d67d8608d9caaac7f5119a56c6d /src/map/atcommand.c | |
parent | 81bfbbfb9c0f5af32e55f66ccea2d444eb76cabc (diff) | |
download | hercules-98e833dc83ad9f0642bdbf6b90b239704292f15f.tar.gz hercules-98e833dc83ad9f0642bdbf6b90b239704292f15f.tar.bz2 hercules-98e833dc83ad9f0642bdbf6b90b239704292f15f.tar.xz hercules-98e833dc83ad9f0642bdbf6b90b239704292f15f.zip |
Follow up r16471 improved overall feature performance by making the bind list a pointer array, this also allows the system to have a unlimited amount of atcommand bind instances. also fixed a memory leak that'd be caused when npc_do_atcmd_event fails (e.g. when target npc is manually reloaded)
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@16485 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map/atcommand.c')
-rw-r--r-- | src/map/atcommand.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 15f75d55a..6eeb5ec9f 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -57,6 +57,8 @@ typedef struct AtCommandInfo AtCommandInfo; typedef struct AliasInfo AliasInfo; +int atcmd_binding_count = 0; + struct AtCommandInfo { char command[ATCOMMAND_LENGTH]; AtCommandFunc func; @@ -86,14 +88,15 @@ static const char* atcommand_checkalias(const char *aliasname); // @help static void atcommand_get_suggestions(struct map_session_data* sd, const char *name, bool atcommand); // @help // @commands (script-based) -struct Atcmd_Binding* get_atcommandbind_byname(const char* name) -{ +struct atcmd_binding_data* get_atcommandbind_byname(const char* name) { int i = 0; + if( *name == atcommand_symbol || *name == charcommand_symbol ) name++; // for backwards compatibility - ARR_FIND( 0, ARRAYLENGTH(atcmd_binding), i, strcmp(atcmd_binding[i].command, name) == 0 ); - return ( i < ARRAYLENGTH(atcmd_binding) ) ? &atcmd_binding[i] : NULL; - return NULL; + + ARR_FIND( 0, atcmd_binding_count, i, strcmp(atcmd_binding[i]->command, name) == 0 ); + + return ( i < atcmd_binding_count ) ? atcmd_binding[i] : NULL; } //----------------------------------------------------------- @@ -8998,9 +9001,6 @@ bool is_atcommand(const int fd, struct map_session_data* sd, const char* message TBL_PC * ssd = NULL; //sd for target AtCommandInfo * info; - // @commands (script based) - Atcmd_Binding * binding; - nullpo_retr(false, sd); //Shouldn't happen @@ -9079,11 +9079,12 @@ bool is_atcommand(const int fd, struct map_session_data* sd, const char* message params[0] = '\0'; // @commands (script based) - if(type == 1) { + if(type == 1 && atcmd_binding_count > 0) { + struct atcmd_binding_data * binding; + // Check if the command initiated is a character command if (*message == charcommand_symbol && - (ssd = map_nick2sd(charname)) == NULL && (ssd = map_nick2sd(charname2)) == NULL ) - { + (ssd = map_nick2sd(charname)) == NULL && (ssd = map_nick2sd(charname2)) == NULL ) { sprintf(output, "%s failed. Player not found.", command); clif_displaymessage(fd, output); return true; |