]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spy.cpp
Fix for parameters which contain a colon (which is not the first char in the string)
[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         void 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 };
87
88 class cmd_spynames : public command_t
89 {
90   public:
91         cmd_spynames (InspIRCd* Instance) : command_t(Instance,"SPYNAMES", 'o', 0)
92         {
93                 this->source = "m_spy.so";
94                 syntax = "{<channel>{,<channel>}}";
95         }
96
97         void Handle (const char** parameters, int pcnt, userrec *user)
98         {
99                 chanrec* c;
100
101                 if (!pcnt)
102                 {
103                         user->WriteServ("366 %s * :End of /NAMES list.",user->nick);
104                         return;
105                 }
106
107                 if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 1))
108                         return;
109
110                 ServerInstance->WriteOpers("*** Oper %s used SPYNAMES to view the users on %s",user->nick,parameters[0]);
111
112                 c = ServerInstance->FindChan(parameters[0]);
113                 if (c)
114                 {
115                         spy_userlist(user,c);
116                         user->WriteServ("366 %s %s :End of /NAMES list.", user->nick, c->name);
117                 }
118                 else
119                 {
120                         user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
121                 }
122         }
123 };
124
125 class ModuleSpy : public Module
126 {
127         cmd_spylist *mycommand;
128         cmd_spynames *mycommand2;
129  public:
130         ModuleSpy(InspIRCd* Me) : Module::Module(Me)
131         {
132                 
133                 mycommand = new cmd_spylist(ServerInstance);
134                 mycommand2 = new cmd_spynames(ServerInstance);
135                 ServerInstance->AddCommand(mycommand);
136                 ServerInstance->AddCommand(mycommand2);
137         }
138         
139         virtual ~ModuleSpy()
140         {
141         }
142         
143         virtual Version GetVersion()
144         {
145                 return Version(1, 0, 0, 0, VF_VENDOR);
146         }
147 };
148
149
150 class ModuleSpyFactory : public ModuleFactory
151 {
152  public:
153         ModuleSpyFactory()
154         {
155         }
156         
157         ~ModuleSpyFactory()
158         {
159         }
160         
161         virtual Module * CreateModule(InspIRCd* Me)
162         {
163                 return new ModuleSpy(Me);
164         }
165         
166 };
167
168
169 extern "C" void * init_module( void )
170 {
171         return new ModuleSpyFactory;
172 }