+
+/**
+ * Handler for the IRC "WHO" command.
+ *
+ * See RFC 2812, 3.6.1 "Who query".
+ *
+ * @param Client The client from which this command has been received.
+ * @param Req Request structure with prefix and all parameters.
+ * @return CONNECTED or DISCONNECTED.
+ */
+GLOBAL bool
+IRC_WHO(CLIENT *Client, REQUEST *Req)
+{
+ bool only_ops;
+ CHANNEL *chan;
+
+ assert (Client != NULL);
+ assert (Req != NULL);
+
+ if (Req->argc > 2)
+ return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
+ Client_ID(Client), Req->command);
+
+ only_ops = false;
+
+ if (Req->argc == 2) {
+ if (strcmp(Req->argv[1], "o") == 0)
+ only_ops = true;
+#ifdef STRICT_RFC
+ else
+ return IRC_WriteStrClient(Client,
+ ERR_NEEDMOREPARAMS_MSG,
+ Client_ID(Client),
+ Req->command);
+#endif
+ }
+
+ IRC_SetPenalty(Client, 1);
+ if (Req->argc >= 1) {
+ /* Channel or mask given */
+ chan = Channel_Search(Req->argv[0]);
+ if (chan) {
+ /* Members of a channel have been requested */
+ IRC_SetPenalty(Client, 1);
+ return IRC_WHO_Channel(Client, chan, only_ops);
+ }
+ if (strcmp(Req->argv[0], "0") != 0) {
+ /* A mask has been given. But please note this RFC
+ * stupidity: "0" is same as no arguments ... */
+ IRC_SetPenalty(Client, 3);
+ return IRC_WHO_Mask(Client, Req->argv[0], only_ops);
+ }
+ }
+
+ /* No channel or (valid) mask given */
+ IRC_SetPenalty(Client, 2);
+ return IRC_WHO_Mask(Client, NULL, only_ops);