Skip to content

Commit

Permalink
Add CALL_CMD_FUNC(cmd_func_name) and use it.
Browse files Browse the repository at this point in the history
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);
  • Loading branch information
syzop committed Aug 28, 2022
1 parent 4e5598b commit dc55c3e
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 11 deletions.
9 changes: 9 additions & 0 deletions include/struct.h
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/modules/mode.c
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/modules/nick.c
Expand Up @@ -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))
{
Expand All @@ -754,7 +754,7 @@ CMD_FUNC(cmd_nick)
return;
} else
{
cmd_nick_remote(client, recv_mtags, parc, parv);
CALL_CMD_FUNC(cmd_nick_remote);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/modules/pingpong.c
Expand Up @@ -162,7 +162,7 @@ CMD_FUNC(cmd_pong)

if (!IsRegistered(client))
{
cmd_nospoof(client, recv_mtags, parc, parv);
CALL_CMD_FUNC(cmd_nospoof);
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/modules/reputation.c
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/modules/sinfo.c
Expand Up @@ -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);
}
4 changes: 2 additions & 2 deletions src/modules/tkl.c
Expand Up @@ -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;
Expand Down

0 comments on commit dc55c3e

Please sign in to comment.