From ac362df89da3503f95aa59b7176fba2ef314c257 Mon Sep 17 00:00:00 2001 From: Moritz Wilhelmy Date: Fri, 29 May 2026 01:37:36 +0200 Subject: [PATCH] irssiproxy: add server_redirect for names Then, use this redirect to make irssi not print NAMES commands sent by proxy clients. Closes #1537 --- src/irc/core/servers-redirect.c | 8 ++++++++ src/irc/proxy/listen.c | 25 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/irc/core/servers-redirect.c b/src/irc/core/servers-redirect.c index 50560883..732763ef 100644 --- a/src/irc/core/servers-redirect.c +++ b/src/irc/core/servers-redirect.c @@ -706,6 +706,14 @@ void servers_redirect_init(void) NULL, /* */ NULL); + /* NAMES */ + server_redirect_register("names", TRUE, 0, + "event 353", 2, /* An element of NAMES (channel at pos 2) */ + NULL, + "event 366", 1, /* End of NAMES */ + NULL, + NULL); + /* LIST */ server_redirect_register("list", FALSE, 0, "event 321", 1, /* Begins the LIST */ diff --git a/src/irc/proxy/listen.c b/src/irc/proxy/listen.c index 1fed639e..527432ed 100644 --- a/src/irc/proxy/listen.c +++ b/src/irc/proxy/listen.c @@ -164,6 +164,29 @@ static void grab_who(CLIENT_REC *client, const char *channel) g_string_free(arg, TRUE); } +static void grab_names(CLIENT_REC *client, const char *channel) +{ + char **list, **tmp; + char *arg, *p; + int count; + + /* NAMES a,b,c responds with one 366 per channel */ + list = g_strsplit(channel, ",", -1); + + for (tmp = list, count = 0; *tmp != NULL; tmp++, count++) + ; + + /* replace commas with spaces for redirect arg matching */ + arg = g_strdup(channel); + for (p = arg; *p != '\0'; p++) + if (*p == ',') *p = ' '; + + proxy_redirect_event(client, "names", count > 0 ? count : 1, arg, TRUE); + + g_free(arg); + g_strfreev(list); +} + static void handle_client_connect_cmd(CLIENT_REC *client, const char *cmd, const char *args) { @@ -302,6 +325,8 @@ static void handle_client_cmd(CLIENT_REC *client, char *cmd, char *args, /* check if the command could be redirected */ if (g_strcmp0(cmd, "WHO") == 0) grab_who(client, args); + else if (g_strcmp0(cmd, "NAMES") == 0) + grab_names(client, args); else if (g_strcmp0(cmd, "WHOWAS") == 0) proxy_redirect_event(client, "whowas", 1, args, -1); else if (g_strcmp0(cmd, "WHOIS") == 0) {