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 std::map<char*,char*> *ulist= c->GetUsers();
74 for (std::map<char*,char*>::iterator i = ulist->begin(); i != ulist->end(); i++)
77 userrec* otheruser = (userrec*)o;
78 strlcat(list,cmode(otheruser,c),MAXBUF);
79 strlcat(list,otheruser->nick,MAXBUF);
80 strlcat(list," ",MAXBUF);
81 if (strlen(list)>(480-NICKMAX))
83 /* list overflowed into
84 * multiple numerics */
85 WriteServ_NoFormat(user->fd,list);
86 snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
89 /* if whats left in the list isnt empty, send it */
90 if (list[strlen(list)-1] != ':')
92 WriteServ_NoFormat(user->fd,list);
98 class cmd_spylist : public command_t
101 cmd_spylist () : command_t("SPYLIST", 'o', 0)
103 this->source = "m_spy.so";
106 void Handle (char **parameters, int pcnt, userrec *user)
108 WriteOpers("*** Oper %s used SPYLIST to list +s/+p channels and keys.",user->nick);
109 WriteServ(user->fd,"321 %s Channel :Users Name",user->nick);
110 for (chan_hash::const_iterator i = chanlist.begin(); i != chanlist.end(); i++)
112 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);
114 WriteServ(user->fd,"323 %s :End of channel list.",user->nick);
118 class cmd_spynames : public command_t
121 cmd_spynames () : command_t("SPYNAMES", 'o', 0)
123 this->source = "m_spy.so";
126 void Handle (char **parameters, int pcnt, userrec *user)
132 WriteServ(user->fd,"366 %s * :End of /NAMES list.",user->nick);
136 if (ServerInstance->Parser->LoopCall(this,parameters,pcnt,user,0,pcnt-1,0))
139 WriteOpers("*** Oper %s used SPYNAMES to view the users on %s",user->nick,parameters[0]);
141 c = FindChan(parameters[0]);
144 spy_userlist(user,c);
145 WriteServ(user->fd,"366 %s %s :End of /NAMES list.", user->nick, c->name);
149 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
154 class ModuleSpy : public Module
156 cmd_spylist *mycommand;
157 cmd_spynames *mycommand2;
159 ModuleSpy(Server* Me) : Module::Module(Me)
162 mycommand = new cmd_spylist();
163 mycommand2 = new cmd_spynames();
164 Srv->AddCommand(mycommand);
165 Srv->AddCommand(mycommand2);
172 virtual Version GetVersion()
174 return Version(1, 0, 0, 0, VF_VENDOR);
179 class ModuleSpyFactory : public ModuleFactory
190 virtual Module * CreateModule(Server* Me)
192 return new ModuleSpy(Me);
198 extern "C" void * init_module( void )
200 return new ModuleSpyFactory;