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 * ---------------------------------------------------
20 * DEVOICE module for InspIRCd
21 * Syntax: /DEVOICE <#chan>
24 /* $ModDesc: Provides an extended version of /WHO for opers */
26 #include "inspircd_config.h"
28 #include "inspircd_io.h"
32 #include <ext/hash_map>
43 #include "helperfuncs.h"
47 extern ServerConfig* Config;
48 extern InspIRCd* ServerInstance;
49 extern user_hash clientlist;
50 extern chan_hash chanlist;
51 extern std::vector<userrec*> all_opers;
52 extern std::vector<userrec*> local_users;
54 class ModuleOperWho : public Module
58 ModuleOperWho(Server* Me) : Module::Module(Me)
63 virtual void Implements(char* List)
65 List[I_OnPreCommand] = 1;
68 virtual int OnPreCommand(std::string command, char **parameters, int pcnt, userrec *user, bool validated)
79 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
82 Ptr = i->second->chans[0].channel;
83 if (*i->second->awaymsg) {
88 if (*i->second->oper) { strlcat(tmp, "*", 9); }
89 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);
91 WriteServ(user->fd,"315 %s * :End of /WHO list.",user->nick);
96 if ((!strcmp(parameters[0],"0")) || (!strcmp(parameters[0],"*")))
98 if ((user->chans.size()) && (user->chans[0].channel))
101 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
103 Ptr = i->second->chans[0].channel;
104 // suggested by phidjit and FCS
105 if ((!common_channels(user,i->second)) && (isnick(i->second->nick)))
109 if (*i->second->awaymsg) {
110 strlcat(tmp, "G", 9);
112 strlcat(tmp, "H", 9);
114 if (*i->second->oper) { strlcat(tmp, "*", 9); }
115 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);
121 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick , parameters[0]);
125 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
129 if (parameters[0][0] == '#')
131 Ptr = FindChan(parameters[0]);
135 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
137 if ((has_channel(i->second,Ptr)) && (isnick(i->second->nick)))
139 // Fix Bug #29 - Part 2..
141 if (*i->second->awaymsg) {
142 strlcat(tmp, "G", 9);
144 strlcat(tmp, "H", 9);
146 if (*i->second->oper) { strlcat(tmp, "*", 9); }
147 strlcat(tmp, cmode(i->second, Ptr),5);
148 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);
152 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
156 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
161 userrec* u = Find(parameters[0]);
164 // Bug Fix #29 -- Part 29..
167 strlcat(tmp, "G" ,9);
169 strlcat(tmp, "H" ,9);
171 if (*u->oper) { strlcat(tmp, "*" ,9); }
172 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
173 : "*", u->ident, u->dhost, u->server, u->nick, tmp, u->fullname);
175 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
180 if ((!strcmp(parameters[0],"0")) || (!strcmp(parameters[0],"*")) && (!strcmp(parameters[1],"o")))
182 for (std::vector<userrec*>::iterator i = all_opers.begin(); i != all_opers.end(); i++)
184 // If i were a rich man.. I wouldn't need to me making these bugfixes..
185 // But i'm a poor bastard with nothing better to do.
188 if (*oper->awaymsg) {
189 strlcat(tmp, "G" ,9);
191 strlcat(tmp, "H" ,9);
193 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
194 : "*", oper->ident, oper->host, oper->server, oper->nick, tmp, oper->fullname);
196 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
202 virtual ~ModuleOperWho()
206 virtual Version GetVersion()
208 return Version(1, 0, 0, 0, VF_VENDOR);
213 class ModuleOperWhoFactory : public ModuleFactory
216 ModuleOperWhoFactory()
220 ~ModuleOperWhoFactory()
224 virtual Module * CreateModule(Server* Me)
226 return new ModuleOperWho(Me);
232 extern "C" void * init_module( void )
234 return new ModuleOperWhoFactory;