+/** Count number of users who match \a mask.
+ * @param[in] mask user\@host or user\@ip mask to check.
+ * @param[in] flags Bitmask possibly containing the value GLINE_LOCAL, to limit searches to this server.
+ * @return Count of matching users.
+ */
+static int
+count_users(char *mask, int flags)
+{
+ struct irc_in_addr ipmask;
+ struct Client *acptr;
+ int count = 0;
+ int ipmask_valid;
+ char namebuf[USERLEN + HOSTLEN + 2];
+ char ipbuf[USERLEN + SOCKIPLEN + 2];
+ unsigned char ipmask_len;
+
+ ipmask_valid = ipmask_parse(mask, &ipmask, &ipmask_len);
+ for (acptr = GlobalClientList; acptr; acptr = cli_next(acptr)) {
+ if (!IsUser(acptr))
+ continue;
+ if ((flags & GLINE_LOCAL) && !MyConnect(acptr))
+ continue;
+
+ ircd_snprintf(0, namebuf, sizeof(namebuf), "%s@%s",
+ cli_user(acptr)->username, cli_user(acptr)->realhost);
+ ircd_snprintf(0, ipbuf, sizeof(ipbuf), "%s@%s", cli_user(acptr)->username,
+ ircd_ntoa(&cli_ip(acptr)));
+
+ if (!match(mask, namebuf)
+ || !match(mask, ipbuf)
+ || (ipmask_valid && ipmask_check(&cli_ip(acptr), &ipmask, ipmask_len)))
+ count++;
+ }
+
+ return count;
+}
+
+/** Count number of users with a realname matching \a mask.
+ * @param[in] mask Wildcard mask to match against realnames.
+ * @return Count of matching users.
+ */
+static int
+count_realnames(const char *mask)
+{
+ struct Client *acptr;
+ int minlen;
+ int count;
+ char cmask[BUFSIZE];
+
+ count = 0;
+ matchcomp(cmask, &minlen, NULL, mask);
+ for (acptr = GlobalClientList; acptr; acptr = cli_next(acptr)) {
+ if (!IsUser(acptr))
+ continue;
+ if (strlen(cli_info(acptr)) < minlen)
+ continue;
+ if (!matchexec(cli_info(acptr), cmask, minlen))
+ count++;
+ }
+ return count;
+}
+