]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spy.cpp
Added <oper:swhois> to m_swhois, which will override <type:swhois> if specified
[user/henk/code/inspircd.git] / src / modules / m_spy.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                     E-mail:
7  *              <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *          the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
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.
20  */
21
22 using namespace std;
23
24 /* $ModDesc: Provides SPYLIST and SPYNAMES capability, allowing opers to see who's in +s channels */
25
26 #include "inspircd_config.h"
27 #include "users.h" 
28 #include "channels.h"
29 #include "modules.h"
30 #include "inspircd.h"
31 #include "wildcard.h"
32
33 void spy_userlist(userrec *user, chanrec *c)
34 {
35         char list[MAXBUF];
36         size_t dlen, curlen;
37
38         dlen = curlen = snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
39
40         int numusers = 0;
41         char* ptr = list + dlen;
42
43         CUList *ulist= c->GetUsers();
44
45         for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
46         {
47                 size_t ptrlen = snprintf(ptr, MAXBUF, "%s%s ", c->GetPrefixChar(i->second), i->second->nick);
48
49                 curlen += ptrlen;
50                 ptr += ptrlen;
51
52                 numusers++;
53
54                 if (curlen > (480-NICKMAX))
55                 {
56                         /* list overflowed into multiple numerics */
57                         user->WriteServ(std::string(list));
58
59                         /* reset our lengths */
60                         dlen = curlen = snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
61                         ptr = list + dlen;
62
63                         ptrlen = 0;
64                         numusers = 0;
65                 }
66         }
67
68         /* if whats left in the list isnt empty, send it */
69         if (numusers)
70         {
71                 user->WriteServ(std::string(list));
72         }
73
74         user->WriteServ("366 %s %s :End of /NAMES list.", user->nick, c->name);
75
76 }
77
78 /** Handle /SPYLIST
79  */
80 class cmd_spylist : public command_t
81 {
82   public:
83         cmd_spylist (InspIRCd* Instance) : command_t(Instance,"SPYLIST", 'o', 0)
84         {
85                 this->source = "m_spy.so";
86                 syntax = "";
87         }
88
89         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
90         {
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++)
94                 {
95                         if (pcnt && !match(i->second->name, parameters[0]))
96                                 continue;
97                         user->WriteServ("322 %s %s %d :[+%s] %s",user->nick,i->second->name,i->second->GetUserCounter(),i->second->ChanModes(true),i->second->topic);
98                 }
99                 user->WriteServ("323 %s :End of channel list.",user->nick);
100
101                 /* Dont send out across the network */
102                 return CMD_FAILURE;
103         }
104 };
105
106 /** Handle /SPYNAMES
107  */
108 class cmd_spynames : public command_t
109 {
110   public:
111         cmd_spynames (InspIRCd* Instance) : command_t(Instance,"SPYNAMES", 'o', 0)
112         {
113                 this->source = "m_spy.so";
114                 syntax = "{<channel>{,<channel>}}";
115         }
116
117         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
118         {
119                 chanrec* c = NULL;
120
121                 if (!pcnt)
122                 {
123                         user->WriteServ("366 %s * :End of /NAMES list.",user->nick);
124                         return CMD_FAILURE;
125                 }
126
127                 if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 0))
128                         return CMD_FAILURE;
129
130                 c = ServerInstance->FindChan(parameters[0]);
131                 if (c)
132                 {
133                         ServerInstance->WriteOpers("*** Oper %s used SPYNAMES to view the users on %s", user->nick, parameters[0]);
134                         spy_userlist(user,c);
135                         user->WriteServ("366 %s %s :End of /NAMES list.", user->nick, c->name);
136                 }
137                 else
138                 {
139                         user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
140                 }
141
142                 return CMD_FAILURE;
143         }
144 };
145
146 class ModuleSpy : public Module
147 {
148         cmd_spylist *mycommand;
149         cmd_spynames *mycommand2;
150  public:
151         ModuleSpy(InspIRCd* Me) : Module::Module(Me)
152         {
153                 
154                 mycommand = new cmd_spylist(ServerInstance);
155                 mycommand2 = new cmd_spynames(ServerInstance);
156                 ServerInstance->AddCommand(mycommand);
157                 ServerInstance->AddCommand(mycommand2);
158         }
159         
160         virtual ~ModuleSpy()
161         {
162         }
163         
164         virtual Version GetVersion()
165         {
166                 return Version(1, 1, 0, 0, VF_VENDOR, API_VERSION);
167         }
168 };
169
170
171 class ModuleSpyFactory : public ModuleFactory
172 {
173  public:
174         ModuleSpyFactory()
175         {
176         }
177         
178         ~ModuleSpyFactory()
179         {
180         }
181         
182         virtual Module * CreateModule(InspIRCd* Me)
183         {
184                 return new ModuleSpy(Me);
185         }
186         
187 };
188
189
190 extern "C" void * init_module( void )
191 {
192         return new ModuleSpyFactory;
193 }