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 std::vector<userrec*> all_opers;
61 extern std::vector<userrec*> local_users;
62 extern userrec* fd_ref_table[MAX_DESCRIPTORS];
64 void cmd_who::Handle (char **parameters, int pcnt, userrec *user)
69 /* theres more to do here, but for now just close the socket */
72 if ((IS_SINGLE(parameters[0],'0')) || (IS_SINGLE(parameters[0],'*')))
74 if ((user->chans.size()) && (((ucrec*)*(user->chans.begin()))->channel))
77 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
79 Ptr = ((ucrec*)*(i->second->chans.begin()))->channel;
80 // suggested by phidjit and FCS
81 if ((!common_channels(user,i->second)) && (isnick(i->second->nick)))
85 if (*i->second->awaymsg) {
86 charlcat(tmp, 'G', 9);
88 charlcat(tmp, 'H', 9);
90 if (*i->second->oper) { charlcat(tmp, '*', 9); }
91 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);
92 if (n_list++ > Config->MaxWhoResults)
94 WriteServ(user->fd,"523 %s WHO :Command aborted: More results than configured limit",user->nick);
102 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick , parameters[0]);
106 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
110 if (parameters[0][0] == '#')
112 Ptr = FindChan(parameters[0]);
116 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
118 if ((Ptr->HasUser(i->second)) && (isnick(i->second->nick)))
120 // Fix Bug #29 - Part 2..
122 if (*i->second->awaymsg) {
123 charlcat(tmp, 'G', 9);
125 charlcat(tmp, 'H', 9);
127 if (*i->second->oper) { charlcat(tmp, '*', 9); }
128 strlcat(tmp, cmode(i->second, Ptr),5);
129 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);
131 if (n_list > Config->MaxWhoResults)
133 WriteServ(user->fd,"523 %s WHO :Command aborted: More results than configured limit",user->nick);
139 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
143 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
148 userrec* u = Find(parameters[0]);
151 // Bug Fix #29 -- Part 29..
154 charlcat(tmp, 'G' ,9);
156 charlcat(tmp, 'H' ,9);
158 if (*u->oper) { charlcat(tmp, '*' ,9); }
159 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
160 : "*", u->ident, u->dhost, u->server, u->nick, tmp, u->fullname);
162 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
167 if ((IS_SINGLE(parameters[0],'0')) || (IS_SINGLE(parameters[0],'*')) && (IS_SINGLE(parameters[1],'o')))
169 for (std::vector<userrec*>::iterator i = all_opers.begin(); i != all_opers.end(); i++)
171 // If i were a rich man.. I wouldn't need to me making these bugfixes..
172 // But i'm a poor bastard with nothing better to do.
175 if (*oper->awaymsg) {
176 charlcat(tmp, 'G' ,9);
178 charlcat(tmp, 'H' ,9);
180 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
181 : "*", oper->ident, oper->dhost, oper->server, oper->nick, tmp, oper->fullname);
183 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);