]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/irc-info.c
IRC_Send_LUSERS(): Code cleanup
[ngircd-alex.git] / src / ngircd / irc-info.c
index 22c65aa2a426cd6a36aba7d42d853391db6f984c..cdd03bb1d3a24290bca78f8ec8f864f925185134 100644 (file)
 #include "conn-func.h"
 #include "conn-zip.h"
 #include "channel.h"
+#include "class.h"
 #include "conf.h"
 #include "defines.h"
+#include "lists.h"
 #include "log.h"
 #include "messages.h"
 #include "match.h"
@@ -478,6 +480,8 @@ IRC_STATS( CLIENT *Client, REQUEST *Req )
        COMMAND *cmd;
        time_t time_now;
        unsigned int days, hrs, mins;
+       struct list_head *list;
+       struct list_elem *list_item;
 
        assert(Client != NULL);
        assert(Req != NULL);
@@ -516,6 +520,28 @@ IRC_STATS( CLIENT *Client, REQUEST *Req )
                query = '*';
 
        switch (query) {
+       case 'g':       /* Network-wide bans ("G-Lines") */
+       case 'G':
+       case 'k':       /* Server-local bans ("K-Lines") */
+       case 'K':
+               if (!Client_HasMode(from, 'o'))
+                   return IRC_WriteStrClient(from, ERR_NOPRIVILEGES_MSG,
+                                             Client_ID(from));
+               if (query == 'g' || query == 'G')
+                       list = Class_GetList(CLASS_GLINE);
+               else
+                       list = Class_GetList(CLASS_KLINE);
+                       list_item = Lists_GetFirst(list);
+                       while (list_item) {
+                               if (!IRC_WriteStrClient(from, RPL_STATSXLINE_MSG,
+                                               Client_ID(from), query,
+                                               Lists_GetMask(list_item),
+                                               Lists_GetValidity(list_item),
+                                               Lists_GetReason(list_item)))
+                                       return DISCONNECTED;
+                               list_item = Lists_GetNext(list_item);
+                       }
+               break;
        case 'l':       /* Link status (servers and own link) */
        case 'L':
                time_now = time(NULL);
@@ -999,7 +1025,7 @@ IRC_WHOIS_SendReply(CLIENT *Client, CLIENT *from, CLIENT *c)
                        return DISCONNECTED;
 
        /* Idle and signon time (local clients only!) */
-       if (Client_Conn(c) > NONE &&
+       if (!Conf_MorePrivacy && Client_Conn(c) > NONE &&
                !IRC_WriteStrClient(from, RPL_WHOISIDLE_MSG,
                                    Client_ID(from), Client_ID(c),
                                    (unsigned long)Conn_GetIdle(Client_Conn(c)),
@@ -1163,6 +1189,10 @@ IRC_WHOWAS( CLIENT *Client, REQUEST *Req )
        assert( Client != NULL );
        assert( Req != NULL );
 
+       /* Do not reveal any info on disconnected users? */
+       if (Conf_MorePrivacy)
+               return CONNECTED;
+
        /* Wrong number of parameters? */
        if (Req->argc > 3)
                return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
@@ -1247,38 +1277,54 @@ IRC_WHOWAS( CLIENT *Client, REQUEST *Req )
 } /* IRC_WHOWAS */
 
 
+/**
+ * Send LUSERS reply to a client.
+ *
+ * @param Client The receipient of the information.
+ * @return CONNECTED or DISCONNECTED.
+ */
 GLOBAL bool
-IRC_Send_LUSERS( CLIENT *Client )
+IRC_Send_LUSERS(CLIENT *Client)
 {
        unsigned long cnt;
 #ifndef STRICT_RFC
        unsigned long max;
 #endif
 
-       assert( Client != NULL );
+       assert(Client != NULL);
 
        /* Users, services and serevers in the network */
-       if( ! IRC_WriteStrClient( Client, RPL_LUSERCLIENT_MSG, Client_ID( Client ), Client_UserCount( ), Client_ServiceCount( ), Client_ServerCount( ))) return DISCONNECTED;
+       if (!IRC_WriteStrClient(Client, RPL_LUSERCLIENT_MSG, Client_ID(Client),
+                               Client_UserCount(), Client_ServiceCount(),
+                               Client_ServerCount()))
+               return DISCONNECTED;
 
        /* Number of IRC operators */
        cnt = Client_OperCount( );
-       if( cnt > 0 )
-       {
-               if( ! IRC_WriteStrClient( Client, RPL_LUSEROP_MSG, Client_ID( Client ), cnt )) return DISCONNECTED;
+       if (cnt > 0) {
+               if (!IRC_WriteStrClient(Client, RPL_LUSEROP_MSG,
+                                       Client_ID(Client), cnt))
+                       return DISCONNECTED;
        }
 
        /* Unknown connections */
        cnt = Client_UnknownCount( );
-       if( cnt > 0 )
-       {
-               if( ! IRC_WriteStrClient( Client, RPL_LUSERUNKNOWN_MSG, Client_ID( Client ), cnt )) return DISCONNECTED;
+       if (cnt > 0) {
+               if (!IRC_WriteStrClient(Client, RPL_LUSERUNKNOWN_MSG,
+                                       Client_ID(Client), cnt))
+                       return DISCONNECTED;
        }
 
        /* Number of created channels */
-       if( ! IRC_WriteStrClient( Client, RPL_LUSERCHANNELS_MSG, Client_ID( Client ), Channel_Count( ))) return DISCONNECTED;
+       if (!IRC_WriteStrClient(Client, RPL_LUSERCHANNELS_MSG,
+                               Client_ID(Client), Channel_Count()))
+               return DISCONNECTED;
 
        /* Number of local users, services and servers */
-       if( ! IRC_WriteStrClient( Client, RPL_LUSERME_MSG, Client_ID( Client ), Client_MyUserCount( ), Client_MyServiceCount( ), Client_MyServerCount( ))) return DISCONNECTED;
+       if (!IRC_WriteStrClient(Client, RPL_LUSERME_MSG, Client_ID(Client),
+                               Client_MyUserCount(), Client_MyServiceCount(),
+                               Client_MyServerCount()))
+               return DISCONNECTED;
 
 #ifndef STRICT_RFC
        /* Maximum number of local users */
@@ -1389,6 +1435,10 @@ IRC_Send_NAMES( CLIENT *Client, CHANNEL *Chan )
        if( Channel_IsMemberOf( Chan, Client )) is_member = true;
        else is_member = false;
 
+       /* Do not print info on channel memberships to anyone that is not member? */
+       if (Conf_MorePrivacy && !is_member)
+               return CONNECTED;
+
        /* Secret channel? */
        if( ! is_member && strchr( Channel_Modes( Chan ), 's' )) return CONNECTED;