* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id$
+ */
+/** @file
+ * @brief Support functions for /WHO-like commands.
+ * @version $Id$
*/
#include "config.h"
#include "hash.h"
#include "ircd.h"
#include "ircd_chattr.h"
-#include "ircd_policy.h"
+#include "ircd_features.h"
#include "ircd_reply.h"
#include "ircd_snprintf.h"
#include "ircd_string.h"
#include "s_user.h"
#include "send.h"
#include "struct.h"
-#include "support.h"
#include "sys.h"
#include "userload.h"
#include "version.h"
#include <sys/stat.h>
#include <unistd.h>
-/*
- * The function that actually prints out the WHO reply for a client found
+/** Send a WHO reply to a client who asked.
+ * @param[in] sptr Client who is searching for other users.
+ * @param[in] acptr Client who may be shown to \a sptr.
+ * @param[in] repchan Shared channel that provides visibility.
+ * @param[in] fields Bitmask of WHO_FIELD_* values, indicating what to show.
+ * @param[in] qrt Query type string (ignored unless \a fields & WHO_FIELD_QTY).
*/
void do_who(struct Client* sptr, struct Client* acptr, struct Channel* repchan,
int fields, char* qrt)
{
const char* p2 = HasHiddenHost(acptr) && !IsAnOper(sptr) ?
feature_str(FEAT_HIDDEN_IP) :
- ircd_ntoa((const char*) &(cli_ip(acptr)));
+ ircd_ntoa(&cli_ip(acptr));
*(p1++) = ' ';
while ((*p2) && (*(p1++) = *(p2++)));
}
if (!fields || (fields & WHO_FIELD_SER))
{
- char *p2;
-#ifdef HEAD_IN_SAND_WHO_SERVERNAME
- if (IsAnOper(sptr))
-#endif
- p2 = cli_name(cli_user(acptr)->server);
-#ifdef HEAD_IN_SAND_WHO_SERVERNAME
- else
- p2 = HEAD_IN_SAND_SERVERNAME;
-#endif
+ const char *p2 = (feature_bool(FEAT_HIS_WHO_SERVERNAME) && !IsAnOper(sptr)) ?
+ feature_str(FEAT_HIS_SERVERNAME) :
+ cli_name(cli_user(acptr)->server);
*(p1++) = ' ';
while ((*p2) && (*(p1++) = *(p2++)));
}
*(p1++) = 'G';
else
*(p1++) = 'H';
- if (IsAnOper(acptr) &&
- (HasPriv(acptr, PRIV_DISPLAY) || HasPriv(sptr, PRIV_SEE_OPERS)))
+ if SeeOper(sptr,acptr)
*(p1++) = '*';
if (fields) {
/* If you specified flags then we assume you know how to parse
*p1++ = ' ';
if (!fields)
*p1++ = ':'; /* Place colon here for default reply */
-#ifdef HEAD_IN_SAND_WHO_HOPCOUNT
- *p1++ = (sptr == acptr) ? '0' : '3';
-#else
- /* three digit hopcount maximum */
- p1 += ircd_snprintf(0, p1, 3, "%d", cli_hopcount(acptr));
-#endif
+ if (feature_bool(FEAT_HIS_WHO_HOPCOUNT) && !IsAnOper(sptr))
+ *p1++ = (sptr == acptr) ? '0' : '3';
+ else
+ /* three digit hopcount maximum */
+ p1 += ircd_snprintf(0, p1, 3, "%d", cli_hopcount(acptr));
}
if (fields & WHO_FIELD_IDL)
{
*p1++ = ' ';
- if (MyUser(acptr)) {
- p1 += ircd_snprintf(0, p1, 11, "%d",
- CurrentTime - cli_user(acptr)->last);
- }
- else {
- *p1++ = '0';
- }
+ if (MyUser(acptr) &&
+ (IsAnOper(sptr) || !feature_bool(FEAT_HIS_WHO_SERVERNAME) ||
+ acptr == sptr))
+ p1 += ircd_snprintf(0, p1, 11, "%d",
+ CurrentTime - cli_user(acptr)->last);
+ else
+ *p1++ = '0';
+ }
+
+ if (fields & WHO_FIELD_ACC)
+ {
+ char *p2 = cli_user(acptr)->account;
+ *(p1++) = ' ';
+ if (*p2)
+ while ((*p2) && (*(p1++) = *(p2++)));
+ else
+ *(p1++) = '0';
}
if (!fields || (fields & WHO_FIELD_REN))
send_reply(sptr, fields ? RPL_WHOSPCRPL : RPL_WHOREPLY, ++p1);
}
+/** Count number of users who match \a mask.
+ * @param[in] mask user\@host or user\@ip mask to check.
+ * @return Count of matching users.
+ */
int
count_users(char *mask)
{
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))));
+ ircd_ntoa(&cli_ip(acptr)));
if (!match(mask, namebuf) || !match(mask, ipbuf))
count++;