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)
38 dlen = curlen = snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
41 char* ptr = list + dlen;
43 CUList *ulist= c->GetUsers();
45 /* Improvement by Brain - this doesnt change in value, so why was it inside
48 bool has_user = c->HasUser(user);
50 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
52 if ((!has_user) && (i->second->modes[UM_INVISIBLE]))
55 * user is +i, and source not on the channel, does not show
61 size_t ptrlen = snprintf(ptr, MAXBUF, "%s%s ", c->GetPrefixChar(i->second), i->second->nick);
68 if (curlen > (480-NICKMAX))
70 /* list overflowed into multiple numerics */
71 user->WriteServ(std::string(list));
73 /* reset our lengths */
74 dlen = curlen = snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
82 /* if whats left in the list isnt empty, send it */
85 user->WriteServ(std::string(list));
88 user->WriteServ("366 %s %s :End of /NAMES list.", user->nick, c->name);
93 class cmd_spylist : public command_t
96 cmd_spylist (InspIRCd* Instance) : command_t(Instance,"SPYLIST", 'o', 0)
98 this->source = "m_spy.so";
102 CmdResult Handle (const char** parameters, int pcnt, userrec *user)
104 ServerInstance->WriteOpers("*** Oper %s used SPYLIST to list +s/+p channels and keys.",user->nick);
105 user->WriteServ("321 %s Channel :Users Name",user->nick);
106 for (chan_hash::const_iterator i = ServerInstance->chanlist.begin(); i != ServerInstance->chanlist.end(); i++)
108 if (pcnt && !match(i->second->name, parameters[0]))
110 user->WriteServ("322 %s %s %d :[+%s] %s",user->nick,i->second->name,i->second->GetUserCounter(),i->second->ChanModes(true),i->second->topic);
112 user->WriteServ("323 %s :End of channel list.",user->nick);
114 /* Dont send out across the network */
119 class cmd_spynames : public command_t
122 cmd_spynames (InspIRCd* Instance) : command_t(Instance,"SPYNAMES", 'o', 0)
124 this->source = "m_spy.so";
125 syntax = "{<channel>{,<channel>}}";
128 CmdResult Handle (const char** parameters, int pcnt, userrec *user)
134 user->WriteServ("366 %s * :End of /NAMES list.",user->nick);
138 if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 0))
141 c = ServerInstance->FindChan(parameters[0]);
144 ServerInstance->WriteOpers("*** Oper %s used SPYNAMES to view the users on %s", user->nick, parameters[0]);
145 spy_userlist(user,c);
146 user->WriteServ("366 %s %s :End of /NAMES list.", user->nick, c->name);
150 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
157 class ModuleSpy : public Module
159 cmd_spylist *mycommand;
160 cmd_spynames *mycommand2;
162 ModuleSpy(InspIRCd* Me) : Module::Module(Me)
165 mycommand = new cmd_spylist(ServerInstance);
166 mycommand2 = new cmd_spynames(ServerInstance);
167 ServerInstance->AddCommand(mycommand);
168 ServerInstance->AddCommand(mycommand2);
175 virtual Version GetVersion()
177 return Version(1, 0, 0, 0, VF_VENDOR, API_VERSION);
182 class ModuleSpyFactory : public ModuleFactory
193 virtual Module * CreateModule(InspIRCd* Me)
195 return new ModuleSpy(Me);
201 extern "C" void * init_module( void )
203 return new ModuleSpyFactory;