]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spy.cpp
Gah, im forgetting to SetMode!
[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 <stdio.h>
27 #include <vector>
28 #include <deque>
29 #include "globals.h"
30 #include "inspircd_config.h"
31 #ifdef GCC3
32 #include <ext/hash_map>
33 #else
34 #include <hash_map>
35 #endif
36 #include "users.h" 
37 #include "channels.h"
38 #include "modules.h"
39 #include "commands.h"
40 #include "socket.h"
41 #include "helperfuncs.h"
42 #include "inspircd.h"
43 #include "inspstring.h"
44 #include "hashcomp.h"
45 #include "message.h"
46 #include "xline.h"
47 #include "typedefs.h"
48 #include "cull_list.h"
49 #include "aes.h"
50
51 #ifdef GCC3
52 #define nspace __gnu_cxx
53 #else
54 #define nspace std
55 #endif
56
57
58 static Server *Srv;
59
60 extern ServerConfig* Config;
61 extern InspIRCd* ServerInstance;
62 extern chan_hash chanlist;
63
64 void spy_userlist(userrec *user,chanrec *c)
65 {
66         static char list[MAXBUF];
67
68         if ((!c) || (!user))
69                 return;
70
71         snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
72
73         CUList *ulist= c->GetUsers();
74         for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
75         {
76                 strlcat(list,cmode(i->second,c),MAXBUF);
77                 strlcat(list,i->second->nick,MAXBUF);
78                 strlcat(list," ",MAXBUF);
79                 if (strlen(list)>(480-NICKMAX))
80                 {
81                         /* list overflowed into
82                          * multiple numerics */
83                         WriteServ_NoFormat(user->fd,list);
84                         snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
85                 }
86         }
87         /* if whats left in the list isnt empty, send it */
88         if (list[strlen(list)-1] != ':')
89         {
90                 WriteServ_NoFormat(user->fd,list);
91         }
92 }
93
94
95
96 class cmd_spylist : public command_t
97 {
98   public:
99         cmd_spylist () : command_t("SPYLIST", 'o', 0)
100         {
101                 this->source = "m_spy.so";
102         }
103
104         void Handle (char **parameters, int pcnt, userrec *user)
105         {
106                 WriteOpers("*** Oper %s used SPYLIST to list +s/+p channels and keys.",user->nick);
107                 WriteServ(user->fd,"321 %s Channel :Users Name",user->nick);
108                 for (chan_hash::const_iterator i = chanlist.begin(); i != chanlist.end(); i++)
109                 {
110                         WriteServ(user->fd,"322 %s %s %d :[+%s] %s",user->nick,i->second->name,usercount(i->second),chanmodes(i->second,true),i->second->topic);
111                 }
112                 WriteServ(user->fd,"323 %s :End of channel list.",user->nick);
113         }
114 };
115
116 class cmd_spynames : public command_t
117 {
118   public:
119           cmd_spynames () : command_t("SPYNAMES", 'o', 0)
120           {
121                   this->source = "m_spy.so";
122           }
123
124           void Handle (char **parameters, int pcnt, userrec *user)
125           {
126                   chanrec* c;
127
128                   if (!pcnt)
129                   {
130                           WriteServ(user->fd,"366 %s * :End of /NAMES list.",user->nick);
131                           return;
132                   }
133
134                   if (ServerInstance->Parser->LoopCall(this,parameters,pcnt,user,0,pcnt-1,0))
135                           return;
136
137                   WriteOpers("*** Oper %s used SPYNAMES to view the users on %s",user->nick,parameters[0]);
138
139                   c = FindChan(parameters[0]);
140                   if (c)
141                   {
142                           spy_userlist(user,c);
143                           WriteServ(user->fd,"366 %s %s :End of /NAMES list.", user->nick, c->name);
144                   }
145                   else
146                   {
147                           WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
148                   }
149           }
150 };
151
152 class ModuleSpy : public Module
153 {
154         cmd_spylist *mycommand;
155         cmd_spynames *mycommand2;
156  public:
157         ModuleSpy(Server* Me) : Module::Module(Me)
158         {
159                 Srv = Me;
160                 mycommand = new cmd_spylist();
161                 mycommand2 = new cmd_spynames();
162                 Srv->AddCommand(mycommand);
163                 Srv->AddCommand(mycommand2);
164         }
165         
166         virtual ~ModuleSpy()
167         {
168         }
169         
170         virtual Version GetVersion()
171         {
172                 return Version(1, 0, 0, 0, VF_VENDOR);
173         }
174 };
175
176
177 class ModuleSpyFactory : public ModuleFactory
178 {
179  public:
180         ModuleSpyFactory()
181         {
182         }
183         
184         ~ModuleSpyFactory()
185         {
186         }
187         
188         virtual Module * CreateModule(Server* Me)
189         {
190                 return new ModuleSpy(Me);
191         }
192         
193 };
194
195
196 extern "C" void * init_module( void )
197 {
198         return new ModuleSpyFactory;
199 }