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