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 * ---------------------------------------------------
19 #include "inspircd_config.h"
20 #include "inspircd_io.h"
24 #include <ext/hash_map>
42 #include "inspstring.h"
44 #include "helperfuncs.h"
46 #include "socketengine.h"
48 #include "command_parse.h"
52 extern ServerConfig* Config;
53 extern InspIRCd* ServerInstance;
55 extern std::vector<Module*> modules;
56 extern std::vector<ircd_module*> factory;
58 extern user_hash clientlist;
59 extern chan_hash chanlist;
60 extern whowas_hash whowas;
61 extern std::vector<userrec*> all_opers;
62 extern std::vector<userrec*> local_users;
63 extern userrec* fd_ref_table[MAX_DESCRIPTORS];
65 void cmd_who::Handle (char **parameters, int pcnt, userrec *user)
70 /* theres more to do here, but for now just close the socket */
73 if ((IS_SINGLE(parameters[0],'0')) || (IS_SINGLE(parameters[0],'*')))
75 if ((user->chans.size()) && (user->chans[0].channel))
78 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
80 Ptr = i->second->chans[0].channel;
81 // suggested by phidjit and FCS
82 if ((!common_channels(user,i->second)) && (isnick(i->second->nick)))
86 if (*i->second->awaymsg) {
87 charlcat(tmp, 'G', 9);
89 charlcat(tmp, 'H', 9);
91 if (*i->second->oper) { charlcat(tmp, '*', 9); }
92 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);
93 if (n_list++ > Config->MaxWhoResults)
95 WriteServ(user->fd,"523 %s WHO :Command aborted: More results than configured limit",user->nick);
103 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick , parameters[0]);
107 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
111 if (parameters[0][0] == '#')
113 Ptr = FindChan(parameters[0]);
117 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
119 if ((has_channel(i->second,Ptr)) && (isnick(i->second->nick)))
121 // Fix Bug #29 - Part 2..
123 if (*i->second->awaymsg) {
124 charlcat(tmp, 'G', 9);
126 charlcat(tmp, 'H', 9);
128 if (*i->second->oper) { charlcat(tmp, '*', 9); }
129 strlcat(tmp, cmode(i->second, Ptr),5);
130 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);
132 if (n_list > Config->MaxWhoResults)
134 WriteServ(user->fd,"523 %s WHO :Command aborted: More results than configured limit",user->nick);
140 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
144 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
149 userrec* u = Find(parameters[0]);
152 // Bug Fix #29 -- Part 29..
155 charlcat(tmp, 'G' ,9);
157 charlcat(tmp, 'H' ,9);
159 if (*u->oper) { charlcat(tmp, '*' ,9); }
160 WriteServ(user->fd,"352 %s %s %s %s %s %s %s :0 %s",user->nick, u->chans.size() && u->chans[0].channel ? u->chans[0].channel->name
161 : "*", u->ident, u->dhost, u->server, u->nick, tmp, u->fullname);
163 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
168 if ((IS_SINGLE(parameters[0],'0')) || (IS_SINGLE(parameters[0],'*')) && (IS_SINGLE(parameters[1],'o')))
170 for (std::vector<userrec*>::iterator i = all_opers.begin(); i != all_opers.end(); i++)
172 // If i were a rich man.. I wouldn't need to me making these bugfixes..
173 // But i'm a poor bastard with nothing better to do.
176 if (*oper->awaymsg) {
177 charlcat(tmp, 'G' ,9);
179 charlcat(tmp, 'H' ,9);
181 WriteServ(user->fd,"352 %s %s %s %s %s %s %s* :0 %s", user->nick, oper->chans.size() && oper->chans[0].channel ? oper->chans[0].channel->name
182 : "*", oper->ident, oper->dhost, oper->server, oper->nick, tmp, oper->fullname);
184 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);