Skip to content

Commit 778facb

Browse files
committed
Modified @command loading
So that HPM plugins are able to override default commands, thanks to Akkarin for bringing it up. Signed-off-by: shennetsind <[email protected]>
1 parent 4d86097 commit 778facb

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

src/map/HPMmap.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,7 @@ void HPM_map_atcommands(void) {
142142
unsigned int i;
143143

144144
for(i = 0; i < atcommand_list_items; i++) {
145-
if( !atcommand->add(atcommand_list[i].name,atcommand_list[i].func) ) {
146-
ShowDebug("HPM_map_atcommands: duplicate command '%s', skipping...\n", atcommand_list[i].name);
147-
continue;
148-
}
145+
atcommand->add(atcommand_list[i].name,atcommand_list[i].func,true);
149146
}
150147
}
151148

src/map/atcommand.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9564,7 +9564,7 @@ void atcommand_basecommands(void) {
95649564
int i;
95659565

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

9579-
bool atcommand_add(char *name,AtCommandFunc func) {
9579+
bool atcommand_add(char *name,AtCommandFunc func, bool replace) {
95809580
AtCommandInfo* cmd;
95819581

9582-
if(atcommand->exists(name)) //caller will handle/display on false
9583-
return false;
9584-
9585-
CREATE(cmd, AtCommandInfo, 1);
9582+
if( (cmd = atcommand->exists(name)) ) { //caller will handle/display on false
9583+
if( !replace )
9584+
return false;
9585+
} else {
9586+
CREATE(cmd, AtCommandInfo, 1);
9587+
strdb_put(atcommand->db, name, cmd);
9588+
}
95869589

95879590
safestrncpy(cmd->command, name, sizeof(cmd->command));
95889591
cmd->func = func;
95899592
cmd->help = NULL;
95909593
cmd->log = true;
9591-
9592-
strdb_put(atcommand->db, cmd->command, cmd);
9593-
9594+
95949595
return true;
95959596
}
95969597

src/map/atcommand.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ struct atcommand_interface {
110110
int (*cmd_db_clear_sub) (DBKey key, DBData *data, va_list args);
111111
void (*doload) (void);
112112
void (*base_commands) (void);
113-
bool (*add) (char *name, AtCommandFunc func);
113+
bool (*add) (char *name, AtCommandFunc func, bool replace);
114114
};
115115

116116
struct atcommand_interface *atcommand;

0 commit comments

Comments
 (0)