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