]> jfr.im git - solanum.git/blobdiff - modules/m_list.c
msg: remove last vestiges of the fakelag system. charybdis has never supported fakelag.
[solanum.git] / modules / m_list.c
index d60c832840418b94516db3bd377ba6220f8fceb4..caf8d33ddfb69049a44d494edfd7932933617225 100644 (file)
 #include "msg.h"
 #include "parse.h"
 #include "modules.h"
+#include "inline/stringops.h"
+#include "s_assert.h"
+#include "logger.h"
+#include "irc_radixtree.h"
 
 static rb_dlink_list safelisting_clients = { NULL, NULL, 0 };
 
 static int _modinit(void);
 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 int m_list(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static int mo_list(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
 
+static void list_one_channel(struct Client *source_p, struct Channel *chptr, int visible);
+
+static void safelist_one_channel(struct Client *source_p, struct Channel *chptr, struct ListClient *params);
 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, int operspy);
 
 struct Message list_msgtab = {
-       "LIST", 0, 0, 0, MFLG_SLOW,
+       "LIST", 0, 0, 0, 0,
        {mg_unreg, {m_list, 0}, mg_ignore, mg_ignore, mg_ignore, {mo_list, 0}}
 };
 
@@ -124,7 +130,7 @@ static void safelist_check_cliexit(hook_data_client_exit * hdata)
  * XXX - With SAFELIST, do we really need to continue pacing?
  *       In theory, the server cannot be lagged by this. --nenolod
  */
-static int m_list(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+static int m_list(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        static time_t last_used = 0L;
 
@@ -148,13 +154,13 @@ static int m_list(struct Client *client_p, struct Client *source_p, int parc, co
                        last_used = rb_current_time();
        }
 
-       return mo_list(client_p, source_p, parc, parv);
+       return mo_list(msgbuf_p, client_p, source_p, parc, parv);
 }
 
 /* mo_list()
  *      parv[1] = channel
  */
-static int mo_list(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+static int mo_list(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        struct ListClient *params;
        char *p;
@@ -191,11 +197,10 @@ static int mo_list(struct Client *client_p, struct Client *source_p, int parc, c
        /* Multiple channels, possibly with parameters. */
        params = rb_malloc(sizeof(struct ListClient));
 
-       /* XXX rather arbitrary -- jilles */
-       params->users_min = 3;
+       params->users_min = ConfigChannel.displayed_usercount;
        params->users_max = INT_MAX;
        params->operspy = operspy;
-       params->created_min = params->topic_min = 
+       params->created_min = params->topic_min =
                params->created_max = params->topic_max = 0;
 
        if (args && !EmptyString(args))
@@ -285,6 +290,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()
  *
@@ -349,6 +377,7 @@ static void safelist_client_release(struct Client *client_p)
 
        rb_dlinkFindDestroy(client_p, &safelisting_clients);
 
+       rb_free(client_p->localClient->safelist_data->chname);
        rb_free(client_p->localClient->safelist_data);
 
        client_p->localClient->safelist_data = NULL;
@@ -367,6 +396,7 @@ static void safelist_channel_named(struct Client *source_p, const char *name, in
 {
        struct Channel *chptr;
        char *p;
+       int visible;
 
        sendto_one(source_p, form_str(RPL_LISTSTART), me.name, source_p->name);
 
@@ -389,11 +419,9 @@ static void safelist_channel_named(struct Client *source_p, const char *name, in
                return;
        }
 
-       if (!SecretChannel(chptr) || IsMember(source_p, chptr) || operspy)
-               sendto_one(source_p, form_str(RPL_LIST), me.name, source_p->name,
-                          (operspy && SecretChannel(chptr)) ? "!" : "",
-                          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;
@@ -407,35 +435,33 @@ static void safelist_channel_named(struct Client *source_p, const char *name, in
  * side effects - a channel is listed if it meets the
  *                requirements
  */
-static void safelist_one_channel(struct Client *source_p, struct Channel *chptr)
+static void safelist_one_channel(struct Client *source_p, struct Channel *chptr, struct ListClient *params)
 {
-       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 && !params->operspy)
                return;
 
-       if ((unsigned int)chptr->members.length < safelist_data->users_min
-           || (unsigned int)chptr->members.length > safelist_data->users_max)
+       if ((unsigned int)chptr->members.length < params->users_min
+           || (unsigned int)chptr->members.length > params->users_max)
                return;
 
-       if (safelist_data->topic_min && chptr->topic_time < safelist_data->topic_min)
+       if (params->topic_min && chptr->topic_time < params->topic_min)
                return;
 
        /* If a topic TS is provided, don't show channels without a topic set. */
-       if (safelist_data->topic_max && (chptr->topic_time > safelist_data->topic_max
+       if (params->topic_max && (chptr->topic_time > params->topic_max
                || chptr->topic_time == 0))
                return;
 
-       if (safelist_data->created_min && chptr->channelts < safelist_data->created_min)
+       if (params->created_min && chptr->channelts < params->created_min)
                return;
 
-       if (safelist_data->created_max && chptr->channelts > safelist_data->created_max)
+       if (params->created_max && chptr->channelts > params->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);
 }
 
 /*
@@ -447,19 +473,20 @@ static void safelist_one_channel(struct Client *source_p, struct Channel *chptr)
  */
 static void safelist_iterate_client(struct Client *source_p)
 {
-       rb_dlink_node *ptr;
-       int iter;
+       struct Channel *chptr;
+       struct irc_radixtree_iteration_state iter;
 
-       for (iter = source_p->localClient->safelist_data->hash_indice; iter < CH_MAX; iter++)
+       IRC_RADIXTREE_FOREACH_FROM(chptr, &iter, channel_tree, source_p->localClient->safelist_data->chname)
        {
                if (safelist_sendq_exceeded(source_p->from) == YES)
                {
-                       source_p->localClient->safelist_data->hash_indice = iter;
+                       rb_free(source_p->localClient->safelist_data->chname);
+                       source_p->localClient->safelist_data->chname = rb_strdup(chptr->chname);
+
                        return;
                }
 
-               RB_DLINK_FOREACH(ptr, channelTable[iter].head) 
-                       safelist_one_channel(source_p, (struct Channel *) ptr->data);
+               safelist_one_channel(source_p, chptr, source_p->localClient->safelist_data);
        }
 
        safelist_client_release(source_p);
@@ -469,6 +496,6 @@ static void safelist_iterate_clients(void *unused)
 {
        rb_dlink_node *n, *n2;
 
-       RB_DLINK_FOREACH_SAFE(n, n2, safelisting_clients.head) 
+       RB_DLINK_FOREACH_SAFE(n, n2, safelisting_clients.head)
                safelist_iterate_client((struct Client *)n->data);
 }