]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_who.cpp
Decide that it wasn't quite appropriate :(
[user/henk/code/inspircd.git] / src / cmd_who.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 #include "inspircd_config.h"
20 #include "inspircd.h"
21 #include "inspircd_io.h"
22 #include <time.h>
23 #include <string>
24 #ifdef GCC3
25 #include <ext/hash_map>
26 #else
27 #include <hash_map>
28 #endif
29 #include <map>
30 #include <sstream>
31 #include <vector>
32 #include <deque>
33 #include "users.h"
34 #include "ctables.h"
35 #include "globals.h"
36 #include "modules.h"
37 #include "dynamic.h"
38 #include "wildcard.h"
39 #include "message.h"
40 #include "commands.h"
41 #include "mode.h"
42 #include "xline.h"
43 #include "inspstring.h"
44 #include "dnsqueue.h"
45 #include "helperfuncs.h"
46 #include "hashcomp.h"
47 #include "socketengine.h"
48 #include "typedefs.h"
49 #include "command_parse.h"
50 #include "cmd_who.h"
51
52 extern ServerConfig* Config;
53 extern InspIRCd* ServerInstance;
54 extern int MODCOUNT;
55 extern std::vector<Module*> modules;
56 extern std::vector<ircd_module*> factory;
57 extern time_t TIME;
58 extern user_hash clientlist;
59 extern chan_hash chanlist;
60 extern whowas_hash whowas;
61 extern std::vector<userrec*> all_opers;
62 extern std::vector<userrec*> local_users;
63 extern userrec* fd_ref_table[MAX_DESCRIPTORS];
64
65 void cmd_who::Handle (char **parameters, int pcnt, userrec *user)
66 {
67         chanrec* Ptr = NULL;
68         char tmp[10];
69         
70         /* theres more to do here, but for now just close the socket */
71         if (pcnt == 1)
72         {
73                 if ((!strcmp(parameters[0],"0")) || (!strcmp(parameters[0],"*")))
74                 {
75                         if ((user->chans.size()) && (user->chans[0].channel))
76                         {
77                                 int n_list = 0;
78                                 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
79                                 {
80                                         Ptr = i->second->chans[0].channel;
81                                         // suggested by phidjit and FCS
82                                         if ((!common_channels(user,i->second)) && (isnick(i->second->nick)))
83                                         {
84                                                 // Bug Fix #29
85                                                 *tmp = 0;
86                                                 if (*i->second->awaymsg) {
87                                                         strlcat(tmp, "G", 9);
88                                                 } else {
89                                                         strlcat(tmp, "H", 9);
90                                                 }
91                                                 if (*i->second->oper) { strlcat(tmp, "*", 9); }
92                                                 WriteServ(user->fd,"352 %s %s %s %s %s %s %s :0 %s",user->nick, Ptr ? Ptr->name : "*", i->second->ident, i->second->dhost, i->second->server, i->second->nick, tmp, i->second->fullname);
93                                                 if (n_list++ > Config->MaxWhoResults)
94                                                 {
95                                                         WriteServ(user->fd,"523 %s WHO :Command aborted: More results than configured limit",user->nick);
96                                                         break;
97                                                 }
98                                         }
99                                 }
100                         }
101                         if (Ptr)
102                         {
103                                 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick , parameters[0]);
104                         }
105                         else
106                         {
107                                 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
108                         }
109                         return;
110                 }
111                 if (parameters[0][0] == '#')
112                 {
113                         Ptr = FindChan(parameters[0]);
114                         if (Ptr)
115                         {
116                                 int n_list = 0;
117                                 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
118                                 {
119                                         if ((has_channel(i->second,Ptr)) && (isnick(i->second->nick)))
120                                         {
121                                                 // Fix Bug #29 - Part 2..
122                                                 *tmp = 0;
123                                                 if (*i->second->awaymsg) {
124                                                         strlcat(tmp, "G", 9);
125                                                 } else {
126                                                         strlcat(tmp, "H", 9);
127                                                 }
128                                                 if (*i->second->oper) { strlcat(tmp, "*", 9); }
129                                                 strlcat(tmp, cmode(i->second, Ptr),5);
130                                                 WriteServ(user->fd,"352 %s %s %s %s %s %s %s :0 %s",user->nick, Ptr->name, i->second->ident, i->second->dhost, i->second->server, i->second->nick, tmp, i->second->fullname);
131                                                 n_list++;
132                                                 if (n_list > Config->MaxWhoResults)
133                                                 {
134                                                         WriteServ(user->fd,"523 %s WHO :Command aborted: More results than configured limit",user->nick);
135                                                         break;
136                                                 }
137
138                                         }
139                                 }
140                                 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
141                         }
142                         else
143                         {
144                                 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
145                         }
146                 }
147                 else
148                 {
149                         userrec* u = Find(parameters[0]);
150                         if (u)
151                         {
152                                 // Bug Fix #29 -- Part 29..
153                                 *tmp = 0;
154                                 if (*u->awaymsg) {
155                                         strlcat(tmp, "G" ,9);
156                                 } else {
157                                         strlcat(tmp, "H" ,9);
158                                 }
159                                 if (*u->oper) { strlcat(tmp, "*" ,9); }
160                                 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
161                                 : "*", u->ident, u->dhost, u->server, u->nick, tmp, u->fullname);
162                         }
163                         WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
164                 }
165         }
166         if (pcnt == 2)
167         {
168                 if ((!strcmp(parameters[0],"0")) || (!strcmp(parameters[0],"*")) && (!strcmp(parameters[1],"o")))
169                 {
170                         for (std::vector<userrec*>::iterator i = all_opers.begin(); i != all_opers.end(); i++)
171                         {
172                                 // If i were a rich man.. I wouldn't need to me making these bugfixes..
173                                 // But i'm a poor bastard with nothing better to do.
174                                 userrec* oper = *i;
175                                 *tmp = 0;
176                                 if (*oper->awaymsg) {
177                                         strlcat(tmp, "G" ,9);
178                                 } else {
179                                         strlcat(tmp, "H" ,9);
180                                 }
181                                 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 
182                                 : "*", oper->ident, oper->dhost, oper->server, oper->nick, tmp, oper->fullname);
183                         }
184                         WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
185                         return;
186                 }
187         }
188 }
189
190