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 /* NO, THIS MODULE DOES NOT SPY ON CHANNELS OR USERS.
18 * IT JUST ALLOWS OPERS TO SEE +s CHANNELS IN LIST AND
19 * WHOIS, WHICH IS SUPPORTED BY MOST IRCDS IN CORE.
24 /* $ModDesc: Provides SPYLIST and SPYNAMES capability, allowing opers to see who's in +s channels */
30 #include "inspircd_config.h"
32 #include <ext/hash_map>
41 #include "helperfuncs.h"
43 #include "inspstring.h"
48 #include "cull_list.h"
52 #define nspace __gnu_cxx
60 extern ServerConfig* Config;
61 extern InspIRCd* ServerInstance;
62 extern chan_hash chanlist;
64 void spy_userlist(userrec *user,chanrec *c)
66 static char list[MAXBUF];
71 snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
73 CUList *ulist= c->GetUsers();
74 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
76 strlcat(list,cmode(i->second,c),MAXBUF);
77 strlcat(list,i->second->nick,MAXBUF);
78 strlcat(list," ",MAXBUF);
79 if (strlen(list)>(480-NICKMAX))
81 /* list overflowed into
82 * multiple numerics */
83 WriteServ_NoFormat(user->fd,list);
84 snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
87 /* if whats left in the list isnt empty, send it */
88 if (list[strlen(list)-1] != ':')
90 WriteServ_NoFormat(user->fd,list);
96 class cmd_spylist : public command_t
99 cmd_spylist () : command_t("SPYLIST", 'o', 0)
101 this->source = "m_spy.so";
104 void Handle (char **parameters, int pcnt, userrec *user)
106 WriteOpers("*** Oper %s used SPYLIST to list +s/+p channels and keys.",user->nick);
107 WriteServ(user->fd,"321 %s Channel :Users Name",user->nick);
108 for (chan_hash::const_iterator i = chanlist.begin(); i != chanlist.end(); i++)
110 WriteServ(user->fd,"322 %s %s %d :[+%s] %s",user->nick,i->second->name,usercount_i(i->second),chanmodes(i->second,true),i->second->topic);
112 WriteServ(user->fd,"323 %s :End of channel list.",user->nick);
116 class cmd_spynames : public command_t
119 cmd_spynames () : command_t("SPYNAMES", 'o', 0)
121 this->source = "m_spy.so";
124 void Handle (char **parameters, int pcnt, userrec *user)
130 WriteServ(user->fd,"366 %s * :End of /NAMES list.",user->nick);
134 if (ServerInstance->Parser->LoopCall(this,parameters,pcnt,user,0,pcnt-1,0))
137 WriteOpers("*** Oper %s used SPYNAMES to view the users on %s",user->nick,parameters[0]);
139 c = FindChan(parameters[0]);
142 spy_userlist(user,c);
143 WriteServ(user->fd,"366 %s %s :End of /NAMES list.", user->nick, c->name);
147 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
152 class ModuleSpy : public Module
154 cmd_spylist *mycommand;
155 cmd_spynames *mycommand2;
157 ModuleSpy(Server* Me) : Module::Module(Me)
160 mycommand = new cmd_spylist();
161 mycommand2 = new cmd_spynames();
162 Srv->AddCommand(mycommand);
163 Srv->AddCommand(mycommand2);
170 virtual Version GetVersion()
172 return Version(1, 0, 0, 0, VF_VENDOR);
177 class ModuleSpyFactory : public ModuleFactory
188 virtual Module * CreateModule(Server* Me)
190 return new ModuleSpy(Me);
196 extern "C" void * init_module( void )
198 return new ModuleSpyFactory;