Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / ircd / m_ison.c
index d97691d1d3066f6ffc428cd8f97f7f6bd13f1abd..1dfa6f2c5b850fb8ea5c4f15c66103cdc952c47f 100644 (file)
  *            note:   it is guaranteed that parv[0]..parv[parc-1] are all
  *                    non-NULL pointers.
  */
-#if 0
-/*
- * No need to include handlers.h here the signatures must match
- * and we don't need to force a rebuild of all the handlers everytime
- * we add a new one to the list. --Bleep
- */
-#include "handlers.h"
-#endif /* 0 */
+#include "config.h"
+
 #include "client.h"
 #include "hash.h"
 #include "ircd.h"
 #include "ircd_reply.h"
 #include "ircd_string.h"
+#include "msgq.h"
 #include "numeric.h"
 #include "send.h"
 
@@ -118,30 +113,31 @@ int m_ison(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
   struct Client* acptr;
   char*          name;
   char*          p = 0;
-  char           buf[BUFSIZE];
-  char*          iter = buf;
-  char*          end = &buf[BUFSIZE - NICKLEN - 4];
+  struct MsgBuf* mb;
+  int i;
 
   if (parc < 2)
     return need_more_params(sptr, "ISON");
 
-  iter = sprintf_irc(buf, rpl_str(RPL_ISON), me.name, sptr->name);
+  mb = msgq_make(sptr, rpl_str(RPL_ISON), cli_name(&me), cli_name(sptr));
 
-  for (name = ircd_strtok(&p, parv[1], " "); name; name = ircd_strtok(&p, 0, " ")) {
-    if ((acptr = FindUser(name))) {
-      strcpy(iter, acptr->name);
-      iter += strlen(iter);
-      if (iter >= end)
-        break;
-      *iter++ = ' ';
+  for (i = 1; i < parc; i++) {
+    for (name = ircd_strtok(&p, parv[i], " "); name;
+        name = ircd_strtok(&p, 0, " ")) {
+      if ((acptr = FindUser(name))) {
+       if (msgq_bufleft(mb) < strlen(cli_name(acptr)) + 1) {
+         send_buffer(sptr, mb, 0); /* send partial response */
+         msgq_clean(mb); /* then do another round */
+         mb = msgq_make(sptr, rpl_str(RPL_ISON), cli_name(&me),
+                        cli_name(sptr));
+       }
+       msgq_append(0, mb, "%s ", cli_name(acptr));
+      }
     }
   }
-  *iter = '\0';
-  if (' ' == *--iter)
-    *iter = '\0';
 
-  send_buffer(sptr, buf);
+  send_buffer(sptr, mb, 0); /* send response */
+  msgq_clean(mb);
+
   return 0;
 }
-
-