From 1aaf54ac24e8e24d5a3ce5b7b00a775f5237d7a9 Mon Sep 17 00:00:00 2001 From: DNS777 Date: Thu, 23 Aug 2012 09:25:30 +0000 Subject: Implement channel mode "M" Only the server, identified users and IRC operators are able to talk. --- src/ngircd/channel.c | 23 +++++++++++++++++++++++ src/ngircd/defines.h | 2 +- src/ngircd/irc-mode.c | 1 + src/ngircd/messages.h | 2 +- 4 files changed, 26 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ngircd/channel.c b/src/ngircd/channel.c index ff470246..1d1645f2 100644 --- a/src/ngircd/channel.c +++ b/src/ngircd/channel.c @@ -845,6 +845,22 @@ Can_Send_To_Channel(CHANNEL *Chan, CLIENT *From) } +static bool +Can_Send_To_Channel_Identified(CHANNEL *Chan, CLIENT *From) +{ + if ((Client_ThisServer() == From) || Client_HasMode(From, 'o')) + return true; + + if (strchr(Channel_Modes(Chan), 'M') && !Client_HasMode(From, 'R')) + return false; + + if (Lists_Check(&Chan->list_excepts, From)) + return true; + + return !Lists_Check(&Chan->list_bans, From); +} + + GLOBAL bool Channel_Write(CHANNEL *Chan, CLIENT *From, CLIENT *Client, const char *Command, bool SendErrors, const char *Text) @@ -856,6 +872,13 @@ Channel_Write(CHANNEL *Chan, CLIENT *From, CLIENT *Client, const char *Command, Client_ID(From), Channel_Name(Chan)); } + if (!Can_Send_To_Channel_Identified(Chan, From)) { + if (! SendErrors) + return CONNECTED; + return IRC_WriteStrClient(From, ERR_CANNOTSENDTOCHAN_MSG, + Client_ID(From), Channel_Name(Chan)); + } + if (Client_Conn(From) > NONE) Conn_UpdateIdle(Client_Conn(From)); diff --git a/src/ngircd/defines.h b/src/ngircd/defines.h index cd0a1666..310e0699 100644 --- a/src/ngircd/defines.h +++ b/src/ngircd/defines.h @@ -164,7 +164,7 @@ #define USERMODES "acCiorRswx" /** Supported channel modes. */ -#define CHANMODES "beiIklmnoOPrRstvz" +#define CHANMODES "beiIklmMnoOPrRstvz" /** Away message for users connected to linked servers. */ #define DEFAULT_AWAY_MSG "Away" diff --git a/src/ngircd/irc-mode.c b/src/ngircd/irc-mode.c index fa35cdd0..f91a28c6 100644 --- a/src/ngircd/irc-mode.c +++ b/src/ngircd/irc-mode.c @@ -500,6 +500,7 @@ Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel) switch (*mode_ptr) { /* --- Channel modes --- */ case 'i': /* Invite only */ + case 'M': /* Only identified nicks can write */ case 'm': /* Moderated */ case 'n': /* Only members can write */ case 'R': /* Registered users only */ diff --git a/src/ngircd/messages.h b/src/ngircd/messages.h index 9ad6be17..0c36f60a 100644 --- a/src/ngircd/messages.h +++ b/src/ngircd/messages.h @@ -21,7 +21,7 @@ #define RPL_YOURHOST_MSG "002 %s :Your host is %s, running version ngircd-%s (%s/%s/%s)" #define RPL_CREATED_MSG "003 %s :This server has been started %s" #define RPL_MYINFO_MSG "004 %s %s ngircd-%s %s %s" -#define RPL_ISUPPORT1_MSG "005 %s RFC2812 IRCD=ngIRCd CASEMAPPING=ascii PREFIX=(ov)@+ CHANTYPES=#&+ CHANMODES=beI,k,l,imnOPRstz CHANLIMIT=#&+:%d :are supported on this server" +#define RPL_ISUPPORT1_MSG "005 %s RFC2812 IRCD=ngIRCd CASEMAPPING=ascii PREFIX=(ov)@+ CHANTYPES=#&+ CHANMODES=beI,k,l,imMnOPRstz CHANLIMIT=#&+:%d :are supported on this server" #define RPL_ISUPPORT2_MSG "005 %s CHANNELLEN=%d NICKLEN=%d TOPICLEN=%d AWAYLEN=%d KICKLEN=%d MODES=%d MAXLIST=beI:%d EXCEPTS=e INVEX=I PENALTY :are supported on this server" #define RPL_TRACELINK_MSG "200 %s Link %s-%s %s %s V%s %ld %d %d" -- cgit 1.4.1 From fee591b7597dfd9b438b6902d7971787dfd69d60 Mon Sep 17 00:00:00 2001 From: Alexander Barton Date: Sun, 26 Aug 2012 16:51:34 +0200 Subject: Remove Can_Send_To_Channel_Identified() Move the functionality directly into Can_Send_To_Channel() function. There should be no functional change ... --- src/ngircd/channel.c | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/ngircd/channel.c b/src/ngircd/channel.c index 1d1645f2..0f21a459 100644 --- a/src/ngircd/channel.c +++ b/src/ngircd/channel.c @@ -832,26 +832,14 @@ Can_Send_To_Channel(CHANNEL *Chan, CLIENT *From) if (strchr(Channel_Modes(Chan), 'n') && !is_member) return false; - if (is_op || has_voice) - return true; - - if (strchr(Channel_Modes(Chan), 'm')) + if (strchr(Channel_Modes(Chan), 'M') && !Client_HasMode(From, 'R') + && !Client_HasMode(From, 'o')) return false; - if (Lists_Check(&Chan->list_excepts, From)) - return true; - - return !Lists_Check(&Chan->list_bans, From); -} - - -static bool -Can_Send_To_Channel_Identified(CHANNEL *Chan, CLIENT *From) -{ - if ((Client_ThisServer() == From) || Client_HasMode(From, 'o')) + if (is_op || has_voice) return true; - if (strchr(Channel_Modes(Chan), 'M') && !Client_HasMode(From, 'R')) + if (strchr(Channel_Modes(Chan), 'm')) return false; if (Lists_Check(&Chan->list_excepts, From)) @@ -872,13 +860,6 @@ Channel_Write(CHANNEL *Chan, CLIENT *From, CLIENT *Client, const char *Command, Client_ID(From), Channel_Name(Chan)); } - if (!Can_Send_To_Channel_Identified(Chan, From)) { - if (! SendErrors) - return CONNECTED; - return IRC_WriteStrClient(From, ERR_CANNOTSENDTOCHAN_MSG, - Client_ID(From), Channel_Name(Chan)); - } - if (Client_Conn(From) > NONE) Conn_UpdateIdle(Client_Conn(From)); -- cgit 1.4.1