]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_operwho.cpp
15ff74c6d4be96761c6e0f8223b0c3eb10d26019
[user/henk/code/inspircd.git] / src / modules / m_operwho.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 using namespace std;
18
19 /*
20  * DEVOICE module for InspIRCd
21  *  Syntax: /DEVOICE <#chan>
22  */
23
24 /* $ModDesc: Provides an extended version of /WHO for opers */
25
26 #include "inspircd_config.h"
27 #include "inspircd.h"
28 #include "inspircd_io.h"
29 #include <time.h>
30 #include <string>
31 #ifdef GCC3
32 #include <ext/hash_map>
33 #else
34 #include <hash_map>
35 #endif
36 #include <map>
37 #include <sstream>
38 #include <vector>
39 #include <deque>
40 #include "users.h"
41 #include "globals.h"
42 #include "modules.h"
43 #include "helperfuncs.h"
44 #include "hashcomp.h"
45 #include "typedefs.h"
46
47 extern ServerConfig* Config;
48 extern InspIRCd* ServerInstance;
49 extern user_hash clientlist;
50 extern chan_hash chanlist;
51 extern std::vector<userrec*> all_opers;
52 extern std::vector<userrec*> local_users;
53
54 class ModuleOperWho : public Module
55 {
56         Server* Srv;
57  public:
58         ModuleOperWho(Server* Me) : Module::Module(Me)
59         {
60                 Srv = Me;
61         }
62
63         virtual void Implements(char* List)
64         {
65                 List[I_OnPreCommand] = 1;
66         }
67
68         virtual int OnPreCommand(std::string command, char **parameters, int pcnt, userrec *user, bool validated)
69         {
70
71                 if (!*user->oper)
72                         return 0;
73
74                 chanrec* Ptr = NULL;
75                 char tmp[10];
76         
77                 if (!pcnt)
78                 {
79                         for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
80                         {
81                                 *tmp = 0;
82                                 Ptr = i->second->chans[0].channel;
83                                 if (*i->second->awaymsg) {
84                                         strlcat(tmp, "G", 9);
85                                 } else {
86                                         strlcat(tmp, "H", 9);
87                                 }
88                                 if (*i->second->oper) { strlcat(tmp, "*", 9); }
89                                 WriteServ(user->fd,"352 %s %s %s %s %s %s %s :0 %s",user->nick, Ptr ? Ptr->name : "*", i->second->ident, i->second->host, i->second->server, i->second->nick, tmp, i->second->fullname);
90                         }
91                         WriteServ(user->fd,"315 %s * :End of /WHO list.",user->nick);
92                         return 1;
93                 }
94                 if (pcnt == 1)
95                 {
96                         if ((!strcmp(parameters[0],"0")) || (!strcmp(parameters[0],"*")))
97                         {
98                                 if ((user->chans.size()) && (user->chans[0].channel))
99                                 {
100                                         int n_list = 0;
101                                         for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
102                                         {
103                                                 Ptr = i->second->chans[0].channel;
104                                                 // suggested by phidjit and FCS
105                                                 if ((!common_channels(user,i->second)) && (isnick(i->second->nick)))
106                                                 {
107                                                         // Bug Fix #29
108                                                         *tmp = 0;
109                                                         if (*i->second->awaymsg) {
110                                                                 strlcat(tmp, "G", 9);
111                                                         } else {
112                                                                 strlcat(tmp, "H", 9);
113                                                         }
114                                                         if (*i->second->oper) { strlcat(tmp, "*", 9); }
115                                                         WriteServ(user->fd,"352 %s %s %s %s %s %s %s :0 %s",user->nick, Ptr ? Ptr->name : "*", i->second->ident, i->second->host, i->second->server, i->second->nick, tmp, i->second->fullname);
116                                                 }
117                                         }
118                                 }
119                                 if (Ptr)
120                                 {
121                                         WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick , parameters[0]);
122                                 }
123                                 else
124                                 {
125                                         WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
126                                 }
127                                 return 1;
128                         }
129                         if (parameters[0][0] == '#')
130                         {
131                                 Ptr = FindChan(parameters[0]);
132                                 if (Ptr)
133                                 {
134                                         int n_list = 0;
135                                         for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
136                                         {
137                                                 if ((has_channel(i->second,Ptr)) && (isnick(i->second->nick)))
138                                                 {
139                                                         // Fix Bug #29 - Part 2..
140                                                         *tmp = 0;
141                                                         if (*i->second->awaymsg) {
142                                                                 strlcat(tmp, "G", 9);
143                                                         } else {
144                                                                 strlcat(tmp, "H", 9);
145                                                         }
146                                                         if (*i->second->oper) { strlcat(tmp, "*", 9); }
147                                                         strlcat(tmp, cmode(i->second, Ptr),5);
148                                                         WriteServ(user->fd,"352 %s %s %s %s %s %s %s :0 %s",user->nick, Ptr->name, i->second->ident, i->second->host, i->second->server, i->second->nick, tmp, i->second->fullname);
149         
150                                                 }
151                                         }
152                                         WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
153                                 }
154                                 else
155                                 {
156                                         WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
157                                 }
158                         }
159                         else
160                         {
161                                 userrec* u = Find(parameters[0]);
162                                 if (u)
163                                 {
164                                         // Bug Fix #29 -- Part 29..
165                                         *tmp = 0;
166                                         if (*u->awaymsg) {
167                                                 strlcat(tmp, "G" ,9);
168                                         } else {
169                                                 strlcat(tmp, "H" ,9);
170                                         }
171                                         if (*u->oper) { strlcat(tmp, "*" ,9); }
172                                         WriteServ(user->fd,"352 %s %s %s %s %s %s %s :0 %s",user->nick, u->chans.size() && u->chans[0].channel ? u->chans[0].channel->name
173                                         : "*", u->ident, u->dhost, u->server, u->nick, tmp, u->fullname);
174                                 }
175                                 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
176                         }
177                 }
178                 if (pcnt == 2)
179                 {
180                         if ((!strcmp(parameters[0],"0")) || (!strcmp(parameters[0],"*")) && (!strcmp(parameters[1],"o")))
181                         {
182                                 for (std::vector<userrec*>::iterator i = all_opers.begin(); i != all_opers.end(); i++)
183                                 {
184                                         // If i were a rich man.. I wouldn't need to me making these bugfixes..
185                                         // But i'm a poor bastard with nothing better to do.
186                                         userrec* oper = *i;
187                                         *tmp = 0;
188                                         if (*oper->awaymsg) {
189                                                 strlcat(tmp, "G" ,9);
190                                         } else {
191                                                 strlcat(tmp, "H" ,9);
192                                         }
193                                         WriteServ(user->fd,"352 %s %s %s %s %s %s %s* :0 %s", user->nick, oper->chans.size() && oper->chans[0].channel ? oper->chans[0].channel->name 
194                                         : "*", oper->ident, oper->host, oper->server, oper->nick, tmp, oper->fullname);
195                                 }
196                                 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
197                                 return 1;
198                         }
199                 }
200         }
201         
202         virtual ~ModuleOperWho()
203         {
204         }
205         
206         virtual Version GetVersion()
207         {
208                 return Version(1, 0, 0, 0, VF_VENDOR);
209         }
210 };
211
212
213 class ModuleOperWhoFactory : public ModuleFactory
214 {
215  public:
216         ModuleOperWhoFactory()
217         {
218         }
219         
220         ~ModuleOperWhoFactory()
221         {
222         }
223         
224         virtual Module * CreateModule(Server* Me)
225         {
226                 return new ModuleOperWho(Me);
227         }
228         
229 };
230
231
232 extern "C" void * init_module( void )
233 {
234         return new ModuleOperWhoFactory;
235 }