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"
31 #include <ext/hash_map>
37 #include "helperfuncs.h"
39 #include "inspstring.h"
44 #include "cull_list.h"
47 #define nspace __gnu_cxx
51 extern ServerConfig* Config;
52 extern InspIRCd* ServerInstance;
53 extern chan_hash chanlist;
55 void spy_userlist(userrec *user,chanrec *c)
57 static char list[MAXBUF];
62 snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
64 CUList *ulist= c->GetUsers();
65 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
67 strlcat(list,cmode(i->second,c),MAXBUF);
68 strlcat(list,i->second->nick,MAXBUF);
69 strlcat(list," ",MAXBUF);
70 if (strlen(list)>(480-NICKMAX))
72 /* list overflowed into
73 * multiple numerics */
74 WriteServ_NoFormat(user->fd,list);
75 snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
78 /* if whats left in the list isnt empty, send it */
79 if (list[strlen(list)-1] != ':')
81 WriteServ_NoFormat(user->fd,list);
87 class cmd_spylist : public command_t
90 cmd_spylist () : command_t("SPYLIST", 'o', 0)
92 this->source = "m_spy.so";
95 void Handle (const char** parameters, int pcnt, userrec *user)
97 WriteOpers("*** Oper %s used SPYLIST to list +s/+p channels and keys.",user->nick);
98 WriteServ(user->fd,"321 %s Channel :Users Name",user->nick);
99 for (chan_hash::const_iterator i = chanlist.begin(); i != chanlist.end(); i++)
101 WriteServ(user->fd,"322 %s %s %d :[+%s] %s",user->nick,i->second->name,usercount(i->second),chanmodes(i->second,true),i->second->topic);
103 WriteServ(user->fd,"323 %s :End of channel list.",user->nick);
107 class cmd_spynames : public command_t
110 cmd_spynames () : command_t("SPYNAMES", 'o', 0)
112 this->source = "m_spy.so";
115 void Handle (const char** parameters, int pcnt, userrec *user)
121 WriteServ(user->fd,"366 %s * :End of /NAMES list.",user->nick);
125 if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 1))
128 WriteOpers("*** Oper %s used SPYNAMES to view the users on %s",user->nick,parameters[0]);
130 c = FindChan(parameters[0]);
133 spy_userlist(user,c);
134 WriteServ(user->fd,"366 %s %s :End of /NAMES list.", user->nick, c->name);
138 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
143 class ModuleSpy : public Module
145 cmd_spylist *mycommand;
146 cmd_spynames *mycommand2;
148 ModuleSpy(Server* Me) : Module::Module(Me)
151 mycommand = new cmd_spylist();
152 mycommand2 = new cmd_spynames();
153 Srv->AddCommand(mycommand);
154 Srv->AddCommand(mycommand2);
161 virtual Version GetVersion()
163 return Version(1, 0, 0, 0, VF_VENDOR);
168 class ModuleSpyFactory : public ModuleFactory
179 virtual Module * CreateModule(Server* Me)
181 return new ModuleSpy(Me);
187 extern "C" void * init_module( void )
189 return new ModuleSpyFactory;