From 1c3eff423231cb682dbdd1a81d12fe299dcdbc02 Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Wed, 27 Nov 2019 09:56:39 +0100 Subject: [PATCH] Update KNOCK to be sent across servers. This will cause double notices if you are running a mixed U4 and U5 network, but it solves the situation where a knock-flood is only detected locally. Since KNOCK usage isn't that common and flooding is worse than double notices during the transition period, I went with this change.. --- src/modules/knock.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/modules/knock.c b/src/modules/knock.c index 7c69e51c0..3cdb48582 100644 --- a/src/modules/knock.c +++ b/src/modules/knock.c @@ -62,6 +62,15 @@ MOD_UNLOAD() ** Additional bugfixes/ideas by codemastr ** (C) codemastr & Stskeeps ** +** 2019-11-27: Behavior change. We now send the KNOCK +** across servers and only deliver the channel notice +** to local channel members. The reason for this is that +** otherwise we cannot count KNOCKs network-wide which +** caused knock-floods per-channel to be per-server +** rather than global, which undesirable. +** Unfortunately, this means that if you have a mixed +** U4 and U5 network you will see KNOCK notices twice +** for every attempt. */ CMD_FUNC(cmd_knock) { @@ -69,6 +78,7 @@ CMD_FUNC(cmd_knock) Hook *h; int i = 0; MessageTag *mtags = NULL; + char *reason; if (IsServer(client)) return; @@ -79,6 +89,8 @@ CMD_FUNC(cmd_knock) return; } + reason = parv[2] ? parv[2] : "no reason specified"; + if (MyConnect(client) && !valid_channelname(parv[1])) { sendnumeric(client, ERR_NOSUCHCHANNEL, parv[1]); @@ -138,14 +150,18 @@ CMD_FUNC(cmd_knock) } new_message(&me, NULL, &mtags); + sendto_channel(channel, &me, NULL, PREFIX_OP|PREFIX_ADMIN|PREFIX_OWNER, - 0, SEND_ALL, mtags, + 0, SEND_LOCAL, mtags, ":%s NOTICE @%s :[Knock] by %s!%s@%s (%s)", me.name, channel->chname, client->name, client->user->username, GetHost(client), - parv[2] ? parv[2] : "no reason specified"); + reason); - sendnotice(client, "Knocked on %s", channel->chname); + sendto_server(client, 0, 0, mtags, ":%s KNOCK %s :%s", client->id, channel->chname, reason); + + if (MyUser(client)) + sendnotice(client, "Knocked on %s", channel->chname); RunHook4(HOOKTYPE_KNOCK, client, channel, mtags, parv[2]);