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 */
26 #include "inspircd_config.h"
33 void spy_userlist(userrec *user,chanrec *c)
35 static char list[MAXBUF];
40 snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
42 CUList *ulist= c->GetUsers();
43 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
45 strlcat(list,c->GetPrefixChar(i->second),MAXBUF);
46 strlcat(list,i->second->nick,MAXBUF);
47 strlcat(list," ",MAXBUF);
48 if (strlen(list)>(480-NICKMAX))
50 /* list overflowed into
51 * multiple numerics */
52 user->WriteServ(std::string(list));
53 snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
56 /* if whats left in the list isnt empty, send it */
57 if (list[strlen(list)-1] != ':')
59 user->WriteServ(std::string(list));
65 class cmd_spylist : public command_t
68 cmd_spylist (InspIRCd* Instance) : command_t(Instance,"SPYLIST", 'o', 0)
70 this->source = "m_spy.so";
74 CmdResult Handle (const char** parameters, int pcnt, userrec *user)
76 ServerInstance->WriteOpers("*** Oper %s used SPYLIST to list +s/+p channels and keys.",user->nick);
77 user->WriteServ("321 %s Channel :Users Name",user->nick);
78 for (chan_hash::const_iterator i = ServerInstance->chanlist.begin(); i != ServerInstance->chanlist.end(); i++)
80 if (pcnt && !match(i->second->name, parameters[0]))
82 user->WriteServ("322 %s %s %d :[+%s] %s",user->nick,i->second->name,i->second->GetUserCounter(),i->second->ChanModes(true),i->second->topic);
84 user->WriteServ("323 %s :End of channel list.",user->nick);
86 /* Dont send out across the network */
91 class cmd_spynames : public command_t
94 cmd_spynames (InspIRCd* Instance) : command_t(Instance,"SPYNAMES", 'o', 0)
96 this->source = "m_spy.so";
97 syntax = "{<channel>{,<channel>}}";
100 CmdResult Handle (const char** parameters, int pcnt, userrec *user)
106 user->WriteServ("366 %s * :End of /NAMES list.",user->nick);
110 if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 1))
113 ServerInstance->WriteOpers("*** Oper %s used SPYNAMES to view the users on %s",user->nick,parameters[0]);
115 c = ServerInstance->FindChan(parameters[0]);
118 spy_userlist(user,c);
119 user->WriteServ("366 %s %s :End of /NAMES list.", user->nick, c->name);
123 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
130 class ModuleSpy : public Module
132 cmd_spylist *mycommand;
133 cmd_spynames *mycommand2;
135 ModuleSpy(InspIRCd* Me) : Module::Module(Me)
138 mycommand = new cmd_spylist(ServerInstance);
139 mycommand2 = new cmd_spynames(ServerInstance);
140 ServerInstance->AddCommand(mycommand);
141 ServerInstance->AddCommand(mycommand2);
148 virtual Version GetVersion()
150 return Version(1, 0, 0, 0, VF_VENDOR);
155 class ModuleSpyFactory : public ModuleFactory
166 virtual Module * CreateModule(InspIRCd* Me)
168 return new ModuleSpy(Me);
174 extern "C" void * init_module( void )
176 return new ModuleSpyFactory;