]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_who.cpp
Updated copyrights in headers etc using perl inplace edit
[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 (strchr(i->second->modes,'o')) { 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                                                 n_list++;
94                                                 if (n_list > Config->MaxWhoResults)
95                                                 {
96                                                         WriteServ(user->fd,"523 %s WHO :Command aborted: More results than configured limit",user->nick);
97                                                         break;
98                                                 }
99                                         }
100                                 }
101                         }
102                         if (Ptr)
103                         {
104                                 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick , parameters[0]);
105                         }
106                         else
107                         {
108                                 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
109                         }
110                         return;
111                 }
112                 if (parameters[0][0] == '#')
113                 {
114                         Ptr = FindChan(parameters[0]);
115                         if (Ptr)
116                         {
117                                 int n_list = 0;
118                                 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
119                                 {
120                                         if ((has_channel(i->second,Ptr)) && (isnick(i->second->nick)))
121                                         {
122                                                 // Fix Bug #29 - Part 2..
123                                                 *tmp = 0;
124                                                 if (*i->second->awaymsg) {
125                                                         strlcat(tmp, "G", 9);
126                                                 } else {
127                                                         strlcat(tmp, "H", 9);
128                                                 }
129                                                 if (strchr(i->second->modes,'o')) { strlcat(tmp, "*", 9); }
130                                                 strlcat(tmp, cmode(i->second, Ptr),5);
131                                                 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);
132                                                 n_list++;
133                                                 if (n_list > Config->MaxWhoResults)
134                                                 {
135                                                         WriteServ(user->fd,"523 %s WHO :Command aborted: More results than configured limit",user->nick);
136                                                         break;
137                                                 }
138
139                                         }
140                                 }
141                                 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
142                         }
143                         else
144                         {
145                                 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
146                         }
147                 }
148                 else
149                 {
150                         userrec* u = Find(parameters[0]);
151                         if (u)
152                         {
153                                 // Bug Fix #29 -- Part 29..
154                                 *tmp = 0;
155                                 if (*u->awaymsg) {
156                                         strlcat(tmp, "G" ,9);
157                                 } else {
158                                         strlcat(tmp, "H" ,9);
159                                 }
160                                 if (strchr(u->modes,'o')) { strlcat(tmp, "*" ,9); }
161                                 WriteServ(user->fd,"352 %s %s %s %s %s %s %s :0 %s",user->nick, u->chans.size() ? u->chans[0].channel->name
162                                 : "*", u->ident, u->dhost, u->server, u->nick, tmp, u->fullname);
163                         }
164                         WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
165                 }
166         }
167         if (pcnt == 2)
168         {
169                 if ((!strcmp(parameters[0],"0")) || (!strcmp(parameters[0],"*")) && (!strcmp(parameters[1],"o")))
170                 {
171                         for (std::vector<userrec*>::iterator i = all_opers.begin(); i != all_opers.end(); i++)
172                         {
173                                 // If i were a rich man.. I wouldn't need to me making these bugfixes..
174                                 // But i'm a poor bastard with nothing better to do.
175                                 userrec* oper = *i;
176                                 *tmp = 0;
177                                 if (*oper->awaymsg) {
178                                         strlcat(tmp, "G" ,9);
179                                 } else {
180                                         strlcat(tmp, "H" ,9);
181                                 }
182                                 WriteServ(user->fd,"352 %s %s %s %s %s %s %s* :0 %s", user->nick, oper->chans.size() ? oper->chans[0].channel->name 
183                                 : "*", oper->ident, oper->dhost, oper->server, oper->nick, tmp, oper->fullname);
184                         }
185                         WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
186                         return;
187                 }
188         }
189 }
190
191