]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_who.cpp
Remove an extern, partly because it's unused, partly because it then gets shadowed...
[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 #include "configreader.h"
18 #include "users.h"
19 #include "message.h"
20 #include "modules.h"
21 #include "commands.h"
22 #include "helperfuncs.h"
23 #include "cmd_who.h"
24
25 extern ServerConfig* Config;
26 extern user_hash clientlist;
27 extern chan_hash chanlist;
28 extern std::vector<userrec*> all_opers;
29
30 void cmd_who::Handle (char **parameters, int pcnt, userrec *user)
31 {
32         chanrec* Ptr = NULL;
33         char tmp[10];
34         
35         if (pcnt == 1)
36         {
37                 if ((IS_SINGLE(parameters[0],'0')) || (IS_SINGLE(parameters[0],'*')))
38                 {
39                         if ((user->chans.size()) && (((ucrec*)*(user->chans.begin()))->channel))
40                         {
41                                 int n_list = 0;
42                                 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
43                                 {
44                                         Ptr = ((ucrec*)*(i->second->chans.begin()))->channel;
45                                         // suggested by phidjit and FCS
46                                         if ((!common_channels(user,i->second)) && (isnick(i->second->nick)))
47                                         {
48                                                 // Bug Fix #29
49                                                 *tmp = 0;
50                                                 if (*i->second->awaymsg) {
51                                                         charlcat(tmp, 'G', 9);
52                                                 } else {
53                                                         charlcat(tmp, 'H', 9);
54                                                 }
55                                                 if (*i->second->oper) { charlcat(tmp, '*', 9); }
56                                                 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);
57                                                 if (n_list++ > Config->MaxWhoResults)
58                                                 {
59                                                         WriteServ(user->fd,"523 %s WHO :Command aborted: More results than configured limit",user->nick);
60                                                         break;
61                                                 }
62                                         }
63                                 }
64                         }
65                         if (Ptr)
66                         {
67                                 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick , parameters[0]);
68                         }
69                         else
70                         {
71                                 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
72                         }
73                         return;
74                 }
75                 if (parameters[0][0] == '#')
76                 {
77                         Ptr = FindChan(parameters[0]);
78                         if (Ptr)
79                         {
80                                 int n_list = 0;
81                                 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
82                                 {
83                                         if ((Ptr->HasUser(i->second)) && (isnick(i->second->nick)))
84                                         {
85                                                 // Fix Bug #29 - Part 2..
86                                                 *tmp = 0;
87                                                 if (*i->second->awaymsg) {
88                                                         charlcat(tmp, 'G', 9);
89                                                 } else {
90                                                         charlcat(tmp, 'H', 9);
91                                                 }
92                                                 if (*i->second->oper) { charlcat(tmp, '*', 9); }
93                                                 strlcat(tmp, cmode(i->second, Ptr),5);
94                                                 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);
95                                                 n_list++;
96                                                 if (n_list > Config->MaxWhoResults)
97                                                 {
98                                                         WriteServ(user->fd,"523 %s WHO :Command aborted: More results than configured limit",user->nick);
99                                                         break;
100                                                 }
101
102                                         }
103                                 }
104                                 WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
105                         }
106                         else
107                         {
108                                 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
109                         }
110                 }
111                 else
112                 {
113                         userrec* u = Find(parameters[0]);
114                         if (u)
115                         {
116                                 // Bug Fix #29 -- Part 29..
117                                 *tmp = 0;
118                                 if (*u->awaymsg) {
119                                         charlcat(tmp, 'G' ,9);
120                                 } else {
121                                         charlcat(tmp, 'H' ,9);
122                                 }
123                                 if (*u->oper) { charlcat(tmp, '*' ,9); }
124                                 WriteServ(user->fd,"352 %s %s %s %s %s %s %s :0 %s",user->nick, u->chans.size() && ((ucrec*)*(u->chans.begin()))->channel ? ((ucrec*)*(u->chans.begin()))->channel->name
125                                 : "*", u->ident, u->dhost, u->server, u->nick, tmp, u->fullname);
126                         }
127                         WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
128                 }
129         }
130         if (pcnt == 2)
131         {
132                 if ((IS_SINGLE(parameters[0],'0')) || (IS_SINGLE(parameters[0],'*')) && (IS_SINGLE(parameters[1],'o')))
133                 {
134                         for (std::vector<userrec*>::iterator i = all_opers.begin(); i != all_opers.end(); i++)
135                         {
136                                 // If i were a rich man.. I wouldn't need to me making these bugfixes..
137                                 // But i'm a poor bastard with nothing better to do.
138                                 userrec* oper = *i;
139                                 *tmp = 0;
140                                 if (*oper->awaymsg) {
141                                         charlcat(tmp, 'G' ,9);
142                                 } else {
143                                         charlcat(tmp, 'H' ,9);
144                                 }
145                                 WriteServ(user->fd,"352 %s %s %s %s %s %s %s* :0 %s", user->nick, oper->chans.size() && ((ucrec*)*(oper->chans.begin()))->channel ? ((ucrec*)*(oper->chans.begin()))->channel->name
146                                 : "*", oper->ident, oper->dhost, oper->server, oper->nick, tmp, oper->fullname);
147                         }
148                         WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
149                         return;
150                 }
151         }
152 }