1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2005 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 * ---------------------------------------------------
19 #include "inspircd_config.h"
21 #include "inspircd_io.h"
25 #include <ext/hash_map>
43 #include "inspstring.h"
45 #include "helperfuncs.h"
47 #include "socketengine.h"
49 #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[65536];
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 ((!strcmp(parameters[0],"0")) || (!strcmp(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 (strcmp(i->second->awaymsg, "")) {
91 if (strchr(i->second->modes,'o')) { strlcat(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);
94 if (n_list > Config->MaxWhoResults)
96 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,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
112 if (parameters[0][0] == '#')
114 Ptr = FindChan(parameters[0]);
118 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
120 if ((has_channel(i->second,Ptr)) && (isnick(i->second->nick)))
122 // Fix Bug #29 - Part 2..
124 if (strcmp(i->second->awaymsg, "")) {
125 strlcat(tmp, "G", 9);
127 strlcat(tmp, "H", 9);
129 if (strchr(i->second->modes,'o')) { strlcat(tmp, "*", 9); }
130 strlcat(tmp, cmode(i->second, Ptr),5);
131 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);
133 if (n_list > Config->MaxWhoResults)
135 WriteServ(user->fd,"523 %s WHO :Command aborted: More results than configured limit",user->nick);
141 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
145 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
150 userrec* u = Find(parameters[0]);
153 // Bug Fix #29 -- Part 29..
155 if (strcmp(u->awaymsg, "")) {
156 strlcat(tmp, "G" ,9);
158 strlcat(tmp, "H" ,9);
160 if (strchr(u->modes,'o')) { strlcat(tmp, "*" ,9); }
161 WriteServ(user->fd,"352 %s %s %s %s %s %s %s :0 %s",user->nick, u->chans.size() ? u->chans[0].channel->name
162 : "*", u->ident, u->dhost, u->server, u->nick, tmp, u->fullname);
164 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
169 if ((!strcmp(parameters[0],"0")) || (!strcmp(parameters[0],"*")) && (!strcmp(parameters[1],"o")))
171 for (std::vector<userrec*>::iterator i = all_opers.begin(); i != all_opers.end(); i++)
173 // If i were a rich man.. I wouldn't need to me making these bugfixes..
174 // But i'm a poor bastard with nothing better to do.
177 if (strcmp(oper->awaymsg, "")) {
178 strlcat(tmp, "G" ,9);
180 strlcat(tmp, "H" ,9);
182 WriteServ(user->fd,"352 %s %s %s %s %s %s %s* :0 %s", user->nick, oper->chans.size() ? oper->chans[0].channel->name
183 : "*", oper->ident, oper->dhost, oper->server, oper->nick, tmp, oper->fullname);
185 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);