- for (c = Client_First(); c != NULL; c = Client_Next(c)) {
- if (Client_Type(c) != CLIENT_USER)
- continue;
- /*
- * RFC 2812, 3.6.1:
- * In the absence of the parameter, all visible (users who aren't
- * invisible (user mode +i) and who don't have a common channel
- * with the requesting client) are listed.
- *
- * The same result can be achieved by using a [sic] of "0"
- * or any wildcard which will end up matching every visible user.
- *
- * The [sic] passed to WHO is matched against users' host, server, real name and
- * nickname if the channel cannot be found.
- */
- client_modes = Client_Modes(c);
- if (strchr(client_modes, 'i'))
+ /* No channel or (valid) mask given */
+ IRC_SetPenalty(Client, 2);
+ return IRC_WHO_Mask(Client, NULL, only_ops);
+} /* IRC_WHO */
+
+
+/**
+ * Generate WHOIS reply of one actual client.
+ *
+ * @param Client The client from which this command has been received.
+ * @param from The client requesting the information ("originator").
+ * @param c The client of which information should be returned.
+ * @returns CONNECTED or DISCONNECTED.
+ */
+static bool
+IRC_WHOIS_SendReply(CLIENT *Client, CLIENT *from, CLIENT *c)
+{
+ char str[LINE_LEN + 1];
+ CL2CHAN *cl2chan;
+ CHANNEL *chan;
+
+ /* Nick, user, hostname and client info */
+ if (!IRC_WriteStrClient(from, RPL_WHOISUSER_MSG, Client_ID(from),
+ Client_ID(c), Client_User(c),
+ Client_HostnameCloaked(c), Client_Info(c)))
+ return DISCONNECTED;
+
+ /* Server */
+ if (!IRC_WriteStrClient(from, RPL_WHOISSERVER_MSG, Client_ID(from),
+ Client_ID(c), Client_ID(Client_Introducer(c)),
+ Client_Info(Client_Introducer(c))))
+ return DISCONNECTED;
+
+ /* Channels */
+ snprintf(str, sizeof(str), RPL_WHOISCHANNELS_MSG,
+ Client_ID(from), Client_ID(c));
+ cl2chan = Channel_FirstChannelOf(c);
+ while (cl2chan) {
+ chan = Channel_GetChannel(cl2chan);
+ assert(chan != NULL);
+
+ /* next */
+ cl2chan = Channel_NextChannelOf(c, cl2chan);
+
+ /* Secret channel? */
+ if (strchr(Channel_Modes(chan), 's')
+ && !Channel_IsMemberOf(chan, Client))