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 /* $ModDesc: Provides an extended version of /WHO for opers */
21 #include "inspircd_config.h"
23 #include "inspircd_io.h"
27 #include <ext/hash_map>
38 #include "helperfuncs.h"
43 extern ServerConfig* Config;
44 extern InspIRCd* ServerInstance;
45 extern user_hash clientlist;
46 extern chan_hash chanlist;
47 extern std::vector<userrec*> all_opers;
48 extern std::vector<userrec*> local_users;
50 class ModuleOperWho : public Module
54 ModuleOperWho(Server* Me) : Module::Module(Me)
59 virtual void Implements(char* List)
61 List[I_OnPreCommand] = 1;
64 virtual int OnPreCommand(std::string command, char **parameters, int pcnt, userrec *user, bool validated)
67 if ((!*user->oper) || (command != "WHO"))
75 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
78 Ptr = ((ucrec*)*(i->second->chans.begin()))->channel;
79 if (*i->second->awaymsg) {
84 if (*i->second->oper) { strlcat(tmp, "*", 9); }
85 WriteServ(user->fd,"352 %s %s %s %s %s %s %s :0 %s",user->nick, Ptr ? Ptr->name : "*", i->second->ident, i->second->host, i->second->server, i->second->nick, tmp, i->second->fullname);
87 WriteServ(user->fd,"315 %s * :End of /WHO list.",user->nick);
92 if ((!strcmp(parameters[0],"0")) || (!strcmp(parameters[0],"*")))
94 if ((user->chans.size()) && (((ucrec*)*(user->chans.begin()))->channel))
96 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
98 Ptr = ((ucrec*)*(i->second->chans.begin()))->channel;
99 // suggested by phidjit and FCS
100 if ((!common_channels(user,i->second)) && (isnick(i->second->nick)))
104 if (*i->second->awaymsg) {
105 strlcat(tmp, "G", 9);
107 strlcat(tmp, "H", 9);
109 if (*i->second->oper) { strlcat(tmp, "*", 9); }
110 WriteServ(user->fd,"352 %s %s %s %s %s %s %s :0 %s",user->nick, Ptr ? Ptr->name : "*", i->second->ident, i->second->host, i->second->server, i->second->nick, tmp, i->second->fullname);
116 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick , parameters[0]);
120 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
124 if (parameters[0][0] == '#')
126 Ptr = FindChan(parameters[0]);
129 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
131 if ((Ptr->HasUser(i->second)) && (isnick(i->second->nick)))
133 // Fix Bug #29 - Part 2..
135 if (*i->second->awaymsg) {
136 strlcat(tmp, "G", 9);
138 strlcat(tmp, "H", 9);
140 if (*i->second->oper) { strlcat(tmp, "*", 9); }
141 strlcat(tmp, cmode(i->second, Ptr),5);
142 WriteServ(user->fd,"352 %s %s %s %s %s %s %s :0 %s",user->nick, Ptr->name, i->second->ident, i->second->host, i->second->server, i->second->nick, tmp, i->second->fullname);
146 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
150 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
156 userrec* u = Find(parameters[0]);
159 // Bug Fix #29 -- Part 29..
162 strlcat(tmp, "G" ,9);
164 strlcat(tmp, "H" ,9);
166 if (*u->oper) { strlcat(tmp, "*" ,9); }
167 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
168 : "*", u->ident, u->dhost, u->server, u->nick, tmp, u->fullname);
170 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
176 if ((!strcmp(parameters[0],"0")) || (!strcmp(parameters[0],"*")) && (!strcmp(parameters[1],"o")))
178 for (std::vector<userrec*>::iterator i = all_opers.begin(); i != all_opers.end(); i++)
180 // If i were a rich man.. I wouldn't need to me making these bugfixes..
181 // But i'm a poor bastard with nothing better to do.
184 if (*oper->awaymsg) {
185 strlcat(tmp, "G" ,9);
187 strlcat(tmp, "H" ,9);
189 WriteServ(user->fd,"352 %s %s %s %s %s %s %s* :0 %s", user->nick, oper->chans.size() && ((ucrec*)*(oper->chans.begin()))->channel ?
190 ((ucrec*)*(oper->chans.begin()))->channel->name : "*", oper->ident, oper->host, oper->server, oper->nick, tmp, oper->fullname);
192 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
199 virtual ~ModuleOperWho()
203 virtual Version GetVersion()
205 return Version(1, 0, 0, 0, VF_VENDOR);
210 class ModuleOperWhoFactory : public ModuleFactory
213 ModuleOperWhoFactory()
217 ~ModuleOperWhoFactory()
221 virtual Module * CreateModule(Server* Me)
223 return new ModuleOperWho(Me);
229 extern "C" void * init_module( void )
231 return new ModuleOperWhoFactory;