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