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