Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / ircd / whocmds.c
index 69829a8fe7bccd592a3200bb11f046f6ec678963..39a9bc7507a0b1a1e0e1a5b81612db39ab55d83b 100644 (file)
@@ -30,7 +30,9 @@
 #include "hash.h"
 #include "ircd.h"
 #include "ircd_chattr.h"
+#include "ircd_policy.h"
 #include "ircd_reply.h"
+#include "ircd_snprintf.h"
 #include "ircd_string.h"
 #include "list.h"
 #include "match.h"
@@ -195,7 +197,12 @@ void do_who(struct Client* sptr, struct Client* acptr, struct Channel* repchan,
     *p1++ = ' ';
     if (!fields)
       *p1++ = ':';              /* Place colon here for default reply */
+#ifdef HEAD_IN_SAND_WHO_HOPCOUNT
+    strcat(p1, sptr == acptr ? "0" : "3");
+    p1++;
+#else
     p1 = sprintf_irc(p1, "%d", cli_hopcount(acptr));
+#endif
   }
 
   if (fields & WHO_FIELD_IDL)
@@ -225,3 +232,26 @@ void do_who(struct Client* sptr, struct Client* acptr, struct Channel* repchan,
   send_reply(sptr, fields ? RPL_WHOSPCRPL : RPL_WHOREPLY, ++p1);
 }
 
+int
+count_users(char *mask)
+{
+  struct Client *acptr;
+  int count = 0;
+  char namebuf[USERLEN + HOSTLEN + 2];
+  char ipbuf[USERLEN + 16 + 2];
+
+  for (acptr = GlobalClientList; acptr; acptr = cli_next(acptr)) {
+    if (!IsUser(acptr))
+      continue;
+
+    ircd_snprintf(0, namebuf, sizeof(namebuf), "%s@%s",
+                 cli_user(acptr)->username, cli_user(acptr)->host);
+    ircd_snprintf(0, ipbuf, sizeof(ipbuf), "%s@%s", cli_user(acptr)->username,
+                 ircd_ntoa((const char *) &(cli_ip(acptr))));
+
+    if (!match(mask, namebuf) || !match(mask, ipbuf))
+      count++;
+  }
+
+  return count;
+}