From: DNS777 Date: Mon, 8 Oct 2012 10:11:04 +0000 (+0200) Subject: Implement user mode "b": block messages X-Git-Tag: rel-20-rc1~41 X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd-alex.git;a=commitdiff_plain;h=9d97004a287589681342a0116746796f2764100c Implement user mode "b": block messages When a user has set mode "b", all private messages and notices to this user are blocked if they don't originate from a registered user, an IRC Op, server or service. The originator gets an error numeric sent back in this case, ERR_CANNOTSENDTONICK_MSG(976), which is/was(?) used by KineIRCd, too. This closes bug #144. --- diff --git a/doc/Modes.txt b/doc/Modes.txt index 8d7cdd70..aee7491c 100644 --- a/doc/Modes.txt +++ b/doc/Modes.txt @@ -22,6 +22,7 @@ channels he is using at the moment. mode since description a 0.3.0 User is away. + b 20 User blocks private messages and notices. B 20 User is flagged as a "bot". c 17 IRC operator wants to receive connect/disconnect NOTICEs. C 19 Only users that share a channel are allowed to send messages. diff --git a/src/ngircd/defines.h b/src/ngircd/defines.h index 37ca6764..977bc74e 100644 --- a/src/ngircd/defines.h +++ b/src/ngircd/defines.h @@ -161,7 +161,7 @@ #endif /** Supported user modes. */ -#define USERMODES "aBcCioqrRswx" +#define USERMODES "abBcCioqrRswx" /** Supported channel modes. */ #define CHANMODES "abehiIklmMnoOPqQrRstvVz" diff --git a/src/ngircd/irc-mode.c b/src/ngircd/irc-mode.c index c7d02c91..ce4044d0 100644 --- a/src/ngircd/irc-mode.c +++ b/src/ngircd/irc-mode.c @@ -215,6 +215,7 @@ Client_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target ) /* Validate modes */ x[0] = '\0'; switch (*mode_ptr) { + case 'b': /* Block private msgs */ case 'C': /* Only messages from clients sharing a channel */ case 'i': /* Invisible */ case 's': /* Server messages */ diff --git a/src/ngircd/irc.c b/src/ngircd/irc.c index ceb649ec..1a57bec1 100644 --- a/src/ngircd/irc.c +++ b/src/ngircd/irc.c @@ -500,6 +500,17 @@ Send_Message(CLIENT * Client, REQUEST * Req, int ForceType, bool SendErrors) Req->command = "PRIVMSG"; } #endif + if (Client_HasMode(cl, 'b') && + !Client_HasMode(from, 'R') && + !Client_HasMode(from, 'o') && + !(Client_Type(from) == CLIENT_SERVER) && + !(Client_Type(from) == CLIENT_SERVICE)) { + if (SendErrors && !IRC_WriteStrClient(from, + ERR_CANNOTSENDTONICK_MSG, + Client_ID(from), Client_ID(cl))) + return DISCONNECTED; + goto send_next_target; + } if (Client_HasMode(cl, 'C')) { cl2chan = Channel_FirstChannelOf(cl); diff --git a/src/ngircd/messages.h b/src/ngircd/messages.h index ec7bb6fd..59e9605d 100644 --- a/src/ngircd/messages.h +++ b/src/ngircd/messages.h @@ -151,6 +151,7 @@ #define ERR_UMODEUNKNOWNFLAG2_MSG "501 %s :Unknown mode \"%c%c\"" #define ERR_USERSDONTMATCH_MSG "502 %s :Can't set/get mode for other users" #define ERR_NOINVITE_MSG "518 %s :Cannot invite to %s (+V)" +#define ERR_CANNOTSENDTONICK_MSG "976 %s :Cannot send to user (+b) -- Only registered users can message %s" #ifdef ZLIB # define RPL_STATSLINKINFOZIP_MSG "211 %s %s %d %ld %ld/%ld %ld %ld/%ld :%ld"