diff --git a/include/h.h b/include/h.h index cc5c0cfbb..fdfb272b6 100644 --- a/include/h.h +++ b/include/h.h @@ -439,7 +439,7 @@ extern char *inetntop(int af, const void *in, char *local_dummy, size_t the_size */ extern MODVAR aCommand *CommandHash[256]; extern void init_CommandHash(void); -extern aCommand *add_Command_backend(char *cmd, int (*func)(), unsigned char parameters, int flags); +extern aCommand *add_Command_backend(char *cmd); extern void add_Command(char *cmd, int (*func)(), unsigned char parameters); extern void add_Command_to_list(aCommand *item, aCommand **list); extern aCommand *del_Command_from_list(aCommand *item, aCommand **list); diff --git a/include/modules.h b/include/modules.h index 8e6bbb407..1564de76c 100644 --- a/include/modules.h +++ b/include/modules.h @@ -711,7 +711,8 @@ extern Callback *CallbackDel(Callback *cb); extern Efunction *EfunctionAddMain(Module *module, int eftype, int (*intfunc)(), void (*voidfunc)(), void *(*pvoidfunc)(), char *(*pcharfunc)()); extern Efunction *EfunctionDel(Efunction *cb); -extern Command *CommandAdd(Module *module, char *cmd, int (*func)(aClient *cptr, aClient *sptr, int parc, char *parv[]), unsigned char params, int flags); +extern Command *CommandAdd(Module *module, char *cmd, CmdFunc func, unsigned char params, int flags); +extern Command *AliasAdd(Module *module, char *cmd, AliasCmdFunc aliasfunc, unsigned char params, int flags); extern void CommandDel(Command *command); extern int CommandExists(char *name); extern Cmdoverride *CmdoverrideAdd(Module *module, char *cmd, int (*func)(Cmdoverride *ovr, aClient *cptr, aClient *sptr, int parc, char *parv[])); diff --git a/include/struct.h b/include/struct.h index fb6ef096d..49ab55daf 100644 --- a/include/struct.h +++ b/include/struct.h @@ -797,6 +797,9 @@ typedef struct ircstatsx { extern MODVAR ircstats IRCstats; +typedef int (*CmdFunc)(aClient *cptr, aClient *sptr, int parc, char *parv[]); +typedef int (*AliasCmdFunc)(aClient *cptr, aClient *sptr, int parc, char *parv[], char *cmd); + #include "modules.h" extern MODVAR Umode *Usermode_Table; @@ -1713,7 +1716,8 @@ extern MODVAR char *gnulicense[]; struct Command { aCommand *prev, *next; char *cmd; - int (*func) (); + CmdFunc func; + AliasCmdFunc aliasfunc; int flags; unsigned int count; unsigned parameters : 5; diff --git a/src/api-command.c b/src/api-command.c index e95808707..cd51670ef 100644 --- a/src/api-command.c +++ b/src/api-command.c @@ -37,7 +37,7 @@ int CommandExists(char *name) return 0; } -Command *CommandAdd(Module *module, char *cmd, int (*func)(), unsigned char params, int flags) +Command *CommandAddInternal(Module *module, char *cmd, CmdFunc func, AliasCmdFunc aliasfunc, unsigned char params, int flags) { Command *command = NULL; aCommand *c; @@ -57,7 +57,11 @@ Command *CommandAdd(Module *module, char *cmd, int (*func)(), unsigned char para return NULL; } - c = add_Command_backend(cmd, func, params, flags); + c = add_Command_backend(cmd); + c->parameters = (params > MAXPARA) ? MAXPARA : params; + c->flags = flags; + c->func = func; + c->aliasfunc = aliasfunc; if (module) { @@ -82,6 +86,26 @@ Command *CommandAdd(Module *module, char *cmd, int (*func)(), unsigned char para return command; } +Command *CommandAdd(Module *module, char *cmd, CmdFunc func, unsigned char params, int flags) +{ + if (flags & M_ALIAS) + { + config_error("Command '%s' used CommandAdd() to add a command alias, " + "but should have used AliasAdd() instead. " + "Old 3rd party module %s? Check for updates!", + cmd, + module ? module->header->name : ""); + return NULL; + } + return CommandAddInternal(module, cmd, func, NULL, params, flags); +} + +Command *AliasAdd(Module *module, char *cmd, AliasCmdFunc aliasfunc, unsigned char params, int flags) +{ + if (!(flags & M_ALIAS)) + flags |= M_ALIAS; + return CommandAddInternal(module, cmd, NULL, aliasfunc, params, flags); +} void CommandDel(Command *command) { diff --git a/src/packet.c b/src/packet.c index 63f405c6f..dd6c87b3a 100644 --- a/src/packet.c +++ b/src/packet.c @@ -101,19 +101,16 @@ void init_CommandHash(void) #endif } -aCommand *add_Command_backend(char *cmd, int (*func)(), unsigned char parameters, int flags) +aCommand *add_Command_backend(char *cmd) { - aCommand *newcmd = MyMallocEx(sizeof(aCommand)); - - newcmd->cmd = (char *) strdup(cmd); - newcmd->parameters = (parameters > MAXPARA) ? MAXPARA : parameters; - newcmd->func = func; - newcmd->flags = flags; - - /* Add in hash with hash value = first byte */ - AddListItem(newcmd, CommandHash[toupper(*cmd)]); + aCommand *c = MyMallocEx(sizeof(aCommand)); - return newcmd; + c->cmd = strdup(cmd); + + /* Add in hash with hash value = first byte */ + AddListItem(c, CommandHash[toupper(*cmd)]); + + return c; } aCommand *find_CommandEx(char *cmd, int (*func)(), int token) diff --git a/src/parse.c b/src/parse.c index dad7ea98f..7371218ce 100644 --- a/src/parse.c +++ b/src/parse.c @@ -462,9 +462,9 @@ int parse(aClient *cptr, char *buffer, char *bufend) #else then = clock(); if (cmptr->flags & M_ALIAS) - retval = (*cmptr->func) (cptr, from, i, para, cmptr->cmd); - else { + retval = (*cmptr->aliasfunc) (cptr, from, i, para, cmptr->cmd); + } else { if (!cmptr->overriders) retval = (*cmptr->func) (cptr, from, i, para); else diff --git a/src/s_conf.c b/src/s_conf.c index 22f038da5..2af04f22a 100644 --- a/src/s_conf.c +++ b/src/s_conf.c @@ -9769,7 +9769,7 @@ int _conf_alias(ConfigFile *conf, ConfigEntry *ce) if (BadPtr(alias->nick) && alias->type != ALIAS_COMMAND) { safestrdup(alias->nick, alias->alias); } - CommandAdd(NULL, alias->alias, (void *)m_alias, 1, M_USER|M_ALIAS); + AliasAdd(NULL, alias->alias, m_alias, 1, M_USER|M_ALIAS); AddListItem(alias, conf_alias); return 0;