2 * IRC - Internet Relay Chat, ircd/s_user.c (formerly ircd/s_msg.c)
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
6 * See file AUTHORS in IRC package for additional names of
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 1, or (at your option)
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 #include "ircd_chattr.h"
34 #include "ircd_string.h"
39 #include "querycmds.h"
46 #include "sprintf_irc.h"
55 #include <arpa/inet.h> /* inet_ntoa */
64 * The function that actually prints out the WHO reply for a client found
66 void do_who(struct Client* sptr, struct Client* acptr, struct Channel* repchan,
67 int fields, char* qrt)
70 struct Channel *chptr = repchan;
72 static char buf1[512];
73 /* NOTE: with current fields list and sizes this _cannot_ overrun,
74 and also the message finally sent shouldn't ever be truncated */
79 /* If we don't have a channel and we need one... try to find it,
80 unless the listing is for a channel service, we already know
81 that there are no common channels, thus use PubChannel and not
83 if (!chptr && (!fields || (fields & (WHO_FIELD_CHA | WHO_FIELD_FLA))) &&
84 !IsChannelService(acptr))
86 struct Membership* chan;
87 for (chan = acptr->user->channel; chan && !chptr; chan = chan->next_channel)
88 if (PubChannel(chan->channel) &&
89 (acptr == sptr || !IsZombie(chan)))
90 chptr = chan->channel;
93 /* Place the fields one by one in the buffer and send it
94 note that fields == NULL means "default query" */
96 if (fields & WHO_FIELD_QTY) /* Query type */
102 while ((*qrt) && (*(p1++) = *(qrt++)));
105 if (!fields || (fields & WHO_FIELD_CHA))
109 if ((p2 = (chptr ? chptr->chname : NULL)))
110 while ((*p2) && (*(p1++) = *(p2++)));
115 if (!fields || (fields & WHO_FIELD_UID))
117 char *p2 = acptr->user->username;
119 while ((*p2) && (*(p1++) = *(p2++)));
122 if (fields & WHO_FIELD_NIP)
124 const char* p2 = ircd_ntoa((const char*) &acptr->ip);
126 while ((*p2) && (*(p1++) = *(p2++)));
129 if (!fields || (fields & WHO_FIELD_HOS))
131 char *p2 = acptr->user->host;
133 while ((*p2) && (*(p1++) = *(p2++)));
136 if (!fields || (fields & WHO_FIELD_SER))
138 char *p2 = acptr->user->server->name;
140 while ((*p2) && (*(p1++) = *(p2++)));
143 if (!fields || (fields & WHO_FIELD_NIC))
145 char *p2 = acptr->name;
147 while ((*p2) && (*(p1++) = *(p2++)));
150 if (!fields || (fields & WHO_FIELD_FLA))
153 if (acptr->user->away)
159 if (chptr && is_chan_op(acptr, chptr))
161 else if (chptr && has_voice(acptr, chptr))
163 else if (chptr && is_zombie(acptr, chptr))
169 if (IsInvisible(acptr))
171 if (SendWallops(acptr))
173 if (SendDebug(acptr))
178 if (!fields || (fields & WHO_FIELD_DIS))
182 *p1++ = ':'; /* Place colon here for default reply */
183 p1 = sprintf_irc(p1, "%d", acptr->hopcount);
186 if (!fields || (fields & WHO_FIELD_REN))
188 char *p2 = acptr->info;
191 *p1++ = ':'; /* Place colon here for special reply */
192 while ((*p2) && (*(p1++) = *(p2++)));
195 /* The first char will always be an useless blank and we
196 need to terminate buf1 */
199 sendto_one(sptr, rpl_str(fields ? RPL_WHOSPCRPL : RPL_WHOREPLY),
200 me.name, sptr->name, ++p1);