Skip to content

Commit

Permalink
Modified @command loading
Browse files Browse the repository at this point in the history
So that HPM plugins are able to override default commands, thanks to Akkarin for bringing it up.

Signed-off-by: shennetsind <ind@henn.et>
  • Loading branch information
shennetsind committed Nov 6, 2013
1 parent 4d86097 commit 778facb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
5 changes: 1 addition & 4 deletions src/map/HPMmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,7 @@ 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;
}
atcommand->add(atcommand_list[i].name,atcommand_list[i].func,true);
}
}

Expand Down
19 changes: 10 additions & 9 deletions src/map/atcommand.c
Original file line number Diff line number Diff line change
Expand Up @@ -9564,7 +9564,7 @@ void atcommand_basecommands(void) {
int i;

for( i = 0; i < ARRAYLENGTH(atcommand_base); i++ ) {
if(!atcommand->add(atcommand_base[i].command,atcommand_base[i].func)) { // Should not happen if atcommand_base[] array is OK
if(!atcommand->add(atcommand_base[i].command,atcommand_base[i].func,false)) { // Should not happen if atcommand_base[] array is OK
ShowDebug("atcommand_basecommands: duplicate ACMD_DEF for '%s'.\n", atcommand_base[i].command);
continue;
}
Expand All @@ -9576,21 +9576,22 @@ void atcommand_basecommands(void) {
return;
}

bool atcommand_add(char *name,AtCommandFunc func) {
bool atcommand_add(char *name,AtCommandFunc func, bool replace) {
AtCommandInfo* cmd;

if(atcommand->exists(name)) //caller will handle/display on false
return false;

CREATE(cmd, AtCommandInfo, 1);
if( (cmd = atcommand->exists(name)) ) { //caller will handle/display on false
if( !replace )
return false;
} else {
CREATE(cmd, AtCommandInfo, 1);
strdb_put(atcommand->db, name, cmd);
}

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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/map/atcommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +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);
bool (*add) (char *name, AtCommandFunc func, bool replace);
};

struct atcommand_interface *atcommand;
Expand Down

0 comments on commit 778facb

Please sign in to comment.