1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
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 void cmd_who::Handle (const char** parameters, int pcnt, userrec *user)
37 if ((IS_SINGLE(parameters[0],'0')) || (IS_SINGLE(parameters[0],'*')))
39 if ((user->chans.size()) && (((ucrec*)*(user->chans.begin()))->channel))
42 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
44 Ptr = ((ucrec*)*(i->second->chans.begin()))->channel;
45 // suggested by phidjit and FCS
46 if ((!common_channels(user,i->second)) && (isnick(i->second->nick)))
50 if (*i->second->awaymsg) {
51 charlcat(tmp, 'G', 9);
53 charlcat(tmp, 'H', 9);
55 if (*i->second->oper) { charlcat(tmp, '*', 9); }
56 WriteServ(user->fd,"352 %s %s %s %s %s %s %s :0 %s",user->nick, Ptr ? Ptr->name : "*", i->second->ident, i->second->dhost, i->second->server, i->second->nick, tmp, i->second->fullname);
57 if (n_list++ > Config->MaxWhoResults)
59 WriteServ(user->fd,"523 %s WHO :Command aborted: More results than configured limit",user->nick);
67 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick , parameters[0]);
71 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
75 if (parameters[0][0] == '#')
77 Ptr = FindChan(parameters[0]);
81 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
83 if ((Ptr->HasUser(i->second)) && (isnick(i->second->nick)))
85 // Fix Bug #29 - Part 2..
87 if (*i->second->awaymsg) {
88 charlcat(tmp, 'G', 9);
90 charlcat(tmp, 'H', 9);
92 if (*i->second->oper) { charlcat(tmp, '*', 9); }
93 strlcat(tmp, cmode(i->second, Ptr),5);
94 WriteServ(user->fd,"352 %s %s %s %s %s %s %s :0 %s",user->nick, Ptr->name, i->second->ident, i->second->dhost, i->second->server, i->second->nick, tmp, i->second->fullname);
96 if (n_list > Config->MaxWhoResults)
98 WriteServ(user->fd,"523 %s WHO :Command aborted: More results than configured limit",user->nick);
104 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
108 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
113 userrec* u = Find(parameters[0]);
116 // Bug Fix #29 -- Part 29..
119 charlcat(tmp, 'G' ,9);
121 charlcat(tmp, 'H' ,9);
123 if (*u->oper) { charlcat(tmp, '*' ,9); }
124 WriteServ(user->fd,"352 %s %s %s %s %s %s %s :0 %s",user->nick, u->chans.size() && ((ucrec*)*(u->chans.begin()))->channel ? ((ucrec*)*(u->chans.begin()))->channel->name
125 : "*", u->ident, u->dhost, u->server, u->nick, tmp, u->fullname);
127 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
132 if ((IS_SINGLE(parameters[0],'0')) || (IS_SINGLE(parameters[0],'*')) && (IS_SINGLE(parameters[1],'o')))
134 for (std::vector<userrec*>::iterator i = all_opers.begin(); i != all_opers.end(); i++)
136 // If i were a rich man.. I wouldn't need to me making these bugfixes..
137 // But i'm a poor bastard with nothing better to do.
140 if (*oper->awaymsg) {
141 charlcat(tmp, 'G' ,9);
143 charlcat(tmp, 'H' ,9);
145 WriteServ(user->fd,"352 %s %s %s %s %s %s %s* :0 %s", user->nick, oper->chans.size() && ((ucrec*)*(oper->chans.begin()))->channel ? ((ucrec*)*(oper->chans.begin()))->channel->name
146 : "*", oper->ident, oper->dhost, oper->server, oper->nick, tmp, oper->fullname);
148 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);