1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 *the file COPYING for details.
14 * ---------------------------------------------------
17 #include "configreader.h"
22 #include "helperfuncs.h"
23 #include "commands/cmd_who.h"
25 extern ServerConfig* Config;
26 extern user_hash clientlist;
27 extern chan_hash chanlist;
28 extern std::vector<userrec*> all_opers;
30 /* get the last 'visible' chan of a user */
31 static char *getlastchanname(userrec *u)
33 for (std::vector<ucrec*>::const_iterator v = u->chans.begin(); v != u->chans.end(); v++)
35 ucrec* temp = (ucrec*)*v;
39 if (!temp->channel->IsModeSet('s'))
40 return temp->channel->name;
47 void cmd_who::Handle (const char** parameters, int pcnt, userrec *user)
51 * The <name> passed to WHO is matched against users' host, server, real
53 * Currently, we support WHO #chan, WHO nick, WHO 0, WHO *, and the addition of a 'o' flag, as per RFC.
56 bool opt_viewopersonly = false;
58 std::vector<std::string> whoresults;
59 std::string initial = "352 " + std::string(user->nick) + " ";
64 const char *iter = parameters[1];
71 opt_viewopersonly = true;
80 /* who on a channel? */
81 ch = FindChan(parameters[0]);
85 /* who on a channel. */
86 CUList *cu = ch->GetUsers();
88 for (CUList::iterator i = cu->begin(); i != cu->end(); i++)
90 /* opers only, please */
91 if (opt_viewopersonly && !*(i->second)->oper)
95 /* XXX - code duplication; this could be more efficient -- w00t */
96 std::string wholine = initial;
98 wholine = wholine + getlastchanname(i->second) + " " + i->second->ident + " " + i->second->dhost + " " +
99 i->second->server + " " + i->second->nick + " ";
102 if (*(i->second)->awaymsg)
112 if (*(i->second)->oper)
117 wholine = wholine + cmode(i->second, ch) + " :0 " + i->second->fullname;
118 whoresults.push_back(wholine);
123 /* uhggle. who on .. something else. */
124 userrec *u = Find(parameters[0]);
128 /* who on a single user */
129 std::string wholine = initial;
131 wholine = wholine + getlastchanname(u) + " " + u->ident + " " + u->dhost + " " +
132 u->server + " " + u->nick + " ";
150 wholine = wholine + cmode(u, ch) + " :0 " + u->fullname;
151 whoresults.push_back(wholine);
154 if (*parameters[0] == '*' || *parameters[0] == '0')
156 if (!opt_viewopersonly && !*user->oper)
157 return; /* No way, jose */
159 if (opt_viewopersonly)
161 for (std::vector<userrec*>::iterator i = all_opers.begin(); i != all_opers.end(); i++)
163 userrec* oper = (userrec*)*i;
165 std::string wholine = initial;
167 wholine = wholine + getlastchanname(oper) + " " + oper->ident + " " + oper->dhost + " " +
168 oper->server + " " + oper->nick + " ";
186 wholine = wholine + cmode(oper, ch) + " :0 " + oper->fullname;
187 whoresults.push_back(wholine);
192 for (user_hash::iterator i = clientlist.begin(); i != clientlist.end(); i++)
194 std::string wholine = initial;
196 wholine = wholine + getlastchanname(i->second) + " " + i->second->ident + " " + i->second->dhost + " " +
197 i->second->server + " " + i->second->nick + " ";
200 if (*(i->second)->awaymsg)
210 if (*(i->second)->oper)
215 wholine = wholine + cmode(i->second, ch) + " :0 " + i->second->fullname;
216 whoresults.push_back(wholine);