]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_operwho.cpp
Warning fixes
[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                                         for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
130                                         {
131                                                 if ((has_channel(i->second,Ptr)) && (isnick(i->second->nick)))
132                                                 {
133                                                         // Fix Bug #29 - Part 2..
134                                                         *tmp = 0;
135                                                         if (*i->second->awaymsg) {
136                                                                 strlcat(tmp, "G", 9);
137                                                         } else {
138                                                                 strlcat(tmp, "H", 9);
139                                                         }
140                                                         if (*i->second->oper) { strlcat(tmp, "*", 9); }
141                                                         strlcat(tmp, cmode(i->second, Ptr),5);
142                                                         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);
143         
144                                                 }
145                                         }
146                                         WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
147                                 }
148                                 else
149                                 {
150                                         WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
151                                 }
152                                 return 1;
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                                 return 1;
172                         }
173                 }
174                 if (pcnt == 2)
175                 {
176                         if ((!strcmp(parameters[0],"0")) || (!strcmp(parameters[0],"*")) && (!strcmp(parameters[1],"o")))
177                         {
178                                 for (std::vector<userrec*>::iterator i = all_opers.begin(); i != all_opers.end(); i++)
179                                 {
180                                         // If i were a rich man.. I wouldn't need to me making these bugfixes..
181                                         // But i'm a poor bastard with nothing better to do.
182                                         userrec* oper = *i;
183                                         *tmp = 0;
184                                         if (*oper->awaymsg) {
185                                                 strlcat(tmp, "G" ,9);
186                                         } else {
187                                                 strlcat(tmp, "H" ,9);
188                                         }
189                                         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 
190                                         : "*", oper->ident, oper->host, oper->server, oper->nick, tmp, oper->fullname);
191                                 }
192                                 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
193                                 return 1;
194                         }
195                 }
196                 return 0;
197         }
198         
199         virtual ~ModuleOperWho()
200         {
201         }
202         
203         virtual Version GetVersion()
204         {
205                 return Version(1, 0, 0, 0, VF_VENDOR);
206         }
207 };
208
209
210 class ModuleOperWhoFactory : public ModuleFactory
211 {
212  public:
213         ModuleOperWhoFactory()
214         {
215         }
216         
217         ~ModuleOperWhoFactory()
218         {
219         }
220         
221         virtual Module * CreateModule(Server* Me)
222         {
223                 return new ModuleOperWho(Me);
224         }
225         
226 };
227
228
229 extern "C" void * init_module( void )
230 {
231         return new ModuleOperWhoFactory;
232 }