]> jfr.im git - solanum.git/blobdiff - modules/m_list.c
m_info: Correct description of general::client_exit like in example confs.
[solanum.git] / modules / m_list.c
index 9bb4d5e6b49811d32aec6d18e3b0cf97750130e1..2737282fb408f9ef7e52c5afd7a222ca2ce532e0 100644 (file)
 #include "s_conf.h"
 #include "s_newconf.h"
 #include "s_serv.h"
+#include "supported.h"
 #include "send.h"
 #include "msg.h"
 #include "parse.h"
 #include "modules.h"
+#include "inline/stringops.h"
 
 static rb_dlink_list safelisting_clients = { NULL, NULL, 0 };
 
@@ -56,13 +58,15 @@ static void _moddeinit(void);
 static int m_list(struct Client *, struct Client *, int, const char **);
 static int mo_list(struct Client *, struct Client *, int, const char **);
 
+static void list_one_channel(struct Client *source_p, struct Channel *chptr, int visible);
+
 static void safelist_check_cliexit(hook_data_client_exit * hdata);
 static void safelist_client_instantiate(struct Client *, struct ListClient *);
 static void safelist_client_release(struct Client *);
 static void safelist_one_channel(struct Client *source_p, struct Channel *chptr);
 static void safelist_iterate_client(struct Client *source_p);
 static void safelist_iterate_clients(void *unused);
-static void safelist_channel_named(struct Client *source_p, const char *name);
+static void safelist_channel_named(struct Client *source_p, const char *name, int operspy);
 
 struct Message list_msgtab = {
        "LIST", 0, 0, 0, MFLG_SLOW,
@@ -84,12 +88,26 @@ static int _modinit(void)
 {
        iterate_clients_ev = rb_event_add("safelist_iterate_clients", safelist_iterate_clients, NULL, 3);
 
+       /* ELIST=[tokens]:
+        *
+        * M = mask search
+        * N = !mask search
+        * U = user count search (< >)
+        * C = creation time search (C> C<)
+        * T = topic search (T> T<)
+        */
+       add_isupport("SAFELIST", isupport_string, "");
+       add_isupport("ELIST", isupport_string, "CTU");
+
        return 0;
 }
 
 static void _moddeinit(void)
 {
        rb_event_delete(iterate_clients_ev);
+
+       delete_isupport("SAFELIST");
+       delete_isupport("ELIST");
 }
 
 static void safelist_check_cliexit(hook_data_client_exit * hdata)
@@ -142,8 +160,10 @@ static int m_list(struct Client *client_p, struct Client *source_p, int parc, co
 static int mo_list(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        struct ListClient *params;
-       char *p, *args;
+       char *p;
+       char *args = NULL;
        int i;
+       int operspy = 0;
 
        if (source_p->localClient->safelist_data != NULL)
        {
@@ -152,10 +172,22 @@ static int mo_list(struct Client *client_p, struct Client *source_p, int parc, c
                return 0;
        }
 
+       if (parc > 1)
+       {
+               args = LOCAL_COPY(parv[1]);
+       }
+
+       if (args && *args == '!' && IsOperSpy(source_p))
+       {
+               args++;
+               report_operspy(source_p, "LIST", args);
+               operspy = 1;
+       }
+
        /* Single channel. */
-       if (parc > 1 && IsChannelName(parv[1]))
+       if (args && IsChannelName(args))
        {
-               safelist_channel_named(source_p, parv[1]);
+               safelist_channel_named(source_p, args, operspy);
                return 0;
        }
 
@@ -165,14 +197,12 @@ static int mo_list(struct Client *client_p, struct Client *source_p, int parc, c
        /* XXX rather arbitrary -- jilles */
        params->users_min = 3;
        params->users_max = INT_MAX;
-       params->operspy = 0;
+       params->operspy = operspy;
        params->created_min = params->topic_min = 
                params->created_max = params->topic_max = 0;
 
-       if (parc > 1 && !EmptyString(parv[1]))
+       if (args && !EmptyString(args))
        {
-               args = LOCAL_COPY(parv[1]);
-
                /* Cancel out default minimum. */
                params->users_min = 0;
 
@@ -245,12 +275,6 @@ static int mo_list(struct Client *client_p, struct Client *source_p, int parc, c
                                        }
                                }
                        }
-                       /* Only accept operspy as the first option. */
-                       else if (*args == '!' && IsOperSpy(source_p) && i == 0)
-                       {
-                               params->operspy = 1;
-                               report_operspy(source_p, "LIST", p);
-                       }
 
                        if (EmptyString(p))
                                break;
@@ -264,6 +288,29 @@ static int mo_list(struct Client *client_p, struct Client *source_p, int parc, c
        return 0;
 }
 
+/*
+ * list_one_channel()
+ *
+ * inputs       - client pointer, channel pointer, whether normally visible
+ * outputs      - none
+ * side effects - a channel is listed
+ */
+static void list_one_channel(struct Client *source_p, struct Channel *chptr,
+               int visible)
+{
+       char topic[TOPICLEN + 1];
+
+       if (chptr->topic != NULL)
+               rb_strlcpy(topic, chptr->topic, sizeof topic);
+       else
+               topic[0] = '\0';
+       strip_colour(topic);
+       sendto_one(source_p, form_str(RPL_LIST), me.name, source_p->name,
+                  visible ? "" : "!",
+                  chptr->chname, rb_dlink_list_length(&chptr->members),
+                  topic);
+}
+
 /*
  * safelist_sendq_exceeded()
  *
@@ -338,41 +385,40 @@ static void safelist_client_release(struct Client *client_p)
 /*
  * safelist_channel_named()
  *
- * inputs       - client pointer, channel name
+ * inputs       - client pointer, channel name, operspy
  * outputs      - none
  * side effects - a named channel is listed
  */
-static void safelist_channel_named(struct Client *source_p, const char *name)
+static void safelist_channel_named(struct Client *source_p, const char *name, int operspy)
 {
        struct Channel *chptr;
        char *p;
-       char *n = LOCAL_COPY(name);
+       int visible;
 
        sendto_one(source_p, form_str(RPL_LISTSTART), me.name, source_p->name);
 
-       if ((p = strchr(n, ',')))
+       if ((p = strchr(name, ',')))
                *p = '\0';
 
-       if (*n == '\0')
+       if (*name == '\0')
        {
                sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), name);
                sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name);
                return;
        }
 
-       chptr = find_channel(n);
+       chptr = find_channel(name);
 
        if (chptr == NULL)
        {
-               sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), n);
+               sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), name);
                sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name);
                return;
        }
 
-       if (!SecretChannel(chptr) || IsMember(source_p, chptr))
-               sendto_one(source_p, form_str(RPL_LIST), me.name, source_p->name, "",
-                          chptr->chname, rb_dlink_list_length(&chptr->members),
-                          chptr->topic == NULL ? "" : chptr->topic);
+       visible = !SecretChannel(chptr) || IsMember(source_p, chptr);
+       if (visible || operspy)
+               list_one_channel(source_p, chptr, visible);
 
        sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name);
        return;
@@ -389,8 +435,10 @@ static void safelist_channel_named(struct Client *source_p, const char *name)
 static void safelist_one_channel(struct Client *source_p, struct Channel *chptr)
 {
        struct ListClient *safelist_data = source_p->localClient->safelist_data;
+       int visible;
 
-       if (SecretChannel(chptr) && !IsMember(source_p, chptr) && !safelist_data->operspy)
+       visible = !SecretChannel(chptr) || IsMember(source_p, chptr);
+       if (!visible && !safelist_data->operspy)
                return;
 
        if ((unsigned int)chptr->members.length < safelist_data->users_min
@@ -411,10 +459,7 @@ static void safelist_one_channel(struct Client *source_p, struct Channel *chptr)
        if (safelist_data->created_max && chptr->channelts > safelist_data->created_max)
                return;
 
-       sendto_one(source_p, form_str(RPL_LIST), me.name, source_p->name,
-                  (safelist_data->operspy && SecretChannel(chptr)) ? "!" : "",
-                  chptr->chname, rb_dlink_list_length(&chptr->members),
-                  chptr->topic == NULL ? "" : chptr->topic);
+       list_one_channel(source_p, chptr, visible);
 }
 
 /*