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>
39 #include "inspstring.h"
43 #include "cull_list.h"
46 #define nspace __gnu_cxx
48 void spy_userlist(userrec *user,chanrec *c)
50 static char list[MAXBUF];
55 snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
57 CUList *ulist= c->GetUsers();
58 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
60 strlcat(list,c->GetStatusChar(i->second),MAXBUF);
61 strlcat(list,i->second->nick,MAXBUF);
62 strlcat(list," ",MAXBUF);
63 if (strlen(list)>(480-NICKMAX))
65 /* list overflowed into
66 * multiple numerics */
67 user->WriteServ(std::string(list));
68 snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
71 /* if whats left in the list isnt empty, send it */
72 if (list[strlen(list)-1] != ':')
74 user->WriteServ(std::string(list));
80 class cmd_spylist : public command_t
83 cmd_spylist (InspIRCd* Instance) : command_t(Instance,"SPYLIST", 'o', 0)
85 this->source = "m_spy.so";
89 void Handle (const char** parameters, int pcnt, userrec *user)
91 ServerInstance->WriteOpers("*** Oper %s used SPYLIST to list +s/+p channels and keys.",user->nick);
92 user->WriteServ("321 %s Channel :Users Name",user->nick);
93 for (chan_hash::const_iterator i = ServerInstance->chanlist.begin(); i != ServerInstance->chanlist.end(); i++)
95 user->WriteServ("322 %s %s %d :[+%s] %s",user->nick,i->second->name,i->second->GetUserCounter(),i->second->ChanModes(true),i->second->topic);
97 user->WriteServ("323 %s :End of channel list.",user->nick);
101 class cmd_spynames : public command_t
104 cmd_spynames (InspIRCd* Instance) : command_t(Instance,"SPYNAMES", 'o', 0)
106 this->source = "m_spy.so";
107 syntax = "{<channel>{,<channel>}}";
110 void Handle (const char** parameters, int pcnt, userrec *user)
116 user->WriteServ("366 %s * :End of /NAMES list.",user->nick);
120 if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 1))
123 ServerInstance->WriteOpers("*** Oper %s used SPYNAMES to view the users on %s",user->nick,parameters[0]);
125 c = ServerInstance->FindChan(parameters[0]);
128 spy_userlist(user,c);
129 user->WriteServ("366 %s %s :End of /NAMES list.", user->nick, c->name);
133 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
138 class ModuleSpy : public Module
140 cmd_spylist *mycommand;
141 cmd_spynames *mycommand2;
143 ModuleSpy(InspIRCd* Me) : Module::Module(Me)
146 mycommand = new cmd_spylist(ServerInstance);
147 mycommand2 = new cmd_spynames(ServerInstance);
148 ServerInstance->AddCommand(mycommand);
149 ServerInstance->AddCommand(mycommand2);
156 virtual Version GetVersion()
158 return Version(1, 0, 0, 0, VF_VENDOR);
163 class ModuleSpyFactory : public ModuleFactory
174 virtual Module * CreateModule(InspIRCd* Me)
176 return new ModuleSpy(Me);
182 extern "C" void * init_module( void )
184 return new ModuleSpyFactory;