Author: Isomer <isomer@coders.net>
[ircu2.10.12-pk.git] / ircd / m_names.c
index 160bbef086b124e045b2d5a18f42534b397213c1..525db66baf8f6dee6476e39445e72f86d0f02b3f 100644 (file)
@@ -114,26 +114,33 @@ int m_names(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
   struct Client *c2ptr;
   struct Membership* member;
   struct Channel *ch2ptr = 0;
-  int idx, flag, len, mlen;
-  char *s, *para = parc > 1 ? parv[1] : 0;
+  int idx;
+  int flag;
+  int len;
+  int mlen;
+  int needs_space;
+  char* s;
+  char* para = parc > 1 ? parv[1] : 0;
   char buf[BUFSIZE];
 
-  if (parc > 2 && hunt_server(1, cptr, sptr, "%s%s " TOK_NAMES " %s %s", 2, parc, parv))
+  if (parc > 2 && hunt_server_cmd(sptr, CMD_NAMES, cptr, 1, "%s %C", 2, parc,
+                                 parv))
     return 0;
 
   mlen = strlen(me.name) + 10 + strlen(sptr->name);
 
-  if (!EmptyString(para))
-  {
-    s = strchr(para, ',');
-    if (s)
-    {
-      parv[1] = ++s;
-      m_names(cptr, sptr, parc, parv);
-    }
-    clean_channelname(para);
-    ch2ptr = FindChannel(para);
+  if (EmptyString(para))
+    return 0;
+  else if (*para == '0')
+    *para = '\0';
+  
+  s = strchr(para, ',');
+  if (s) {
+    parv[1] = ++s;
+    m_names(cptr, sptr, parc, parv);
   }
+  clean_channelname(para);
+  ch2ptr = FindChannel(para);
 
   /*
    * First, do all visible channels (public and the one user self is)
@@ -163,13 +170,15 @@ int m_names(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
       *buf = '@';
     idx = len + 4;
     flag = 1;
+    needs_space = 0;
     for (member = chptr->members; member; member = member->next_member)
     {
       c2ptr = member->user;
-#ifndef GODMODE
-      if (sptr != c2ptr && IsInvisible(c2ptr) && !find_channel_member(sptr, chptr))
-        continue;
-#endif
+      if (needs_space) {
+       strcat(buf, " ");
+        idx++;
+      }
+      needs_space=1;
       if (IsZombie(member))
       {
         if (member->user != sptr)
@@ -191,24 +200,12 @@ int m_names(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
         idx++;
       }
       strcat(buf, c2ptr->name);
-      strcat(buf, " ");
       idx += strlen(c2ptr->name) + 1;
       flag = 1;
-#ifdef GODMODE
-      {
-        char yxx[6];
-        sprintf_irc(yxx, "%s%s", NumNick(c2ptr));
-        assert(c2ptr == findNUser(yxx));
-        sprintf_irc(buf + strlen(buf), "(%s) ", yxx);
-        idx += 6;
-      }
-      if (mlen + idx + NICKLEN + 11 > BUFSIZE)
-#else
       if (mlen + idx + NICKLEN + 5 > BUFSIZE)
-#endif
         /* space, modifier, nick, \r \n \0 */
       {
-        sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf);
+       send_reply(sptr, RPL_NAMREPLY, buf);
         strcpy(buf, "* ");
         ircd_strncpy(buf + 2, chptr->chname, len + 1);
         buf[len + 2] = 0;
@@ -219,15 +216,15 @@ int m_names(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
           *buf = '@';
         idx = len + 4;
         flag = 0;
+        needs_space=0;
       }
     }
     if (flag)
-      sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf);
+      send_reply(sptr, RPL_NAMREPLY, buf);
   }
   if (!EmptyString(para))
   {
-    sendto_one(sptr, rpl_str(RPL_ENDOFNAMES), me.name, parv[0],
-        ch2ptr ? ch2ptr->chname : para);
+    send_reply(sptr, RPL_ENDOFNAMES, ch2ptr ? ch2ptr->chname : para);
     return (1);
   }
 
@@ -289,15 +286,15 @@ int m_names(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     if (mlen + idx + NICKLEN + 3 > BUFSIZE)     /* space, \r\n\0 */
 #endif
     {
-      sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf);
+      send_reply(sptr, RPL_NAMREPLY, buf);
       strcpy(buf, "* * :");
       idx = 5;
       flag = 0;
     }
   }
   if (flag)
-    sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf);
-  sendto_one(sptr, rpl_str(RPL_ENDOFNAMES), me.name, parv[0], "*");
+    send_reply(sptr, RPL_NAMREPLY, buf);
+  send_reply(sptr, RPL_ENDOFNAMES, "*");
   return 1;
   return 0;
 }
@@ -318,7 +315,8 @@ int ms_names(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
   char *s, *para = parc > 1 ? parv[1] : 0;
   char buf[BUFSIZE];
 
-  if (parc > 2 && hunt_server(1, cptr, sptr, "%s%s " TOK_NAMES " %s %s", 2, parc, parv))
+  if (parc > 2 && hunt_server_cmd(sptr, CMD_NAMES, cptr, 1, "%s %C", 2, parc,
+                                 parv))
     return 0;
 
   mlen = strlen(me.name) + 10 + strlen(sptr->name);
@@ -408,7 +406,7 @@ int ms_names(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 #endif
         /* space, modifier, nick, \r \n \0 */
       {
-        sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf);
+       send_reply(sptr, RPL_NAMREPLY, buf);
         strcpy(buf, "* ");
         ircd_strncpy(buf + 2, chptr->chname, len + 1);
         buf[len + 2] = 0;
@@ -422,12 +420,11 @@ int ms_names(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
       }
     }
     if (flag)
-      sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf);
+      send_reply(sptr, RPL_NAMREPLY, buf);
   }
   if (!EmptyString(para))
   {
-    sendto_one(sptr, rpl_str(RPL_ENDOFNAMES), me.name, parv[0],
-        ch2ptr ? ch2ptr->chname : para);
+    send_reply(sptr, RPL_ENDOFNAMES, ch2ptr ? ch2ptr->chname : para);
     return (1);
   }
 
@@ -489,15 +486,15 @@ int ms_names(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     if (mlen + idx + NICKLEN + 3 > BUFSIZE)     /* space, \r\n\0 */
 #endif
     {
-      sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf);
+      send_reply(sptr, RPL_NAMREPLY, buf);
       strcpy(buf, "* * :");
       idx = 5;
       flag = 0;
     }
   }
   if (flag)
-    sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf);
-  sendto_one(sptr, rpl_str(RPL_ENDOFNAMES), me.name, parv[0], "*");
+    send_reply(sptr, RPL_NAMREPLY, buf);
+  send_reply(sptr, RPL_ENDOFNAMES, "*");
   return 1;
   return 0;
 }
@@ -520,7 +517,7 @@ int m_names(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
   char *s, *para = parc > 1 ? parv[1] : 0;
   char buf[BUFSIZE];
 
-  if (parc > 2 && hunt_server(1, cptr, sptr, "%s%s " TOK_NAMES " %s %s", 2, parc, parv))
+  if (parc > 2 && hunt_server(1, cptr, sptr, "%s%s " TOK_NAMES " %s %s", 2, parc, parv)) /* XXX DEAD */
     return 0;
 
   mlen = strlen(me.name) + 10 + strlen(sptr->name);
@@ -610,7 +607,7 @@ int m_names(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
 #endif
         /* space, modifier, nick, \r \n \0 */
       {
-        sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf);
+        sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf); /* XXX DEAD */
         strcpy(buf, "* ");
         ircd_strncpy(buf + 2, chptr->chname, len + 1);
         buf[len + 2] = 0;
@@ -624,11 +621,11 @@ int m_names(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
       }
     }
     if (flag)
-      sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf);
+      sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf); /* XXX DEAD */
   }
   if (!EmptyString(para))
   {
-    sendto_one(sptr, rpl_str(RPL_ENDOFNAMES), me.name, parv[0],
+    sendto_one(sptr, rpl_str(RPL_ENDOFNAMES), me.name, parv[0], /* XXX DEAD */
         ch2ptr ? ch2ptr->chname : para);
     return (1);
   }
@@ -691,15 +688,15 @@ int m_names(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
     if (mlen + idx + NICKLEN + 3 > BUFSIZE)     /* space, \r\n\0 */
 #endif
     {
-      sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf);
+      sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf); /* XXX DEAD */
       strcpy(buf, "* * :");
       idx = 5;
       flag = 0;
     }
   }
   if (flag)
-    sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf);
-  sendto_one(sptr, rpl_str(RPL_ENDOFNAMES), me.name, parv[0], "*");
+    sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf); /* XXX DEAD */
+  sendto_one(sptr, rpl_str(RPL_ENDOFNAMES), me.name, parv[0], "*"); /* XXX DEAD */
   return 1;
 }
 #endif /* 0 */