]> jfr.im git - solanum.git/blobdiff - modules/m_names.c
m_list: fail on invalid parameters
[solanum.git] / modules / m_names.c
index b1e4b2792d8c6d3f5d6947d1c5895178f6017dd4..a5e1e9203ac6f8cd7a21f9acf0610008714e7a5c 100644 (file)
@@ -119,16 +119,10 @@ m_names(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_
 static void
 names_global(struct Client *source_p)
 {
-       int mlen;
-       int tlen;
-       int cur_len;
        bool dont_show = false;
-       rb_dlink_node *lp, *ptr;
+       rb_dlink_node *ptr;
        struct Client *target_p;
        struct Channel *chptr = NULL;
-       struct membership *msptr;
-       char buf[BUFSIZE];
-       char *t;
 
        /* first do all visible channels */
        RB_DLINK_FOREACH(ptr, global_channel_list.head)
@@ -136,13 +130,19 @@ names_global(struct Client *source_p)
                chptr = ptr->data;
                channel_member_names(chptr, source_p, 0);
        }
-       cur_len = mlen = sprintf(buf, form_str(RPL_NAMREPLY),
-                                   me.name, source_p->name, "*", "*");
-       t = buf + mlen;
+
+       send_multiline_init(source_p, " ", form_str(RPL_NAMREPLY),
+                                   me.name,
+                                   source_p->name,
+                                   "*",
+                                   "*");
 
        /* Second, do all clients in one big sweep */
        RB_DLINK_FOREACH(ptr, global_client_list.head)
        {
+               rb_dlink_node *ps, *pt;
+               struct membership *ms, *mt;
+
                target_p = ptr->data;
                dont_show = false;
 
@@ -156,13 +156,11 @@ names_global(struct Client *source_p)
                 * both were missed out above.  if the target is on a
                 * common channel with source, its already been shown.
                 */
-               RB_DLINK_FOREACH(lp, target_p->user->channel.head)
+               ITER_COMM_CHANNELS(ps, pt, source_p->user->channel.head, target_p->user->channel.head, ms, mt, chptr)
                {
-                       msptr = lp->data;
-                       chptr = msptr->chptr;
+                       if (!mt) continue;
 
-                       if(PubChannel(chptr) || IsMember(source_p, chptr) ||
-                          SecretChannel(chptr))
+                       if (PubChannel(chptr) || SecretChannel(chptr) || ms)
                        {
                                dont_show = true;
                                break;
@@ -172,18 +170,18 @@ names_global(struct Client *source_p)
                if(dont_show)
                        continue;
 
-               if((cur_len + NICKLEN + 2) > (BUFSIZE - 3))
+               if (IsCapable(source_p, CLICAP_USERHOST_IN_NAMES))
                {
-                       sendto_one(source_p, "%s", buf);
-                       cur_len = mlen;
-                       t = buf + mlen;
+                       send_multiline_item(source_p, "%s!%s@%s",
+                                       target_p->name,
+                                       target_p->username,
+                                       target_p->host);
+               }
+               else
+               {
+                       send_multiline_item(source_p, "%s", target_p->name);
                }
-
-               tlen = sprintf(t, "%s ", target_p->name);
-               cur_len += tlen;
-               t += tlen;
        }
 
-       if(cur_len > mlen)
-               sendto_one(source_p, "%s", buf);
+       send_multiline_fini(source_p, NULL);
 }