]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spy.cpp
Just to mess with om's head, remove helperfuncs.h from everywhere
[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
38 #include "inspircd.h"
39 #include "inspstring.h"
40 #include "hashcomp.h"
41 #include "xline.h"
42 #include "typedefs.h"
43 #include "cull_list.h"
44 #include "aes.h"
45
46 #define nspace __gnu_cxx
47
48 void spy_userlist(userrec *user,chanrec *c)
49 {
50         static char list[MAXBUF];
51
52         if ((!c) || (!user))
53                 return;
54
55         snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
56
57         CUList *ulist= c->GetUsers();
58         for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
59         {
60                 strlcat(list,c->GetStatusChar(i->second),MAXBUF);
61                 strlcat(list,i->second->nick,MAXBUF);
62                 strlcat(list," ",MAXBUF);
63                 if (strlen(list)>(480-NICKMAX))
64                 {
65                         /* list overflowed into
66                          * multiple numerics */
67                         user->WriteServ(std::string(list));
68                         snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
69                 }
70         }
71         /* if whats left in the list isnt empty, send it */
72         if (list[strlen(list)-1] != ':')
73         {
74                 user->WriteServ(std::string(list));
75         }
76 }
77
78
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         void 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                         user->WriteServ("322 %s %s %d :[+%s] %s",user->nick,i->second->name,i->second->GetUserCounter(),i->second->ChanModes(true),i->second->topic);
96                 }
97                 user->WriteServ("323 %s :End of channel list.",user->nick);
98         }
99 };
100
101 class cmd_spynames : public command_t
102 {
103   public:
104  cmd_spynames (InspIRCd* Instance) : command_t(Instance,"SPYNAMES", 'o', 0)
105         {
106                 this->source = "m_spy.so";
107                 syntax = "{<channel>{,<channel>}}";
108         }
109
110         void Handle (const char** parameters, int pcnt, userrec *user)
111         {
112                 chanrec* c;
113
114                 if (!pcnt)
115                 {
116                         user->WriteServ("366 %s * :End of /NAMES list.",user->nick);
117                         return;
118                 }
119
120                 if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 1))
121                         return;
122
123                 ServerInstance->WriteOpers("*** Oper %s used SPYNAMES to view the users on %s",user->nick,parameters[0]);
124
125                 c = ServerInstance->FindChan(parameters[0]);
126                 if (c)
127                 {
128                         spy_userlist(user,c);
129                         user->WriteServ("366 %s %s :End of /NAMES list.", user->nick, c->name);
130                 }
131                 else
132                 {
133                         user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
134                 }
135         }
136 };
137
138 class ModuleSpy : public Module
139 {
140         cmd_spylist *mycommand;
141         cmd_spynames *mycommand2;
142  public:
143         ModuleSpy(InspIRCd* Me) : Module::Module(Me)
144         {
145                 
146                 mycommand = new cmd_spylist(ServerInstance);
147                 mycommand2 = new cmd_spynames(ServerInstance);
148                 ServerInstance->AddCommand(mycommand);
149                 ServerInstance->AddCommand(mycommand2);
150         }
151         
152         virtual ~ModuleSpy()
153         {
154         }
155         
156         virtual Version GetVersion()
157         {
158                 return Version(1, 0, 0, 0, VF_VENDOR);
159         }
160 };
161
162
163 class ModuleSpyFactory : public ModuleFactory
164 {
165  public:
166         ModuleSpyFactory()
167         {
168         }
169         
170         ~ModuleSpyFactory()
171         {
172         }
173         
174         virtual Module * CreateModule(InspIRCd* Me)
175         {
176                 return new ModuleSpy(Me);
177         }
178         
179 };
180
181
182 extern "C" void * init_module( void )
183 {
184         return new ModuleSpyFactory;
185 }