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