]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * m_who.c: Shows who is on a channel. | |
4 | * | |
5 | * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center | |
6 | * Copyright (C) 1996-2002 Hybrid Development Team | |
7 | * Copyright (C) 2002-2005 ircd-ratbox development team | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
22 | * USA | |
23 | * | |
f71e18ee | 24 | * $Id: m_who.c 3350 2007-04-02 22:03:08Z jilles $ |
212380e3 AC |
25 | */ |
26 | #include "stdinc.h" | |
212380e3 AC |
27 | #include "common.h" |
28 | #include "client.h" | |
29 | #include "channel.h" | |
30 | #include "hash.h" | |
31 | #include "ircd.h" | |
32 | #include "numeric.h" | |
33 | #include "s_serv.h" | |
34 | #include "send.h" | |
4562c604 | 35 | #include "match.h" |
212380e3 | 36 | #include "s_conf.h" |
4016731b | 37 | #include "logger.h" |
212380e3 AC |
38 | #include "msg.h" |
39 | #include "parse.h" | |
40 | #include "modules.h" | |
41 | #include "packet.h" | |
42 | #include "s_newconf.h" | |
43 | ||
44 | static int m_who(struct Client *, struct Client *, int, const char **); | |
45 | ||
46 | struct Message who_msgtab = { | |
47 | "WHO", 0, 0, 0, MFLG_SLOW, | |
48 | {mg_unreg, {m_who, 2}, mg_ignore, mg_ignore, mg_ignore, {m_who, 2}} | |
49 | }; | |
50 | ||
51 | mapi_clist_av1 who_clist[] = { &who_msgtab, NULL }; | |
f71e18ee | 52 | DECLARE_MODULE_AV1(who, NULL, NULL, who_clist, NULL, NULL, "$Revision: 3350 $"); |
212380e3 AC |
53 | |
54 | static void do_who_on_channel(struct Client *source_p, struct Channel *chptr, | |
55 | int server_oper, int member); | |
56 | ||
57 | static void who_global(struct Client *source_p, const char *mask, int server_oper, int operspy); | |
58 | ||
59 | static void do_who(struct Client *source_p, | |
60 | struct Client *target_p, const char *chname, const char *op_flags); | |
61 | ||
62 | ||
63 | /* | |
64 | ** m_who | |
65 | ** parv[0] = sender prefix | |
66 | ** parv[1] = nickname mask list | |
67 | ** parv[2] = additional selection flag, only 'o' for now. | |
68 | */ | |
69 | static int | |
70 | m_who(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
71 | { | |
72 | static time_t last_used = 0; | |
73 | struct Client *target_p; | |
74 | struct membership *msptr; | |
75 | char *mask; | |
5b96d9a6 | 76 | rb_dlink_node *lp; |
212380e3 AC |
77 | struct Channel *chptr = NULL; |
78 | int server_oper = parc > 2 ? (*parv[2] == 'o') : 0; /* Show OPERS only */ | |
79 | int member; | |
80 | int operspy = 0; | |
81 | ||
82 | mask = LOCAL_COPY(parv[1]); | |
83 | ||
84 | collapse(mask); | |
85 | ||
86 | /* '/who *' */ | |
87 | if((*(mask + 1) == '\0') && (*mask == '*')) | |
88 | { | |
89 | if(source_p->user == NULL) | |
90 | return 0; | |
91 | ||
92 | if((lp = source_p->user->channel.head) != NULL) | |
93 | { | |
94 | msptr = lp->data; | |
95 | do_who_on_channel(source_p, msptr->chptr, server_oper, YES); | |
96 | } | |
97 | ||
98 | sendto_one(source_p, form_str(RPL_ENDOFWHO), | |
99 | me.name, source_p->name, "*"); | |
100 | return 0; | |
101 | } | |
102 | ||
103 | if(IsOperSpy(source_p) && *mask == '!') | |
104 | { | |
105 | mask++; | |
106 | operspy = 1; | |
107 | ||
108 | if(EmptyString(mask)) | |
109 | { | |
110 | sendto_one(source_p, form_str(RPL_ENDOFWHO), | |
111 | me.name, source_p->name, parv[1]); | |
112 | return 0; | |
113 | } | |
114 | } | |
115 | ||
116 | /* '/who #some_channel' */ | |
117 | if(IsChannelName(mask)) | |
118 | { | |
119 | /* List all users on a given channel */ | |
f71e18ee | 120 | chptr = find_channel(parv[1] + operspy); |
212380e3 AC |
121 | if(chptr != NULL) |
122 | { | |
123 | if(operspy) | |
124 | report_operspy(source_p, "WHO", chptr->chname); | |
125 | ||
126 | if(IsMember(source_p, chptr) || operspy) | |
127 | do_who_on_channel(source_p, chptr, server_oper, YES); | |
128 | else if(!SecretChannel(chptr)) | |
129 | do_who_on_channel(source_p, chptr, server_oper, NO); | |
130 | } | |
131 | sendto_one(source_p, form_str(RPL_ENDOFWHO), | |
f71e18ee | 132 | me.name, source_p->name, parv[1] + operspy); |
212380e3 AC |
133 | return 0; |
134 | } | |
135 | ||
136 | /* '/who nick' */ | |
137 | ||
138 | if(((target_p = find_named_person(mask)) != NULL) && | |
139 | (!server_oper || IsOper(target_p))) | |
140 | { | |
141 | int isinvis = 0; | |
142 | ||
143 | isinvis = IsInvisible(target_p); | |
5b96d9a6 | 144 | RB_DLINK_FOREACH(lp, target_p->user->channel.head) |
212380e3 AC |
145 | { |
146 | msptr = lp->data; | |
147 | chptr = msptr->chptr; | |
148 | ||
149 | member = IsMember(source_p, chptr); | |
150 | ||
151 | if(isinvis && !member) | |
152 | continue; | |
153 | ||
154 | if(member || (!isinvis && PubChannel(chptr))) | |
155 | break; | |
156 | } | |
157 | ||
158 | /* if we stopped midlist, lp->data is the membership for | |
159 | * target_p of chptr | |
160 | */ | |
161 | if(lp != NULL) | |
162 | do_who(source_p, target_p, chptr->chname, | |
163 | find_channel_status(lp->data, IsCapable(source_p, CLICAP_MULTI_PREFIX))); | |
164 | else | |
165 | do_who(source_p, target_p, NULL, ""); | |
166 | ||
167 | sendto_one(source_p, form_str(RPL_ENDOFWHO), | |
168 | me.name, source_p->name, mask); | |
169 | return 0; | |
170 | } | |
171 | ||
172 | if(!IsFloodDone(source_p)) | |
173 | flood_endgrace(source_p); | |
174 | ||
175 | /* it has to be a global who at this point, limit it */ | |
176 | if(!IsOper(source_p)) | |
177 | { | |
e3354945 | 178 | if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) |
212380e3 AC |
179 | { |
180 | sendto_one(source_p, form_str(RPL_LOAD2HI), | |
181 | me.name, source_p->name, "WHO"); | |
182 | sendto_one(source_p, form_str(RPL_ENDOFWHO), | |
183 | me.name, source_p->name, "*"); | |
184 | return 0; | |
185 | } | |
186 | else | |
e3354945 | 187 | last_used = rb_current_time(); |
212380e3 AC |
188 | } |
189 | ||
190 | /* Note: operspy_dont_care_user_info does not apply to | |
191 | * who on channels */ | |
192 | if(IsOperSpy(source_p) && ConfigFileEntry.operspy_dont_care_user_info) | |
193 | operspy = 1; | |
194 | ||
195 | /* '/who 0' for a global list. this forces clients to actually | |
196 | * request a full list. I presume its because of too many typos | |
197 | * with "/who" ;) --fl | |
198 | */ | |
199 | if((*(mask + 1) == '\0') && (*mask == '0')) | |
200 | who_global(source_p, NULL, server_oper, 0); | |
201 | else | |
202 | who_global(source_p, mask, server_oper, operspy); | |
203 | ||
204 | sendto_one(source_p, form_str(RPL_ENDOFWHO), | |
205 | me.name, source_p->name, mask); | |
206 | ||
207 | return 0; | |
208 | } | |
209 | ||
210 | /* who_common_channel | |
211 | * inputs - pointer to client requesting who | |
212 | * - pointer to channel member chain. | |
213 | * - char * mask to match | |
214 | * - int if oper on a server or not | |
215 | * - pointer to int maxmatches | |
216 | * output - NONE | |
217 | * side effects - lists matching invisible clients on specified channel, | |
218 | * marks matched clients. | |
219 | */ | |
220 | static void | |
221 | who_common_channel(struct Client *source_p, struct Channel *chptr, | |
222 | const char *mask, int server_oper, int *maxmatches) | |
223 | { | |
224 | struct membership *msptr; | |
225 | struct Client *target_p; | |
5b96d9a6 | 226 | rb_dlink_node *ptr; |
212380e3 | 227 | |
5b96d9a6 | 228 | RB_DLINK_FOREACH(ptr, chptr->members.head) |
212380e3 AC |
229 | { |
230 | msptr = ptr->data; | |
231 | target_p = msptr->client_p; | |
232 | ||
233 | if(!IsInvisible(target_p) || IsMarked(target_p)) | |
234 | continue; | |
235 | ||
236 | if(server_oper && !IsOper(target_p)) | |
237 | continue; | |
238 | ||
239 | SetMark(target_p); | |
240 | ||
241 | if(*maxmatches > 0) | |
242 | { | |
243 | if((mask == NULL) || | |
244 | match(mask, target_p->name) || match(mask, target_p->username) || | |
c88cdb00 | 245 | match(mask, target_p->host) || match(mask, target_p->servptr->name) || |
212380e3 AC |
246 | (IsOper(source_p) && match(mask, target_p->orighost)) || |
247 | match(mask, target_p->info)) | |
248 | { | |
249 | do_who(source_p, target_p, NULL, ""); | |
250 | --(*maxmatches); | |
251 | } | |
252 | } | |
253 | } | |
254 | } | |
255 | ||
256 | /* | |
257 | * who_global | |
258 | * | |
259 | * inputs - pointer to client requesting who | |
260 | * - char * mask to match | |
261 | * - int if oper on a server or not | |
262 | * output - NONE | |
263 | * side effects - do a global scan of all clients looking for match | |
264 | * this is slightly expensive on EFnet ... | |
265 | * marks assumed cleared for all clients initially | |
266 | * and will be left cleared on return | |
267 | */ | |
268 | static void | |
269 | who_global(struct Client *source_p, const char *mask, int server_oper, int operspy) | |
270 | { | |
271 | struct membership *msptr; | |
272 | struct Client *target_p; | |
5b96d9a6 | 273 | rb_dlink_node *lp, *ptr; |
212380e3 AC |
274 | int maxmatches = 500; |
275 | ||
276 | /* first, list all matching INvisible clients on common channels | |
277 | * if this is not an operspy who | |
278 | */ | |
279 | if(!operspy) | |
280 | { | |
5b96d9a6 | 281 | RB_DLINK_FOREACH(lp, source_p->user->channel.head) |
212380e3 AC |
282 | { |
283 | msptr = lp->data; | |
284 | who_common_channel(source_p, msptr->chptr, mask, server_oper, &maxmatches); | |
285 | } | |
286 | } | |
287 | else if (!ConfigFileEntry.operspy_dont_care_user_info) | |
288 | report_operspy(source_p, "WHO", mask); | |
289 | ||
290 | /* second, list all matching visible clients and clear all marks | |
291 | * on invisible clients | |
292 | * if this is an operspy who, list all matching clients, no need | |
293 | * to clear marks | |
294 | */ | |
5b96d9a6 | 295 | RB_DLINK_FOREACH(ptr, global_client_list.head) |
212380e3 AC |
296 | { |
297 | target_p = ptr->data; | |
298 | if(!IsPerson(target_p)) | |
299 | continue; | |
300 | ||
301 | if(IsInvisible(target_p) && !operspy) | |
302 | { | |
303 | ClearMark(target_p); | |
304 | continue; | |
305 | } | |
306 | ||
307 | if(server_oper && !IsOper(target_p)) | |
308 | continue; | |
309 | ||
310 | if(maxmatches > 0) | |
311 | { | |
312 | if(!mask || | |
313 | match(mask, target_p->name) || match(mask, target_p->username) || | |
c88cdb00 | 314 | match(mask, target_p->host) || match(mask, target_p->servptr->name) || |
212380e3 AC |
315 | (IsOper(source_p) && match(mask, target_p->orighost)) || |
316 | match(mask, target_p->info)) | |
317 | { | |
318 | do_who(source_p, target_p, NULL, ""); | |
319 | --maxmatches; | |
320 | } | |
321 | } | |
322 | } | |
323 | ||
324 | if (maxmatches <= 0) | |
325 | sendto_one(source_p, | |
326 | form_str(ERR_TOOMANYMATCHES), | |
327 | me.name, source_p->name, "WHO"); | |
328 | } | |
329 | ||
330 | /* | |
331 | * do_who_on_channel | |
332 | * | |
333 | * inputs - pointer to client requesting who | |
334 | * - pointer to channel to do who on | |
335 | * - The "real name" of this channel | |
336 | * - int if source_p is a server oper or not | |
337 | * - int if client is member or not | |
338 | * output - NONE | |
339 | * side effects - do a who on given channel | |
340 | */ | |
341 | static void | |
342 | do_who_on_channel(struct Client *source_p, struct Channel *chptr, | |
343 | int server_oper, int member) | |
344 | { | |
345 | struct Client *target_p; | |
346 | struct membership *msptr; | |
5b96d9a6 | 347 | rb_dlink_node *ptr; |
212380e3 AC |
348 | int combine = IsCapable(source_p, CLICAP_MULTI_PREFIX); |
349 | ||
5b96d9a6 | 350 | RB_DLINK_FOREACH(ptr, chptr->members.head) |
212380e3 AC |
351 | { |
352 | msptr = ptr->data; | |
353 | target_p = msptr->client_p; | |
354 | ||
355 | if(server_oper && !IsOper(target_p)) | |
356 | continue; | |
357 | ||
358 | if(member || !IsInvisible(target_p)) | |
359 | do_who(source_p, target_p, chptr->chname, | |
360 | find_channel_status(msptr, combine)); | |
361 | } | |
362 | } | |
363 | ||
364 | /* | |
365 | * do_who | |
366 | * | |
367 | * inputs - pointer to client requesting who | |
368 | * - pointer to client to do who on | |
369 | * - The reported name | |
370 | * - channel flags | |
371 | * output - NONE | |
372 | * side effects - do a who on given person | |
373 | */ | |
374 | ||
375 | static void | |
376 | do_who(struct Client *source_p, struct Client *target_p, const char *chname, const char *op_flags) | |
377 | { | |
378 | char status[5]; | |
379 | ||
7cdb0a09 | 380 | rb_sprintf(status, "%c%s%s", |
212380e3 AC |
381 | target_p->user->away ? 'G' : 'H', IsOper(target_p) ? "*" : "", op_flags); |
382 | ||
383 | sendto_one(source_p, form_str(RPL_WHOREPLY), me.name, source_p->name, | |
384 | (chname) ? (chname) : "*", | |
385 | target_p->username, | |
c88cdb00 | 386 | target_p->host, target_p->servptr->name, target_p->name, |
212380e3 AC |
387 | status, |
388 | ConfigServerHide.flatten_links ? 0 : target_p->hopcount, | |
389 | target_p->info); | |
390 | } |