Implement IRC "STATS g" and "STATS k" command
authorAlexander Barton <alex@barton.de>
Sun, 25 Dec 2011 13:50:19 +0000 (14:50 +0100)
committerAlexander Barton <alex@barton.de>
Sun, 25 Dec 2011 13:50:19 +0000 (14:50 +0100)
src/ngircd/irc-info.c
src/ngircd/messages.h

index 301da5337d32430592cfe1fe9e88838064b1c232..736412f1fcdde91459540de1b51df995b2003e70 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);
index 78ac06893c6347e4c0fe9871d314c9eb5e176ff8..7bf7367e56ea03a671c55ba4a5c3382f3c975233 100644 (file)
@@ -29,6 +29,7 @@
 #define RPL_TRACESERVER_MSG            "206 %s Serv 1 0S 0C %s[%s@%s] *!*@%s :V%s"
 #define RPL_STATSLINKINFO_MSG          "211 %s %s %d %ld %ld %ld %ld :%ld"
 #define RPL_STATSCOMMANDS_MSG          "212 %s %s %ld %ld %ld"
+#define RPL_STATSXLINE_MSG             "216 %s %c %s %ld :%s"
 #define RPL_ENDOFSTATS_MSG             "219 %s %c :End of STATS report"
 #define RPL_UMODEIS_MSG                        "221 %s +%s"
 #define RPL_SERVLIST_MSG               "234 %s %s %s %s %d %d :%s"