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