1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-07-09 15:43:12 +02:00

Add function type checking in CommandAdd()

And, for aliases, now use AliasAdd(), CommandAdd() is no longer permitted
for it. Do any modules use this?
This commit is contained in:
Bram Matthys
2019-03-24 08:16:45 +01:00
parent f9db29b768
commit 60952328f0
7 changed files with 45 additions and 19 deletions
+26 -2
View File
@@ -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)
{