From 21767c968d5799ce153f860db6c119eb4b7f9518 Mon Sep 17 00:00:00 2001 From: LucentW Date: Mon, 27 Apr 2015 23:20:32 +0200 Subject: [PATCH 1/3] Implement +I (private channel list on whois) Implements enhancement requested in issue #179 --- src/ngircd/defines.h | 2 +- src/ngircd/irc-info.c | 66 ++++++++++++++++++++++--------------------- src/ngircd/irc-mode.c | 1 + 3 files changed, 36 insertions(+), 33 deletions(-) diff --git a/src/ngircd/defines.h b/src/ngircd/defines.h index 456c4c93..ff849bbe 100644 --- a/src/ngircd/defines.h +++ b/src/ngircd/defines.h @@ -177,7 +177,7 @@ #endif /** Supported user modes. */ -#define USERMODES "abBcCFioqrRswx" +#define USERMODES "abBcCFiIoqrRswx" /** Supported channel modes. */ #define CHANMODES "abehiIklmMnoOPqQrRstvVz" diff --git a/src/ngircd/irc-info.c b/src/ngircd/irc-info.c index 61c6239c..e261b7f6 100644 --- a/src/ngircd/irc-info.c +++ b/src/ngircd/irc-info.c @@ -313,48 +313,50 @@ IRC_WHOIS_SendReply(CLIENT *Client, CLIENT *from, CLIENT *c) Client_Info(Client_Introducer(c)))) return DISCONNECTED; - /* Channels */ - snprintf(str, sizeof(str), RPL_WHOISCHANNELS_MSG, - Client_ID(from), Client_ID(c)); - cl2chan = Channel_FirstChannelOf(c); - while (cl2chan) { - chan = Channel_GetChannel(cl2chan); - assert(chan != NULL); + /* Channels, show only if client has no +I or if from is oper */ + if(!(Client_HasMode(c, 'I')) || Client_HasMode(from, 'o')) { + snprintf(str, sizeof(str), RPL_WHOISCHANNELS_MSG, + Client_ID(from), Client_ID(c)); + cl2chan = Channel_FirstChannelOf(c); + while (cl2chan) { + chan = Channel_GetChannel(cl2chan); + assert(chan != NULL); - /* next */ - cl2chan = Channel_NextChannelOf(c, cl2chan); + /* next */ + cl2chan = Channel_NextChannelOf(c, cl2chan); - /* Secret channel? */ - if (Channel_HasMode(chan, 's') - && !Channel_IsMemberOf(chan, Client)) - continue; + /* Secret channel? */ + if (Channel_HasMode(chan, 's') + && !Channel_IsMemberOf(chan, Client)) + continue; - /* Local channel and request is not from a user? */ - if (Client_Type(Client) == CLIENT_SERVER - && Channel_IsLocal(chan)) - continue; + /* Local channel and request is not from a user? */ + if (Client_Type(Client) == CLIENT_SERVER + && Channel_IsLocal(chan)) + continue; - /* Concatenate channel names */ - if (str[strlen(str) - 1] != ':') - strlcat(str, " ", sizeof(str)); + /* Concatenate channel names */ + if (str[strlen(str) - 1] != ':') + strlcat(str, " ", sizeof(str)); - who_flags_qualifier(Client, Channel_UserModes(chan, c), - str, sizeof(str)); - strlcat(str, Channel_Name(chan), sizeof(str)); + who_flags_qualifier(Client, Channel_UserModes(chan, c), + str, sizeof(str)); + strlcat(str, Channel_Name(chan), sizeof(str)); - if (strlen(str) > (COMMAND_LEN - CHANNEL_NAME_LEN - 4)) { - /* Line becomes too long: send it! */ + if (strlen(str) > (COMMAND_LEN - CHANNEL_NAME_LEN - 4)) { + /* Line becomes too long: send it! */ + if (!IRC_WriteStrClient(Client, "%s", str)) + return DISCONNECTED; + snprintf(str, sizeof(str), RPL_WHOISCHANNELS_MSG, + Client_ID(from), Client_ID(c)); + } + } + if(str[strlen(str) - 1] != ':') { + /* There is data left to send: */ if (!IRC_WriteStrClient(Client, "%s", str)) return DISCONNECTED; - snprintf(str, sizeof(str), RPL_WHOISCHANNELS_MSG, - Client_ID(from), Client_ID(c)); } } - if(str[strlen(str) - 1] != ':') { - /* There is data left to send: */ - if (!IRC_WriteStrClient(Client, "%s", str)) - return DISCONNECTED; - } /* IRC-Services? */ if (Client_Type(c) == CLIENT_SERVICE && diff --git a/src/ngircd/irc-mode.c b/src/ngircd/irc-mode.c index cde573bf..ec7d53c4 100644 --- a/src/ngircd/irc-mode.c +++ b/src/ngircd/irc-mode.c @@ -206,6 +206,7 @@ Client_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target ) case 'b': /* Block private msgs */ case 'C': /* Only messages from clients sharing a channel */ case 'i': /* Invisible */ + case 'I': /* Hide channel list from WHOIS */ case 's': /* Server messages */ case 'w': /* Wallops messages */ x[0] = *mode_ptr; From 6fc53558ed2117e5dd4e6bd1e9fb595bba67aa79 Mon Sep 17 00:00:00 2001 From: LucentW Date: Wed, 29 Apr 2015 20:25:18 +0200 Subject: [PATCH 2/3] Fixed indents and documentation (also updated the copyright date on the txt I edited) --- doc/Modes.txt | 3 ++- src/ngircd/irc-info.c | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/Modes.txt b/doc/Modes.txt index a9317873..61d5e8f6 100644 --- a/doc/Modes.txt +++ b/doc/Modes.txt @@ -2,7 +2,7 @@ ngIRCd - Next Generation IRC Server http://ngircd.barton.de/ - (c)2001-2014 Alexander Barton and Contributors. + (c)2001-2015 Alexander Barton and Contributors. ngIRCd is free software and published under the terms of the GNU General Public License. @@ -28,6 +28,7 @@ channels he is using at the moment. C 19 Only users that share a channel are allowed to send messages. F 22 Relaxed flood protection (only settable by IRC Operators). i 0.0.1 User is "invisible". + I 23 No channels are shown on WHOIS (IRC Operators can always see those). o 0.0.1 User is IRC operator. q 20 User is protected, can not be kicked from a channel. r 0.0.1 User is restricted. diff --git a/src/ngircd/irc-info.c b/src/ngircd/irc-info.c index e261b7f6..7bb453df 100644 --- a/src/ngircd/irc-info.c +++ b/src/ngircd/irc-info.c @@ -327,12 +327,12 @@ IRC_WHOIS_SendReply(CLIENT *Client, CLIENT *from, CLIENT *c) /* Secret channel? */ if (Channel_HasMode(chan, 's') - && !Channel_IsMemberOf(chan, Client)) + && !Channel_IsMemberOf(chan, Client)) continue; /* Local channel and request is not from a user? */ if (Client_Type(Client) == CLIENT_SERVER - && Channel_IsLocal(chan)) + && Channel_IsLocal(chan)) continue; /* Concatenate channel names */ @@ -340,7 +340,6 @@ IRC_WHOIS_SendReply(CLIENT *Client, CLIENT *from, CLIENT *c) strlcat(str, " ", sizeof(str)); who_flags_qualifier(Client, Channel_UserModes(chan, c), - str, sizeof(str)); strlcat(str, Channel_Name(chan), sizeof(str)); if (strlen(str) > (COMMAND_LEN - CHANNEL_NAME_LEN - 4)) { From a4af9024fd12d4a755ddf2a7aa1d0036ff997672 Mon Sep 17 00:00:00 2001 From: LucentW Date: Wed, 29 Apr 2015 20:27:11 +0200 Subject: [PATCH 3/3] Fixed indents 2 --- src/ngircd/irc-info.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ngircd/irc-info.c b/src/ngircd/irc-info.c index 7bb453df..ba7a2b74 100644 --- a/src/ngircd/irc-info.c +++ b/src/ngircd/irc-info.c @@ -340,6 +340,7 @@ IRC_WHOIS_SendReply(CLIENT *Client, CLIENT *from, CLIENT *c) strlcat(str, " ", sizeof(str)); who_flags_qualifier(Client, Channel_UserModes(chan, c), + str, sizeof(str)); strlcat(str, Channel_Name(chan), sizeof(str)); if (strlen(str) > (COMMAND_LEN - CHANNEL_NAME_LEN - 4)) {