1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-07-08 07:23:13 +02:00

Add CALL_CMD_FUNC(cmd_func_name) and use it.

This is only for calls within the same module, as otherwise you
should use do_cmd().

Benefit of this way is that it is short and you don't have to worry
about passing the right command parameters, which may change over time.
Example as used in src/modules/nick.c:
-               cmd_nick_remote(client, recv_mtags, parc, parv);
+               CALL_CMD_FUNC(cmd_nick_remote);
This commit is contained in:
Bram Matthys
2022-08-28 08:59:46 +02:00
parent 4e5598b6cf
commit dc55c3ec9f
7 changed files with 20 additions and 11 deletions
+9
View File
@@ -904,6 +904,15 @@ struct SWhois {
* E.g. parv[3] in the above example is out of bounds.
*/
#define CMD_FUNC(x) void (x) (Client *client, MessageTag *recv_mtags, int parc, const char *parv[])
/** Call a command function - can be useful if you are calling another command function in your own module.
* For example in cmd_nick() we call cmd_nick_local() for local functions,
* and then we can just use CALL_CMD_FUNC(cmd_nick_local); and don't have
* to bother with passing the right command arguments. Which is nice because
* command arguments may change in future UnrealIRCd versions.
*/
#define CALL_CMD_FUNC(x) (x)(client, recv_mtags, parc, parv)
/** @} */
/** Command override function - used by all command override handlers.
+2 -2
View File
@@ -107,12 +107,12 @@ CMD_FUNC(cmd_mode)
channel = find_channel(parv[1]);
if (!channel)
{
cmd_umode(client, recv_mtags, parc, parv);
CALL_CMD_FUNC(cmd_umode);
return;
}
} else
{
cmd_umode(client, recv_mtags, parc, parv);
CALL_CMD_FUNC(cmd_umode);
return;
}
} else
+2 -2
View File
@@ -740,7 +740,7 @@ CMD_FUNC(cmd_nick)
if (MyConnect(client) && !IsServer(client))
{
cmd_nick_local(client, recv_mtags, parc, parv);
CALL_CMD_FUNC(cmd_nick_local);
} else
if (!IsUser(client))
{
@@ -754,7 +754,7 @@ CMD_FUNC(cmd_nick)
return;
} else
{
cmd_nick_remote(client, recv_mtags, parc, parv);
CALL_CMD_FUNC(cmd_nick_remote);
}
}
+1 -1
View File
@@ -162,7 +162,7 @@ CMD_FUNC(cmd_pong)
if (!IsRegistered(client))
{
cmd_nospoof(client, recv_mtags, parc, parv);
CALL_CMD_FUNC(cmd_nospoof);
return;
}
+2 -2
View File
@@ -1330,9 +1330,9 @@ CMD_FUNC(reputation_server_cmd)
CMD_FUNC(reputation_cmd)
{
if (MyUser(client))
reputation_user_cmd(client, recv_mtags, parc, parv);
CALL_CMD_FUNC(reputation_user_cmd);
else if (IsServer(client) || IsMe(client))
reputation_server_cmd(client, recv_mtags, parc, parv);
CALL_CMD_FUNC(reputation_server_cmd);
}
int reputation_whois(Client *client, Client *target, NameValuePrioList **list)
+2 -2
View File
@@ -157,7 +157,7 @@ CMD_FUNC(sinfo_user)
CMD_FUNC(cmd_sinfo)
{
if (IsServer(client))
sinfo_server(client, recv_mtags, parc, parv);
CALL_CMD_FUNC(sinfo_server);
else if (MyUser(client))
sinfo_user(client, recv_mtags, parc, parv);
CALL_CMD_FUNC(sinfo_user);
}
+2 -2
View File
@@ -4451,10 +4451,10 @@ CMD_FUNC(_cmd_tkl)
switch (*parv[1])
{
case '+':
cmd_tkl_add(client, recv_mtags, parc, parv);
CALL_CMD_FUNC(cmd_tkl_add);
break;
case '-':
cmd_tkl_del(client, recv_mtags, parc, parv);
CALL_CMD_FUNC(cmd_tkl_del);
break;
default:
break;