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 /* $ModDesc: Provides an extended version of /WHO for opers */
21 #include "inspircd_config.h"
24 #include "helperfuncs.h"
27 extern user_hash clientlist;
28 extern std::vector<userrec*> all_opers;
30 class ModuleOperWho : public Module
34 ModuleOperWho(Server* Me) : Module::Module(Me)
39 virtual void Implements(char* List)
41 List[I_OnPreCommand] = 1;
44 virtual int OnPreCommand(const std::string &command, char **parameters, int pcnt, userrec *user, bool validated)
47 if ((!*user->oper) || (command != "WHO"))
55 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
58 Ptr = ((ucrec*)*(i->second->chans.begin()))->channel;
59 if (*i->second->awaymsg) {
64 if (*i->second->oper) { strlcat(tmp, "*", 9); }
65 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);
67 WriteServ(user->fd,"315 %s * :End of /WHO list.",user->nick);
72 if ((!strcmp(parameters[0],"0")) || (!strcmp(parameters[0],"*")))
74 if ((user->chans.size()) && (((ucrec*)*(user->chans.begin()))->channel))
76 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
78 Ptr = ((ucrec*)*(i->second->chans.begin()))->channel;
79 // suggested by phidjit and FCS
80 if ((!common_channels(user,i->second)) && (isnick(i->second->nick)))
84 if (*i->second->awaymsg) {
89 if (*i->second->oper) { strlcat(tmp, "*", 9); }
90 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);
96 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick , parameters[0]);
100 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
104 if (parameters[0][0] == '#')
106 Ptr = FindChan(parameters[0]);
109 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
111 if ((Ptr->HasUser(i->second)) && (isnick(i->second->nick)))
113 // Fix Bug #29 - Part 2..
115 if (*i->second->awaymsg) {
116 strlcat(tmp, "G", 9);
118 strlcat(tmp, "H", 9);
120 if (*i->second->oper) { strlcat(tmp, "*", 9); }
121 strlcat(tmp, cmode(i->second, Ptr),5);
122 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);
126 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
130 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
136 userrec* u = Find(parameters[0]);
139 // Bug Fix #29 -- Part 29..
142 strlcat(tmp, "G" ,9);
144 strlcat(tmp, "H" ,9);
146 if (*u->oper) { strlcat(tmp, "*" ,9); }
147 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
148 : "*", u->ident, u->dhost, u->server, u->nick, tmp, u->fullname);
150 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
156 if ((!strcmp(parameters[0],"0")) || (!strcmp(parameters[0],"*")) && (!strcmp(parameters[1],"o")))
158 for (std::vector<userrec*>::iterator i = all_opers.begin(); i != all_opers.end(); i++)
160 // If i were a rich man.. I wouldn't need to me making these bugfixes..
161 // But i'm a poor bastard with nothing better to do.
164 if (*oper->awaymsg) {
165 strlcat(tmp, "G" ,9);
167 strlcat(tmp, "H" ,9);
169 WriteServ(user->fd,"352 %s %s %s %s %s %s %s* :0 %s", user->nick, oper->chans.size() && ((ucrec*)*(oper->chans.begin()))->channel ?
170 ((ucrec*)*(oper->chans.begin()))->channel->name : "*", oper->ident, oper->host, oper->server, oper->nick, tmp, oper->fullname);
172 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
179 virtual ~ModuleOperWho()
183 virtual Version GetVersion()
185 return Version(1, 0, 0, 0, VF_VENDOR);
190 class ModuleOperWhoFactory : public ModuleFactory
193 ModuleOperWhoFactory()
197 ~ModuleOperWhoFactory()
201 virtual Module * CreateModule(Server* Me)
203 return new ModuleOperWho(Me);
209 extern "C" void * init_module( void )
211 return new ModuleOperWhoFactory;