]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spy.cpp
Removed superfluous semicolons
[user/henk/code/inspircd.git] / src / modules / m_spy.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 /* NO, THIS MODULE DOES NOT SPY ON CHANNELS OR USERS.
15  * IT JUST ALLOWS OPERS TO SEE +s CHANNELS IN LIST AND
16  * WHOIS, WHICH IS SUPPORTED BY MOST IRCDS IN CORE.
17  */
18
19 /* $ModDesc: Provides SPYLIST and SPYNAMES capability, allowing opers to see who's in +s channels */
20
21 #include "inspircd.h"
22 #include "users.h" 
23 #include "channels.h"
24 #include "modules.h"
25 #include "wildcard.h"
26
27 void spy_userlist(userrec *user, chanrec *c)
28 {
29         char list[MAXBUF];
30         size_t dlen, curlen;
31
32         dlen = curlen = snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
33
34         int numusers = 0;
35         char* ptr = list + dlen;
36
37         CUList *ulist= c->GetUsers();
38
39         for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
40         {
41                 size_t ptrlen = snprintf(ptr, MAXBUF, "%s%s ", c->GetPrefixChar(i->first), i->first->nick);
42
43                 curlen += ptrlen;
44                 ptr += ptrlen;
45
46                 numusers++;
47
48                 if (curlen > (480-NICKMAX))
49                 {
50                         /* list overflowed into multiple numerics */
51                         user->WriteServ(std::string(list));
52
53                         /* reset our lengths */
54                         dlen = curlen = snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
55                         ptr = list + dlen;
56
57                         ptrlen = 0;
58                         numusers = 0;
59                 }
60         }
61
62         /* if whats left in the list isnt empty, send it */
63         if (numusers)
64         {
65                 user->WriteServ(std::string(list));
66         }
67
68         user->WriteServ("366 %s %s :End of /NAMES list.", user->nick, c->name);
69
70 }
71
72 /** Handle /SPYLIST
73  */
74 class cmd_spylist : public command_t
75 {
76   public:
77         cmd_spylist (InspIRCd* Instance) : command_t(Instance,"SPYLIST", 'o', 0)
78         {
79                 this->source = "m_spy.so";
80                 syntax.clear();
81         }
82
83         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
84         {
85                 ServerInstance->WriteOpers("*** Oper %s used SPYLIST to list +s/+p channels and keys.",user->nick);
86                 user->WriteServ("321 %s Channel :Users Name",user->nick);
87                 for (chan_hash::const_iterator i = ServerInstance->chanlist->begin(); i != ServerInstance->chanlist->end(); i++)
88                 {
89                         if (pcnt && !match(i->second->name, parameters[0]))
90                                 continue;
91                         user->WriteServ("322 %s %s %d :[+%s] %s",user->nick,i->second->name,i->second->GetUserCounter(),i->second->ChanModes(true),i->second->topic);
92                 }
93                 user->WriteServ("323 %s :End of channel list.",user->nick);
94
95                 /* Dont send out across the network */
96                 return CMD_FAILURE;
97         }
98 };
99
100 /** Handle /SPYNAMES
101  */
102 class cmd_spynames : public command_t
103 {
104   public:
105         cmd_spynames (InspIRCd* Instance) : command_t(Instance,"SPYNAMES", 'o', 0)
106         {
107                 this->source = "m_spy.so";
108                 syntax = "{<channel>{,<channel>}}";
109         }
110
111         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
112         {
113                 chanrec* c = NULL;
114
115                 if (!pcnt)
116                 {
117                         user->WriteServ("366 %s * :End of /NAMES list.",user->nick);
118                         return CMD_FAILURE;
119                 }
120
121                 if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 0))
122                         return CMD_FAILURE;
123
124                 c = ServerInstance->FindChan(parameters[0]);
125                 if (c)
126                 {
127                         ServerInstance->WriteOpers("*** Oper %s used SPYNAMES to view the users on %s", user->nick, parameters[0]);
128                         spy_userlist(user,c);
129                 }
130                 else
131                 {
132                         user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
133                 }
134
135                 return CMD_FAILURE;
136         }
137 };
138
139 class ModuleSpy : public Module
140 {
141         cmd_spylist *mycommand;
142         cmd_spynames *mycommand2;
143  public:
144         ModuleSpy(InspIRCd* Me) : Module(Me)
145         {
146                 
147                 mycommand = new cmd_spylist(ServerInstance);
148                 mycommand2 = new cmd_spynames(ServerInstance);
149                 ServerInstance->AddCommand(mycommand);
150                 ServerInstance->AddCommand(mycommand2);
151         }
152         
153         virtual ~ModuleSpy()
154         {
155         }
156         
157         virtual Version GetVersion()
158         {
159                 return Version(1, 1, 0, 0, VF_VENDOR, API_VERSION);
160         }
161 };
162
163 MODULE_INIT(ModuleSpy)