Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / ircd / m_names.c
index 072b567dd94bdec4894635fea9eaace16c6bb409..1ccb30489a66e6b7565c19592840cb0c651d7b80 100644 (file)
@@ -79,6 +79,8 @@
  *            note:   it is guaranteed that parv[0]..parv[parc-1] are all
  *                    non-NULL pointers.
  */
+#include "config.h"
+
 #if 0
 /*
  * No need to include handlers.h here the signatures must match
 #include <assert.h>
 #include <string.h>
 
-#define NAMES_ALL 1 /* List all users in channel */
-#define NAMES_VIS 2 /* List only visible users in non-secret channels */
-
 /*
  *  Sends a suitably formatted 'names' reply to 'sptr' consisting of nicks within
  *  'chptr', depending on 'filter'.
  *
  *  NAMES_ALL - Lists all users on channel.
  *  NAMES_VIS - Only list visible (-i) users. --Gte (04/06/2000).
+ *  NAMES_EON - When OR'd with the other two, adds an 'End of Names' numeric
+ *              used by m_join
  *
  */
 
@@ -124,6 +125,10 @@ void do_names(struct Client* sptr, struct Channel* chptr, int filter)
   char buf[BUFSIZE];
   struct Client *c2ptr;
   struct Membership* member;
+  
+  assert(chptr);
+  assert(sptr);
+  assert((filter&NAMES_ALL) != (filter&NAMES_VIS));
 
   /* Tag Pub/Secret channels accordingly. */
 
@@ -146,13 +151,13 @@ void do_names(struct Client* sptr, struct Channel* chptr, int filter)
 
   /* Iterate over all channel members, and build up the list. */
 
-  mlen = strlen(me.name) + 10 + strlen(sptr->name);
+  mlen = strlen(cli_name(&me)) + 10 + strlen(cli_name(sptr));
   
   for (member = chptr->members; member; member = member->next_member)
   {
     c2ptr = member->user;
 
-    if ((filter == NAMES_VIS) && IsInvisible(c2ptr))
+    if (((filter&NAMES_VIS)!=0) && IsInvisible(c2ptr))
       continue;
 
     if (IsZombie(member) && member->user != sptr)
@@ -178,13 +183,13 @@ void do_names(struct Client* sptr, struct Channel* chptr, int filter)
       strcat(buf, "+");
       idx++;
     }
-    strcat(buf, c2ptr->name);
-    idx += strlen(c2ptr->name) + 1;
+    strcat(buf, cli_name(c2ptr));
+    idx += strlen(cli_name(c2ptr)) + 1;
     flag = 1;
     if (mlen + idx + NICKLEN + 5 > BUFSIZE)
       /* space, modifier, nick, \r \n \0 */
     { 
-      sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, sptr->name, buf);
+      send_reply(sptr, RPL_NAMREPLY, buf);
       strcpy(buf, "* ");
       ircd_strncpy(buf + 2, chptr->chname, len + 1);
       buf[len + 2] = 0;
@@ -200,6 +205,8 @@ void do_names(struct Client* sptr, struct Channel* chptr, int filter)
   }
   if (flag)
     send_reply(sptr, RPL_NAMREPLY, buf); 
+  if (filter&NAMES_EON)
+    send_reply(sptr, RPL_ENDOFNAMES, chptr->chname);
 }
 
 /*
@@ -246,7 +253,7 @@ int m_names(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     struct Channel *ch3ptr;
     char buf[BUFSIZE]; 
 
-    mlen = strlen(me.name) + 10 + strlen(sptr->name);
+    mlen = strlen(cli_name(&me)) + 10 + strlen(cli_name(sptr));
 
     /* List all visible channels/visible members */ 
 
@@ -269,14 +276,14 @@ int m_names(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     idx = 5;
     flag = 0;
 
-    for (c2ptr = GlobalClientList; c2ptr; c2ptr = c2ptr->next)
+    for (c2ptr = GlobalClientList; c2ptr; c2ptr = cli_next(c2ptr))
     {
       int showflag = 0;
 
       if (!IsUser(c2ptr) || (sptr != c2ptr && IsInvisible(c2ptr)))
         continue;
 
-      member = c2ptr->user->channel; 
+      member = cli_user(c2ptr)->channel;
 
       while (member)
       {
@@ -291,9 +298,9 @@ int m_names(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
       if (showflag)               /* Have we already shown them? */
         continue;
  
-      strcat(buf, c2ptr->name);
+      strcat(buf, cli_name(c2ptr));
       strcat(buf, " ");
-      idx += strlen(c2ptr->name) + 1;
+      idx += strlen(cli_name(c2ptr)) + 1;
       flag = 1;
 
       if (mlen + idx + NICKLEN + 3 > BUFSIZE)     /* space, \r\n\0 */
@@ -317,30 +324,28 @@ int m_names(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 
   clean_channelname(para);
   chptr = FindChannel(para); 
-  member = find_member_link(chptr, sptr); 
-  if (member)
-  { 
-    if (chptr) do_names(sptr, chptr, NAMES_ALL);
-    if (!EmptyString(para))
-    {
-      send_reply(sptr, RPL_ENDOFNAMES, chptr ? chptr->chname : para);
-      return 1;
+
+  if (chptr) {
+    member = find_member_link(chptr, sptr);
+    if (member)
+    { 
+      do_names(sptr, chptr, NAMES_ALL);
+      if (!EmptyString(para))
+      {
+        send_reply(sptr, RPL_ENDOFNAMES, chptr ? chptr->chname : para);
+        return 1;
+      }
     }
-  }
-    else
-  {
-    /*
-     *  Special Case 3: User isn't on this channel, show all visible users, in 
-     *  non secret channels.
-     */
-     
-    if (chptr) do_names(sptr, chptr, NAMES_VIS);
-    if (!EmptyString(para))
+      else 
     {
-      send_reply(sptr, RPL_ENDOFNAMES, para);
-      return 1;
-    }
+      /*
+       *  Special Case 3: User isn't on this channel, show all visible users, in 
+       *  non secret channels.
+       */ 
+      do_names(sptr, chptr, NAMES_VIS);
+    } 
+  } else { /* Channel doesn't exist. */ 
+      send_reply(sptr, RPL_ENDOFNAMES, para); 
   }
   return 1;
 }
@@ -389,7 +394,7 @@ int ms_names(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     struct Channel *ch3ptr;
     char buf[BUFSIZE]; 
 
-    mlen = strlen(me.name) + 10 + strlen(sptr->name);
+    mlen = strlen(cli_name(&me)) + 10 + strlen(cli_name(sptr));
 
     /* List all visible channels/visible members */ 
 
@@ -412,14 +417,14 @@ int ms_names(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     idx = 5;
     flag = 0;
 
-    for (c2ptr = GlobalClientList; c2ptr; c2ptr = c2ptr->next)
+    for (c2ptr = GlobalClientList; c2ptr; c2ptr = cli_next(c2ptr))
     {
       int showflag = 0;
 
       if (!IsUser(c2ptr) || (sptr != c2ptr && IsInvisible(c2ptr)))
         continue;
 
-      member = c2ptr->user->channel; 
+      member = cli_user(c2ptr)->channel; 
 
       while (member)
       {
@@ -434,9 +439,9 @@ int ms_names(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
       if (showflag)               /* Have we already shown them? */
         continue;
  
-      strcat(buf, c2ptr->name);
+      strcat(buf, cli_name(c2ptr));
       strcat(buf, " ");
-      idx += strlen(c2ptr->name) + 1;
+      idx += strlen(cli_name(c2ptr)) + 1;
       flag = 1;
 
       if (mlen + idx + NICKLEN + 3 > BUFSIZE)     /* space, \r\n\0 */
@@ -460,32 +465,29 @@ int ms_names(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 
   clean_channelname(para);
   chptr = FindChannel(para); 
-  member = find_member_link(chptr, sptr); 
-  if (member)
-  { 
-    if (chptr) do_names(sptr, chptr, NAMES_ALL);
-    if (!EmptyString(para))
-    {
-      send_reply(sptr, RPL_ENDOFNAMES, chptr ? chptr->chname : para);
-      return 1;
-    }
 
-  }
-    else
-  {
-    /*
-     *  Special Case 3: User isn't on this channel, show all visible users, in 
-     *  non secret channels.
-     */
-     
-    if (chptr) do_names(sptr, chptr, NAMES_VIS);
-    if (!EmptyString(para))
-    {
-      send_reply(sptr, RPL_ENDOFNAMES, para);
-      return 1;
+  if (chptr) {
+    member = find_member_link(chptr, sptr);
+    if (member)
+    { 
+      do_names(sptr, chptr, NAMES_ALL);
+      if (!EmptyString(para))
+      {
+        send_reply(sptr, RPL_ENDOFNAMES, chptr ? chptr->chname : para);
+        return 1;
+      }
     }
-  } 
+      else 
+    {
+      /*
+       *  Special Case 3: User isn't on this channel, show all visible users, in 
+       *  non secret channels.
+       */ 
+      do_names(sptr, chptr, NAMES_VIS);
+    } 
+  } else { /* Channel doesn't exist. */ 
+      send_reply(sptr, RPL_ENDOFNAMES, para); 
+  }
   return 1;
 }