]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/irc-info.c
New configuration option "OperServerMode".
[ngircd-alex.git] / src / ngircd / irc-info.c
index f95d5c5dc972deaec4ebdda66bd79cc753c9642e..3811ea73d406c7b429eaee389b575bdc78a0a726 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: irc-info.c,v 1.23 2005/01/24 14:17:21 alex Exp $";
+static char UNUSED id[] = "$Id: irc-info.c,v 1.27 2005/03/02 16:35:11 alex Exp $";
 
 #include "imp.h"
 #include <assert.h>
@@ -114,7 +114,7 @@ IRC_ISON( CLIENT *Client, REQUEST *Req )
                        ptr = strtok( NULL, " " );
                }
        }
-       if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
+       ngt_TrimLastChr(rpl, ' ');
 
        return IRC_WriteStrClient( Client, rpl, Client_ID( Client ) );
 } /* IRC_ISON */
@@ -484,7 +484,7 @@ IRC_USERHOST( CLIENT *Client, REQUEST *Req )
                        strlcat( rpl, " ", sizeof( rpl ));
                }
        }
-       if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
+       ngt_TrimLastChr( rpl, ' ');
 
        return IRC_WriteStrClient( Client, rpl, Client_ID( Client ) );
 } /* IRC_USERHOST */
@@ -530,9 +530,9 @@ IRC_VERSION( CLIENT *Client, REQUEST *Req )
        strncpy( ver + 4, ver + 5, 2 );
        strncpy( ver + 6, ver + 8, 3 );
        snprintf( vertxt, sizeof( vertxt ), "%s(%s)", PACKAGE_VERSION, ver );
-       return IRC_WriteStrClient( Client, RPL_VERSION_MSG, Client_ID( prefix ), PACKAGE_NAME, vertxt, NGIRCd_DebugLevel, Conf_ServerName, NGIRCd_VersionAddition( ));
+       return IRC_WriteStrClient( Client, RPL_VERSION_MSG, Client_ID( prefix ), PACKAGE_NAME, vertxt, NGIRCd_DebugLevel, Conf_ServerName, NGIRCd_VersionAddition );
 #else
-       return IRC_WriteStrClient( Client, RPL_VERSION_MSG, Client_ID( prefix ), PACKAGE_NAME, PACKAGE_VERSION, NGIRCd_DebugLevel, Conf_ServerName, NGIRCd_VersionAddition( ));
+       return IRC_WriteStrClient( Client, RPL_VERSION_MSG, Client_ID( prefix ), PACKAGE_NAME, PACKAGE_VERSION, NGIRCd_DebugLevel, Conf_ServerName, NGIRCd_VersionAddition );
 #endif
 } /* IRC_VERSION */
 
@@ -543,7 +543,7 @@ IRC_WHO( CLIENT *Client, REQUEST *Req )
        BOOLEAN ok, only_ops;
        CHAR flags[8], *ptr;
        CL2CHAN *cl2chan;
-       CHANNEL *chan;
+       CHANNEL *chan, *cn;
        CLIENT *c;
 
        assert( Client != NULL );
@@ -591,14 +591,25 @@ IRC_WHO( CLIENT *Client, REQUEST *Req )
 
                        if( ok && (( ! only_ops ) || ( strchr( Client_Modes( c ), 'o' ))))
                        {
-                               /* Flags zusammenbasteln */
+                               /* Get flags */
                                strcpy( flags, "H" );
                                if( strchr( Client_Modes( c ), 'o' )) strlcat( flags, "*", sizeof( flags ));
 
-                               /* ausgeben */
+                               /* Search suitable channel */
                                cl2chan = Channel_FirstChannelOf( c );
-                               if( cl2chan ) ptr = Channel_Name( Channel_GetChannel( cl2chan ));
-                               else ptr = "*";
+                               while( cl2chan )
+                               {
+                                       cn = Channel_GetChannel( cl2chan );
+                                       if( Channel_IsMemberOf( cn, Client ) ||
+                                           ! strchr( Channel_Modes( cn ), 's' ))
+                                       {
+                                               ptr = Channel_Name( cn );
+                                               break;
+                                       }
+                                       cl2chan = Channel_NextChannelOf( c, cl2chan );
+                               }
+                               if( ! cl2chan ) ptr = "*";
+
                                if( ! IRC_WriteStrClient( Client, RPL_WHOREPLY_MSG, Client_ID( Client ), ptr, Client_User( c ), Client_Hostname( c ), Client_ID( Client_Introducer( c )), Client_ID( c ), flags, Client_Hops( c ), Client_Info( c ))) return DISCONNECTED;
                        }
                }
@@ -663,6 +674,12 @@ IRC_WHOIS( CLIENT *Client, REQUEST *Req )
                chan = Channel_GetChannel( cl2chan );
                assert( chan != NULL );
 
+               /* next */
+               cl2chan = Channel_NextChannelOf( c, cl2chan );
+
+               /* Secret channel? */
+               if( strchr( Channel_Modes( chan ), 's' ) && ! Channel_IsMemberOf( chan, Client )) continue;
+
                /* Concatenate channel names */
                if( str[strlen( str ) - 1] != ':' ) strlcat( str, " ", sizeof( str ));
                if( strchr( Channel_UserModes( chan, c ), 'o' )) strlcat( str, "@", sizeof( str ));
@@ -675,9 +692,6 @@ IRC_WHOIS( CLIENT *Client, REQUEST *Req )
                        if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
                        snprintf( str, sizeof( str ), RPL_WHOISCHANNELS_MSG, Client_ID( from ), Client_ID( c ));
                }
-
-               /* next */
-               cl2chan = Channel_NextChannelOf( c, cl2chan );
        }
        if( str[strlen( str ) - 1] != ':')
        {
@@ -770,7 +784,6 @@ IRC_Show_MOTD( CLIENT *Client )
        BOOLEAN ok;
        CHAR line[127];
        FILE *fd;
-       UINT line_len;
 
        assert( Client != NULL );
 
@@ -793,9 +806,7 @@ IRC_Show_MOTD( CLIENT *Client )
        {
                if( ! fgets( line, sizeof( line ), fd )) break;
 
-               line_len = strlen( line );
-               if( line_len > 0 ) pos--;
-               if( line[line_len] == '\n' ) line[line_len] = '\0';
+               ngt_TrimLastChr( line, '\n');
 
                if( ! IRC_WriteStrClient( Client, RPL_MOTD_MSG, Client_ID( Client ), line ))
                {
@@ -825,6 +836,9 @@ IRC_Send_NAMES( CLIENT *Client, CHANNEL *Chan )
        if( Channel_IsMemberOf( Chan, Client )) is_member = TRUE;
        else is_member = FALSE;
 
+       /* Secret channel? */
+       if( ! is_member && strchr( Channel_Modes( Chan ), 's' )) return CONNECTED;
+
        /* Alle Mitglieder suchen */
        snprintf( str, sizeof( str ), RPL_NAMREPLY_MSG, Client_ID( Client ), "=", Channel_Name( Chan ));
        cl2chan = Channel_FirstMember( Chan );
@@ -878,6 +892,9 @@ IRC_Send_WHO( CLIENT *Client, CHANNEL *Chan, BOOLEAN OnlyOps )
        if( Channel_IsMemberOf( Chan, Client )) is_member = TRUE;
        else is_member = FALSE;
 
+       /* Secret channel? */
+       if( ! is_member && strchr( Channel_Modes( Chan ), 's' )) return CONNECTED;
+
        /* Alle Mitglieder suchen */
        cl2chan = Channel_FirstMember( Chan );
        while( cl2chan )