From dc55c3ec9f19e5ed284e5a786f646d0e6bb60ef9 Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Sun, 28 Aug 2022 08:59:46 +0200 Subject: [PATCH] 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); --- include/struct.h | 9 +++++++++ src/modules/mode.c | 4 ++-- src/modules/nick.c | 4 ++-- src/modules/pingpong.c | 2 +- src/modules/reputation.c | 4 ++-- src/modules/sinfo.c | 4 ++-- src/modules/tkl.c | 4 ++-- 7 files changed, 20 insertions(+), 11 deletions(-) diff --git a/include/struct.h b/include/struct.h index ae814e0d4..d78a06934 100644 --- a/include/struct.h +++ b/include/struct.h @@ -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. diff --git a/src/modules/mode.c b/src/modules/mode.c index f1ec5df4b..03ed8d4aa 100644 --- a/src/modules/mode.c +++ b/src/modules/mode.c @@ -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 diff --git a/src/modules/nick.c b/src/modules/nick.c index 99952be94..c6ee1afab 100644 --- a/src/modules/nick.c +++ b/src/modules/nick.c @@ -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); } } diff --git a/src/modules/pingpong.c b/src/modules/pingpong.c index d9bdd9c03..9c8557734 100644 --- a/src/modules/pingpong.c +++ b/src/modules/pingpong.c @@ -162,7 +162,7 @@ CMD_FUNC(cmd_pong) if (!IsRegistered(client)) { - cmd_nospoof(client, recv_mtags, parc, parv); + CALL_CMD_FUNC(cmd_nospoof); return; } diff --git a/src/modules/reputation.c b/src/modules/reputation.c index ca9a58087..c6b1ba16f 100644 --- a/src/modules/reputation.c +++ b/src/modules/reputation.c @@ -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) diff --git a/src/modules/sinfo.c b/src/modules/sinfo.c index 5af22f0f5..451db5854 100644 --- a/src/modules/sinfo.c +++ b/src/modules/sinfo.c @@ -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); } diff --git a/src/modules/tkl.c b/src/modules/tkl.c index e4542ec19..824e851f1 100644 --- a/src/modules/tkl.c +++ b/src/modules/tkl.c @@ -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;