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