]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * send.c: Functions for sending messages. | |
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 | * | |
8aba962d | 24 | * $Id: send.c 3520 2007-06-30 22:15:35Z jilles $ |
212380e3 AC |
25 | */ |
26 | ||
27 | #include "stdinc.h" | |
212380e3 AC |
28 | #include "send.h" |
29 | #include "channel.h" | |
30 | #include "class.h" | |
31 | #include "client.h" | |
32 | #include "common.h" | |
4562c604 | 33 | #include "match.h" |
212380e3 AC |
34 | #include "ircd.h" |
35 | #include "numeric.h" | |
212380e3 | 36 | #include "s_serv.h" |
212380e3 AC |
37 | #include "s_conf.h" |
38 | #include "s_newconf.h" | |
4016731b | 39 | #include "logger.h" |
212380e3 | 40 | #include "hook.h" |
8aba962d | 41 | #include "monitor.h" |
212380e3 AC |
42 | |
43 | #define LOG_BUFSIZE 2048 | |
44 | ||
45 | /* send the message to the link the target is attached to */ | |
46 | #define send_linebuf(a,b) _send_linebuf((a->from ? a->from : a) ,b) | |
47 | ||
3b2ebd04 JT |
48 | static void send_queued_write(rb_fde_t *F, void *data); |
49 | ||
212380e3 AC |
50 | unsigned long current_serial = 0L; |
51 | ||
ad13bb75 JT |
52 | struct Client *remote_rehash_oper_p; |
53 | ||
212380e3 AC |
54 | /* send_linebuf() |
55 | * | |
56 | * inputs - client to send to, linebuf to attach | |
57 | * outputs - | |
58 | * side effects - linebuf is attached to client | |
59 | */ | |
60 | static int | |
61 | _send_linebuf(struct Client *to, buf_head_t *linebuf) | |
62 | { | |
63 | if(IsMe(to)) | |
64 | { | |
65 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "Trying to send message to myself!"); | |
66 | return 0; | |
67 | } | |
68 | ||
69 | if(!MyConnect(to) || IsIOError(to)) | |
70 | return 0; | |
71 | ||
3b2ebd04 | 72 | if(rb_linebuf_len(&to->localClient->buf_sendq) > get_sendq(to)) |
212380e3 AC |
73 | { |
74 | if(IsServer(to)) | |
75 | { | |
76 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
77 | "Max SendQ limit exceeded for %s: %u > %lu", | |
b3ebc7ab | 78 | to->name, |
3b2ebd04 | 79 | rb_linebuf_len(&to->localClient->buf_sendq), |
212380e3 AC |
80 | get_sendq(to)); |
81 | ||
82 | ilog(L_SERVER, "Max SendQ limit exceeded for %s: %u > %lu", | |
83 | log_client_name(to, SHOW_IP), | |
3b2ebd04 | 84 | rb_linebuf_len(&to->localClient->buf_sendq), |
212380e3 AC |
85 | get_sendq(to)); |
86 | } | |
87 | ||
88 | if(IsClient(to)) | |
89 | to->flags |= FLAGS_SENDQEX; | |
90 | ||
91 | dead_link(to); | |
92 | return -1; | |
93 | } | |
94 | else | |
95 | { | |
96 | /* just attach the linebuf to the sendq instead of | |
97 | * generating a new one | |
98 | */ | |
3b2ebd04 | 99 | rb_linebuf_attach(&to->localClient->buf_sendq, linebuf); |
212380e3 AC |
100 | } |
101 | ||
102 | /* | |
103 | ** Update statistics. The following is slightly incorrect | |
104 | ** because it counts messages even if queued, but bytes | |
105 | ** only really sent. Queued bytes get updated in SendQueued. | |
106 | */ | |
107 | to->localClient->sendM += 1; | |
108 | me.localClient->sendM += 1; | |
3b2ebd04 JT |
109 | if(rb_linebuf_len(&to->localClient->buf_sendq) > 0) |
110 | send_queued(to); | |
212380e3 AC |
111 | return 0; |
112 | } | |
113 | ||
114 | /* send_linebuf_remote() | |
115 | * | |
116 | * inputs - client to attach to, sender, linebuf | |
117 | * outputs - | |
118 | * side effects - client has linebuf attached | |
119 | */ | |
120 | static void | |
121 | send_linebuf_remote(struct Client *to, struct Client *from, buf_head_t *linebuf) | |
122 | { | |
123 | if(to->from) | |
124 | to = to->from; | |
125 | ||
8d0d947d | 126 | /* we assume the caller has already tested for fake direction */ |
212380e3 AC |
127 | |
128 | _send_linebuf(to, linebuf); | |
129 | return; | |
130 | } | |
131 | ||
132 | /* send_queued_write() | |
133 | * | |
134 | * inputs - fd to have queue sent, client we're sending to | |
135 | * outputs - contents of queue | |
136 | * side effects - write is rescheduled if queue isnt emptied | |
137 | */ | |
138 | void | |
3b2ebd04 | 139 | send_queued(struct Client *to) |
212380e3 | 140 | { |
212380e3 | 141 | int retlen; |
212380e3 AC |
142 | #ifdef USE_IODEBUG_HOOKS |
143 | hook_data_int hd; | |
144 | #endif | |
3b2ebd04 | 145 | rb_fde_t *F = to->localClient->F; |
5cd74a3b AC |
146 | if (!F) |
147 | return; | |
148 | ||
212380e3 AC |
149 | /* cant write anything to a dead socket. */ |
150 | if(IsIOError(to)) | |
151 | return; | |
152 | ||
8bd5767b JT |
153 | /* Something wants us to not send anything currently */ |
154 | /* if(IsCork(to)) | |
155 | return; */ | |
156 | ||
157 | /* try to flush later when the write event resets this */ | |
158 | if(IsFlush(to)) | |
c6d72037 VY |
159 | return; |
160 | ||
212380e3 AC |
161 | #ifdef USE_IODEBUG_HOOKS |
162 | hd.client = to; | |
163 | if(to->localClient->buf_sendq.list.head) | |
164 | hd.arg1 = ((buf_line_t *) to->localClient->buf_sendq.list.head->data)->buf + | |
165 | to->localClient->buf_sendq.writeofs; | |
166 | #endif | |
167 | ||
3b2ebd04 | 168 | if(rb_linebuf_len(&to->localClient->buf_sendq)) |
212380e3 AC |
169 | { |
170 | while ((retlen = | |
3b2ebd04 | 171 | rb_linebuf_flush(F, &to->localClient->buf_sendq)) > 0) |
212380e3 AC |
172 | { |
173 | /* We have some data written .. update counters */ | |
174 | #ifdef USE_IODEBUG_HOOKS | |
175 | hd.arg2 = retlen; | |
176 | call_hook(h_iosend_id, &hd); | |
177 | ||
178 | if(to->localClient->buf_sendq.list.head) | |
179 | hd.arg1 = | |
180 | ((buf_line_t *) to->localClient->buf_sendq.list.head-> | |
181 | data)->buf + to->localClient->buf_sendq.writeofs; | |
182 | #endif | |
183 | ||
184 | ||
c6d72037 VY |
185 | ClearFlush(to); |
186 | ||
212380e3 AC |
187 | to->localClient->sendB += retlen; |
188 | me.localClient->sendB += retlen; | |
189 | if(to->localClient->sendB > 1023) | |
190 | { | |
191 | to->localClient->sendK += (to->localClient->sendB >> 10); | |
192 | to->localClient->sendB &= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */ | |
193 | } | |
194 | else if(me.localClient->sendB > 1023) | |
195 | { | |
196 | me.localClient->sendK += (me.localClient->sendB >> 10); | |
197 | me.localClient->sendB &= 0x03ff; | |
198 | } | |
199 | } | |
200 | ||
3b2ebd04 | 201 | if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) |
212380e3 AC |
202 | { |
203 | dead_link(to); | |
204 | return; | |
205 | } | |
206 | } | |
c6d72037 | 207 | |
8bd5767b JT |
208 | if(rb_linebuf_len(&to->localClient->buf_sendq)) |
209 | { | |
210 | SetFlush(to); | |
211 | rb_setselect(to->localClient->F, RB_SELECT_WRITE, | |
212 | send_queued_write, to); | |
213 | } | |
214 | else | |
c6d72037 VY |
215 | ClearFlush(to); |
216 | } | |
217 | ||
8bd5767b JT |
218 | void |
219 | send_pop_queue(struct Client *to) | |
220 | { | |
221 | if(to->from != NULL) | |
222 | to = to->from; | |
223 | if(!MyConnect(to) || IsIOError(to)) | |
224 | return; | |
225 | if(rb_linebuf_len(&to->localClient->buf_sendq) > 0) | |
226 | send_queued(to); | |
3b2ebd04 JT |
227 | } |
228 | ||
229 | /* send_queued_write() | |
230 | * | |
231 | * inputs - fd to have queue sent, client we're sending to | |
232 | * outputs - contents of queue | |
233 | * side effects - write is scheduled if queue isnt emptied | |
234 | */ | |
235 | static void | |
236 | send_queued_write(rb_fde_t *F, void *data) | |
237 | { | |
238 | struct Client *to = data; | |
c6d72037 | 239 | ClearFlush(to); |
3b2ebd04 | 240 | send_queued(to); |
212380e3 AC |
241 | } |
242 | ||
212380e3 AC |
243 | /* sendto_one() |
244 | * | |
245 | * inputs - client to send to, va_args | |
246 | * outputs - client has message put into its queue | |
247 | * side effects - | |
248 | */ | |
249 | void | |
250 | sendto_one(struct Client *target_p, const char *pattern, ...) | |
251 | { | |
252 | va_list args; | |
253 | buf_head_t linebuf; | |
254 | ||
255 | /* send remote if to->from non NULL */ | |
256 | if(target_p->from != NULL) | |
257 | target_p = target_p->from; | |
258 | ||
259 | if(IsIOError(target_p)) | |
260 | return; | |
261 | ||
3b2ebd04 | 262 | rb_linebuf_newbuf(&linebuf); |
212380e3 AC |
263 | |
264 | va_start(args, pattern); | |
3b2ebd04 | 265 | rb_linebuf_putmsg(&linebuf, pattern, &args, NULL); |
212380e3 AC |
266 | va_end(args); |
267 | ||
268 | _send_linebuf(target_p, &linebuf); | |
269 | ||
3b2ebd04 | 270 | rb_linebuf_donebuf(&linebuf); |
212380e3 AC |
271 | |
272 | } | |
273 | ||
274 | /* sendto_one_prefix() | |
275 | * | |
276 | * inputs - client to send to, va_args | |
277 | * outputs - client has message put into its queue | |
278 | * side effects - source(us)/target is chosen based on TS6 capability | |
279 | */ | |
280 | void | |
281 | sendto_one_prefix(struct Client *target_p, struct Client *source_p, | |
282 | const char *command, const char *pattern, ...) | |
283 | { | |
284 | struct Client *dest_p; | |
285 | va_list args; | |
286 | buf_head_t linebuf; | |
287 | ||
288 | /* send remote if to->from non NULL */ | |
289 | if(target_p->from != NULL) | |
290 | dest_p = target_p->from; | |
291 | else | |
292 | dest_p = target_p; | |
293 | ||
294 | if(IsIOError(dest_p)) | |
295 | return; | |
296 | ||
297 | if(IsMe(dest_p)) | |
298 | { | |
299 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "Trying to send to myself!"); | |
300 | return; | |
301 | } | |
302 | ||
3b2ebd04 | 303 | rb_linebuf_newbuf(&linebuf); |
212380e3 | 304 | va_start(args, pattern); |
3b2ebd04 | 305 | rb_linebuf_putmsg(&linebuf, pattern, &args, |
212380e3 AC |
306 | ":%s %s %s ", |
307 | get_id(source_p, target_p), | |
308 | command, get_id(target_p, target_p)); | |
309 | va_end(args); | |
310 | ||
311 | _send_linebuf(dest_p, &linebuf); | |
3b2ebd04 | 312 | rb_linebuf_donebuf(&linebuf); |
212380e3 AC |
313 | } |
314 | ||
315 | /* sendto_one_notice() | |
316 | * | |
317 | * inputs - client to send to, va_args | |
318 | * outputs - client has a NOTICE put into its queue | |
319 | * side effects - source(us)/target is chosen based on TS6 capability | |
320 | */ | |
321 | void | |
322 | sendto_one_notice(struct Client *target_p, const char *pattern, ...) | |
323 | { | |
324 | struct Client *dest_p; | |
325 | va_list args; | |
326 | buf_head_t linebuf; | |
5366977b | 327 | char *to; |
212380e3 AC |
328 | |
329 | /* send remote if to->from non NULL */ | |
330 | if(target_p->from != NULL) | |
331 | dest_p = target_p->from; | |
332 | else | |
333 | dest_p = target_p; | |
334 | ||
335 | if(IsIOError(dest_p)) | |
336 | return; | |
337 | ||
338 | if(IsMe(dest_p)) | |
339 | { | |
340 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "Trying to send to myself!"); | |
341 | return; | |
342 | } | |
343 | ||
3b2ebd04 | 344 | rb_linebuf_newbuf(&linebuf); |
212380e3 | 345 | va_start(args, pattern); |
3b2ebd04 | 346 | rb_linebuf_putmsg(&linebuf, pattern, &args, |
212380e3 | 347 | ":%s NOTICE %s ", |
5366977b | 348 | get_id(&me, target_p), *(to = get_id(target_p, target_p)) != '\0' ? to : "*"); |
212380e3 AC |
349 | va_end(args); |
350 | ||
351 | _send_linebuf(dest_p, &linebuf); | |
3b2ebd04 | 352 | rb_linebuf_donebuf(&linebuf); |
212380e3 AC |
353 | } |
354 | ||
355 | ||
356 | /* sendto_one_numeric() | |
357 | * | |
358 | * inputs - client to send to, va_args | |
359 | * outputs - client has message put into its queue | |
360 | * side effects - source/target is chosen based on TS6 capability | |
361 | */ | |
362 | void | |
363 | sendto_one_numeric(struct Client *target_p, int numeric, const char *pattern, ...) | |
364 | { | |
365 | struct Client *dest_p; | |
366 | va_list args; | |
367 | buf_head_t linebuf; | |
5366977b | 368 | char *to; |
212380e3 AC |
369 | |
370 | /* send remote if to->from non NULL */ | |
371 | if(target_p->from != NULL) | |
372 | dest_p = target_p->from; | |
373 | else | |
374 | dest_p = target_p; | |
375 | ||
376 | if(IsIOError(dest_p)) | |
377 | return; | |
378 | ||
379 | if(IsMe(dest_p)) | |
380 | { | |
381 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "Trying to send to myself!"); | |
382 | return; | |
383 | } | |
384 | ||
3b2ebd04 | 385 | rb_linebuf_newbuf(&linebuf); |
212380e3 | 386 | va_start(args, pattern); |
3b2ebd04 | 387 | rb_linebuf_putmsg(&linebuf, pattern, &args, |
212380e3 AC |
388 | ":%s %03d %s ", |
389 | get_id(&me, target_p), | |
5366977b | 390 | numeric, *(to = get_id(target_p, target_p)) != '\0' ? to : "*"); |
212380e3 AC |
391 | va_end(args); |
392 | ||
393 | _send_linebuf(dest_p, &linebuf); | |
3b2ebd04 | 394 | rb_linebuf_donebuf(&linebuf); |
212380e3 AC |
395 | } |
396 | ||
397 | /* | |
398 | * sendto_server | |
399 | * | |
400 | * inputs - pointer to client to NOT send to | |
401 | * - caps or'd together which must ALL be present | |
402 | * - caps or'd together which must ALL NOT be present | |
403 | * - printf style format string | |
404 | * - args to format string | |
405 | * output - NONE | |
406 | * side effects - Send a message to all connected servers, except the | |
407 | * client 'one' (if non-NULL), as long as the servers | |
408 | * support ALL capabs in 'caps', and NO capabs in 'nocaps'. | |
409 | * | |
410 | * This function was written in an attempt to merge together the other | |
411 | * billion sendto_*serv*() functions, which sprung up with capabs, uids etc | |
412 | * -davidt | |
413 | */ | |
414 | void | |
415 | sendto_server(struct Client *one, struct Channel *chptr, unsigned long caps, | |
416 | unsigned long nocaps, const char *format, ...) | |
417 | { | |
418 | va_list args; | |
419 | struct Client *target_p; | |
330fc5c1 | 420 | rb_dlink_node *ptr; |
637c4932 | 421 | rb_dlink_node *next_ptr; |
212380e3 AC |
422 | buf_head_t linebuf; |
423 | ||
424 | /* noone to send to.. */ | |
330fc5c1 | 425 | if(rb_dlink_list_length(&serv_list) == 0) |
212380e3 AC |
426 | return; |
427 | ||
428 | if(chptr != NULL && *chptr->chname != '#') | |
429 | return; | |
430 | ||
3b2ebd04 | 431 | rb_linebuf_newbuf(&linebuf); |
212380e3 | 432 | va_start(args, format); |
3b2ebd04 | 433 | rb_linebuf_putmsg(&linebuf, format, &args, NULL); |
212380e3 AC |
434 | va_end(args); |
435 | ||
637c4932 | 436 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, serv_list.head) |
212380e3 AC |
437 | { |
438 | target_p = ptr->data; | |
439 | ||
440 | /* check against 'one' */ | |
441 | if(one != NULL && (target_p == one->from)) | |
442 | continue; | |
443 | ||
444 | /* check we have required capabs */ | |
445 | if(!IsCapable(target_p, caps)) | |
446 | continue; | |
447 | ||
448 | /* check we don't have any forbidden capabs */ | |
449 | if(!NotCapable(target_p, nocaps)) | |
450 | continue; | |
451 | ||
452 | _send_linebuf(target_p, &linebuf); | |
453 | } | |
454 | ||
3b2ebd04 | 455 | rb_linebuf_donebuf(&linebuf); |
212380e3 AC |
456 | |
457 | } | |
458 | ||
459 | /* sendto_channel_flags() | |
460 | * | |
461 | * inputs - server not to send to, flags needed, source, channel, va_args | |
462 | * outputs - message is sent to channel members | |
463 | * side effects - | |
464 | */ | |
465 | void | |
466 | sendto_channel_flags(struct Client *one, int type, struct Client *source_p, | |
467 | struct Channel *chptr, const char *pattern, ...) | |
468 | { | |
469 | static char buf[BUFSIZE]; | |
470 | va_list args; | |
3b2ebd04 | 471 | buf_head_t rb_linebuf_local; |
3b2ebd04 | 472 | buf_head_t rb_linebuf_id; |
212380e3 AC |
473 | struct Client *target_p; |
474 | struct membership *msptr; | |
330fc5c1 | 475 | rb_dlink_node *ptr; |
637c4932 | 476 | rb_dlink_node *next_ptr; |
212380e3 | 477 | |
3b2ebd04 | 478 | rb_linebuf_newbuf(&rb_linebuf_local); |
3b2ebd04 | 479 | rb_linebuf_newbuf(&rb_linebuf_id); |
212380e3 AC |
480 | |
481 | current_serial++; | |
482 | ||
483 | va_start(args, pattern); | |
3b2ebd04 | 484 | rb_vsnprintf(buf, sizeof(buf), pattern, args); |
212380e3 AC |
485 | va_end(args); |
486 | ||
487 | if(IsServer(source_p)) | |
3b2ebd04 | 488 | rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL, |
212380e3 AC |
489 | ":%s %s", source_p->name, buf); |
490 | else | |
3b2ebd04 | 491 | rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL, |
212380e3 AC |
492 | ":%s!%s@%s %s", |
493 | source_p->name, source_p->username, | |
494 | source_p->host, buf); | |
495 | ||
3b2ebd04 | 496 | rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s %s", use_id(source_p), buf); |
212380e3 | 497 | |
637c4932 | 498 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->members.head) |
212380e3 AC |
499 | { |
500 | msptr = ptr->data; | |
501 | target_p = msptr->client_p; | |
502 | ||
503 | if(IsIOError(target_p->from) || target_p->from == one) | |
504 | continue; | |
505 | ||
506 | if(type && ((msptr->flags & type) == 0)) | |
507 | continue; | |
508 | ||
509 | if(IsDeaf(target_p)) | |
510 | continue; | |
511 | ||
512 | if(!MyClient(target_p)) | |
513 | { | |
514 | /* if we've got a specific type, target must support | |
515 | * CHW.. --fl | |
516 | */ | |
517 | if(type && NotCapable(target_p->from, CAP_CHW)) | |
518 | continue; | |
519 | ||
520 | if(target_p->from->serial != current_serial) | |
521 | { | |
ba301eff | 522 | send_linebuf_remote(target_p, source_p, &rb_linebuf_id); |
212380e3 AC |
523 | target_p->from->serial = current_serial; |
524 | } | |
525 | } | |
526 | else | |
3b2ebd04 | 527 | _send_linebuf(target_p, &rb_linebuf_local); |
212380e3 AC |
528 | } |
529 | ||
3b2ebd04 | 530 | rb_linebuf_donebuf(&rb_linebuf_local); |
3b2ebd04 | 531 | rb_linebuf_donebuf(&rb_linebuf_id); |
212380e3 AC |
532 | } |
533 | ||
c4d2d014 JT |
534 | /* sendto_channel_flags() |
535 | * | |
536 | * inputs - server not to send to, flags needed, source, channel, va_args | |
537 | * outputs - message is sent to channel members | |
538 | * side effects - | |
539 | */ | |
540 | void | |
541 | sendto_channel_opmod(struct Client *one, struct Client *source_p, | |
542 | struct Channel *chptr, const char *command, | |
543 | const char *text) | |
544 | { | |
c4d2d014 JT |
545 | buf_head_t rb_linebuf_local; |
546 | buf_head_t rb_linebuf_old; | |
547 | buf_head_t rb_linebuf_new; | |
548 | struct Client *target_p; | |
549 | struct membership *msptr; | |
550 | rb_dlink_node *ptr; | |
551 | rb_dlink_node *next_ptr; | |
552 | ||
553 | rb_linebuf_newbuf(&rb_linebuf_local); | |
554 | rb_linebuf_newbuf(&rb_linebuf_old); | |
555 | rb_linebuf_newbuf(&rb_linebuf_new); | |
556 | ||
557 | current_serial++; | |
558 | ||
559 | if(IsServer(source_p)) | |
560 | rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL, | |
561 | ":%s %s %s :%s", | |
562 | source_p->name, command, chptr->chname, text); | |
563 | else | |
564 | rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL, | |
565 | ":%s!%s@%s %s %s :%s", | |
566 | source_p->name, source_p->username, | |
567 | source_p->host, command, chptr->chname, text); | |
568 | ||
569 | if (chptr->mode.mode & MODE_MODERATED) | |
570 | rb_linebuf_putmsg(&rb_linebuf_old, NULL, NULL, | |
571 | ":%s %s %s :%s", | |
572 | use_id(source_p), command, chptr->chname, text); | |
573 | else | |
574 | rb_linebuf_putmsg(&rb_linebuf_old, NULL, NULL, | |
575 | ":%s NOTICE @%s :<%s:%s> %s", | |
576 | use_id(source_p->servptr), chptr->chname, | |
577 | source_p->name, chptr->chname, text); | |
578 | rb_linebuf_putmsg(&rb_linebuf_new, NULL, NULL, | |
579 | ":%s %s =%s :%s", | |
580 | use_id(source_p), command, chptr->chname, text); | |
581 | ||
582 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->members.head) | |
583 | { | |
584 | msptr = ptr->data; | |
585 | target_p = msptr->client_p; | |
586 | ||
587 | if(IsIOError(target_p->from) || target_p->from == one) | |
588 | continue; | |
589 | ||
590 | if((msptr->flags & CHFL_CHANOP) == 0) | |
591 | continue; | |
592 | ||
593 | if(IsDeaf(target_p)) | |
594 | continue; | |
595 | ||
596 | if(!MyClient(target_p)) | |
597 | { | |
598 | /* if we've got a specific type, target must support | |
599 | * CHW.. --fl | |
600 | */ | |
601 | if(NotCapable(target_p->from, CAP_CHW)) | |
602 | continue; | |
603 | ||
604 | if(target_p->from->serial != current_serial) | |
605 | { | |
606 | if (IsCapable(target_p->from, CAP_EOPMOD)) | |
607 | send_linebuf_remote(target_p, source_p, &rb_linebuf_new); | |
608 | else | |
609 | send_linebuf_remote(target_p, source_p, &rb_linebuf_old); | |
610 | target_p->from->serial = current_serial; | |
611 | } | |
612 | } | |
613 | else | |
614 | _send_linebuf(target_p, &rb_linebuf_local); | |
615 | } | |
616 | ||
617 | rb_linebuf_donebuf(&rb_linebuf_local); | |
618 | rb_linebuf_donebuf(&rb_linebuf_old); | |
619 | rb_linebuf_donebuf(&rb_linebuf_new); | |
620 | } | |
212380e3 AC |
621 | |
622 | /* sendto_channel_local() | |
623 | * | |
624 | * inputs - flags to send to, channel to send to, va_args | |
625 | * outputs - message to local channel members | |
626 | * side effects - | |
627 | */ | |
628 | void | |
629 | sendto_channel_local(int type, struct Channel *chptr, const char *pattern, ...) | |
630 | { | |
631 | va_list args; | |
632 | buf_head_t linebuf; | |
633 | struct membership *msptr; | |
634 | struct Client *target_p; | |
330fc5c1 | 635 | rb_dlink_node *ptr; |
637c4932 | 636 | rb_dlink_node *next_ptr; |
212380e3 | 637 | |
3b2ebd04 | 638 | rb_linebuf_newbuf(&linebuf); |
212380e3 AC |
639 | |
640 | va_start(args, pattern); | |
3b2ebd04 | 641 | rb_linebuf_putmsg(&linebuf, pattern, &args, NULL); |
212380e3 AC |
642 | va_end(args); |
643 | ||
637c4932 | 644 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head) |
212380e3 AC |
645 | { |
646 | msptr = ptr->data; | |
647 | target_p = msptr->client_p; | |
648 | ||
649 | if(IsIOError(target_p)) | |
650 | continue; | |
651 | ||
652 | if(type && ((msptr->flags & type) == 0)) | |
653 | continue; | |
654 | ||
655 | _send_linebuf(target_p, &linebuf); | |
656 | } | |
657 | ||
3b2ebd04 | 658 | rb_linebuf_donebuf(&linebuf); |
212380e3 AC |
659 | } |
660 | ||
661 | /* sendto_channel_local_butone() | |
662 | * | |
663 | * inputs - flags to send to, channel to send to, va_args | |
664 | * - user to ignore when sending | |
665 | * outputs - message to local channel members | |
666 | * side effects - | |
667 | */ | |
668 | void | |
669 | sendto_channel_local_butone(struct Client *one, int type, struct Channel *chptr, const char *pattern, ...) | |
670 | { | |
671 | va_list args; | |
672 | buf_head_t linebuf; | |
673 | struct membership *msptr; | |
674 | struct Client *target_p; | |
330fc5c1 | 675 | rb_dlink_node *ptr; |
637c4932 | 676 | rb_dlink_node *next_ptr; |
212380e3 | 677 | |
3b2ebd04 | 678 | rb_linebuf_newbuf(&linebuf); |
212380e3 AC |
679 | |
680 | va_start(args, pattern); | |
3b2ebd04 | 681 | rb_linebuf_putmsg(&linebuf, pattern, &args, NULL); |
212380e3 AC |
682 | va_end(args); |
683 | ||
637c4932 | 684 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head) |
212380e3 AC |
685 | { |
686 | msptr = ptr->data; | |
687 | target_p = msptr->client_p; | |
688 | ||
689 | if(target_p == one) | |
690 | continue; | |
691 | ||
692 | if(IsIOError(target_p)) | |
693 | continue; | |
694 | ||
695 | if(type && ((msptr->flags & type) == 0)) | |
696 | continue; | |
697 | ||
698 | _send_linebuf(target_p, &linebuf); | |
699 | } | |
700 | ||
3b2ebd04 | 701 | rb_linebuf_donebuf(&linebuf); |
212380e3 AC |
702 | } |
703 | ||
704 | /* | |
705 | * sendto_common_channels_local() | |
706 | * | |
707 | * inputs - pointer to client | |
708 | * - pattern to send | |
709 | * output - NONE | |
710 | * side effects - Sends a message to all people on local server who are | |
711 | * in same channel with user. | |
712 | * used by m_nick.c and exit_one_client. | |
713 | */ | |
714 | void | |
715 | sendto_common_channels_local(struct Client *user, const char *pattern, ...) | |
716 | { | |
717 | va_list args; | |
330fc5c1 | 718 | rb_dlink_node *ptr; |
637c4932 | 719 | rb_dlink_node *next_ptr; |
330fc5c1 AC |
720 | rb_dlink_node *uptr; |
721 | rb_dlink_node *next_uptr; | |
212380e3 AC |
722 | struct Channel *chptr; |
723 | struct Client *target_p; | |
724 | struct membership *msptr; | |
725 | struct membership *mscptr; | |
726 | buf_head_t linebuf; | |
727 | ||
3b2ebd04 | 728 | rb_linebuf_newbuf(&linebuf); |
212380e3 | 729 | va_start(args, pattern); |
3b2ebd04 | 730 | rb_linebuf_putmsg(&linebuf, pattern, &args, NULL); |
212380e3 AC |
731 | va_end(args); |
732 | ||
733 | ++current_serial; | |
734 | ||
637c4932 | 735 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, user->user->channel.head) |
212380e3 AC |
736 | { |
737 | mscptr = ptr->data; | |
738 | chptr = mscptr->chptr; | |
739 | ||
5cefa1d6 | 740 | RB_DLINK_FOREACH_SAFE(uptr, next_uptr, chptr->locmembers.head) |
212380e3 AC |
741 | { |
742 | msptr = uptr->data; | |
743 | target_p = msptr->client_p; | |
744 | ||
745 | if(IsIOError(target_p) || | |
746 | target_p->serial == current_serial) | |
747 | continue; | |
748 | ||
749 | target_p->serial = current_serial; | |
750 | send_linebuf(target_p, &linebuf); | |
751 | } | |
752 | } | |
753 | ||
754 | /* this can happen when the user isnt in any channels, but we still | |
755 | * need to send them the data, ie a nick change | |
756 | */ | |
757 | if(MyConnect(user) && (user->serial != current_serial)) | |
758 | send_linebuf(user, &linebuf); | |
759 | ||
3b2ebd04 | 760 | rb_linebuf_donebuf(&linebuf); |
212380e3 AC |
761 | } |
762 | ||
763 | /* | |
764 | * sendto_common_channels_local_butone() | |
765 | * | |
766 | * inputs - pointer to client | |
767 | * - pattern to send | |
768 | * output - NONE | |
769 | * side effects - Sends a message to all people on local server who are | |
770 | * in same channel with user, except for user itself. | |
771 | */ | |
772 | void | |
773 | sendto_common_channels_local_butone(struct Client *user, const char *pattern, ...) | |
774 | { | |
775 | va_list args; | |
330fc5c1 | 776 | rb_dlink_node *ptr; |
637c4932 | 777 | rb_dlink_node *next_ptr; |
330fc5c1 AC |
778 | rb_dlink_node *uptr; |
779 | rb_dlink_node *next_uptr; | |
212380e3 AC |
780 | struct Channel *chptr; |
781 | struct Client *target_p; | |
782 | struct membership *msptr; | |
783 | struct membership *mscptr; | |
784 | buf_head_t linebuf; | |
785 | ||
3b2ebd04 | 786 | rb_linebuf_newbuf(&linebuf); |
212380e3 | 787 | va_start(args, pattern); |
3b2ebd04 | 788 | rb_linebuf_putmsg(&linebuf, pattern, &args, NULL); |
212380e3 AC |
789 | va_end(args); |
790 | ||
791 | ++current_serial; | |
792 | /* Skip them -- jilles */ | |
793 | user->serial = current_serial; | |
794 | ||
637c4932 | 795 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, user->user->channel.head) |
212380e3 AC |
796 | { |
797 | mscptr = ptr->data; | |
798 | chptr = mscptr->chptr; | |
799 | ||
5cefa1d6 | 800 | RB_DLINK_FOREACH_SAFE(uptr, next_uptr, chptr->locmembers.head) |
212380e3 AC |
801 | { |
802 | msptr = uptr->data; | |
803 | target_p = msptr->client_p; | |
804 | ||
805 | if(IsIOError(target_p) || | |
806 | target_p->serial == current_serial) | |
807 | continue; | |
808 | ||
809 | target_p->serial = current_serial; | |
810 | send_linebuf(target_p, &linebuf); | |
811 | } | |
812 | } | |
813 | ||
3b2ebd04 | 814 | rb_linebuf_donebuf(&linebuf); |
212380e3 AC |
815 | } |
816 | ||
817 | /* sendto_match_butone() | |
818 | * | |
819 | * inputs - server not to send to, source, mask, type of mask, va_args | |
820 | * output - | |
821 | * side effects - message is sent to matching clients | |
822 | */ | |
823 | void | |
824 | sendto_match_butone(struct Client *one, struct Client *source_p, | |
825 | const char *mask, int what, const char *pattern, ...) | |
826 | { | |
827 | static char buf[BUFSIZE]; | |
828 | va_list args; | |
829 | struct Client *target_p; | |
330fc5c1 | 830 | rb_dlink_node *ptr; |
637c4932 | 831 | rb_dlink_node *next_ptr; |
3b2ebd04 | 832 | buf_head_t rb_linebuf_local; |
3b2ebd04 | 833 | buf_head_t rb_linebuf_id; |
212380e3 | 834 | |
3b2ebd04 | 835 | rb_linebuf_newbuf(&rb_linebuf_local); |
3b2ebd04 | 836 | rb_linebuf_newbuf(&rb_linebuf_id); |
212380e3 AC |
837 | |
838 | va_start(args, pattern); | |
3b2ebd04 | 839 | rb_vsnprintf(buf, sizeof(buf), pattern, args); |
212380e3 AC |
840 | va_end(args); |
841 | ||
842 | if(IsServer(source_p)) | |
3b2ebd04 | 843 | rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL, |
212380e3 AC |
844 | ":%s %s", source_p->name, buf); |
845 | else | |
3b2ebd04 | 846 | rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL, |
212380e3 AC |
847 | ":%s!%s@%s %s", |
848 | source_p->name, source_p->username, | |
849 | source_p->host, buf); | |
850 | ||
3b2ebd04 | 851 | rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s %s", use_id(source_p), buf); |
212380e3 AC |
852 | |
853 | if(what == MATCH_HOST) | |
854 | { | |
637c4932 | 855 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head) |
212380e3 AC |
856 | { |
857 | target_p = ptr->data; | |
858 | ||
859 | if(match(mask, target_p->host)) | |
3b2ebd04 | 860 | _send_linebuf(target_p, &rb_linebuf_local); |
212380e3 AC |
861 | } |
862 | } | |
863 | /* what = MATCH_SERVER, if it doesnt match us, just send remote */ | |
864 | else if(match(mask, me.name)) | |
865 | { | |
637c4932 | 866 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head) |
212380e3 AC |
867 | { |
868 | target_p = ptr->data; | |
3b2ebd04 | 869 | _send_linebuf(target_p, &rb_linebuf_local); |
212380e3 AC |
870 | } |
871 | } | |
872 | ||
5cefa1d6 | 873 | RB_DLINK_FOREACH(ptr, serv_list.head) |
212380e3 AC |
874 | { |
875 | target_p = ptr->data; | |
876 | ||
877 | if(target_p == one) | |
878 | continue; | |
879 | ||
ba301eff | 880 | send_linebuf_remote(target_p, source_p, &rb_linebuf_id); |
212380e3 AC |
881 | } |
882 | ||
3b2ebd04 JT |
883 | rb_linebuf_donebuf(&rb_linebuf_local); |
884 | rb_linebuf_donebuf(&rb_linebuf_id); | |
212380e3 AC |
885 | } |
886 | ||
887 | /* sendto_match_servs() | |
888 | * | |
889 | * inputs - source, mask to send to, caps needed, va_args | |
890 | * outputs - | |
891 | * side effects - message is sent to matching servers with caps. | |
892 | */ | |
893 | void | |
894 | sendto_match_servs(struct Client *source_p, const char *mask, int cap, | |
895 | int nocap, const char *pattern, ...) | |
896 | { | |
897 | static char buf[BUFSIZE]; | |
898 | va_list args; | |
330fc5c1 | 899 | rb_dlink_node *ptr; |
212380e3 | 900 | struct Client *target_p; |
3b2ebd04 | 901 | buf_head_t rb_linebuf_id; |
212380e3 AC |
902 | |
903 | if(EmptyString(mask)) | |
904 | return; | |
905 | ||
3b2ebd04 | 906 | rb_linebuf_newbuf(&rb_linebuf_id); |
212380e3 AC |
907 | |
908 | va_start(args, pattern); | |
3b2ebd04 | 909 | rb_vsnprintf(buf, sizeof(buf), pattern, args); |
212380e3 AC |
910 | va_end(args); |
911 | ||
3b2ebd04 | 912 | rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, |
212380e3 | 913 | ":%s %s", use_id(source_p), buf); |
212380e3 AC |
914 | |
915 | current_serial++; | |
916 | ||
5cefa1d6 | 917 | RB_DLINK_FOREACH(ptr, global_serv_list.head) |
212380e3 AC |
918 | { |
919 | target_p = ptr->data; | |
920 | ||
921 | /* dont send to ourselves, or back to where it came from.. */ | |
922 | if(IsMe(target_p) || target_p->from == source_p->from) | |
923 | continue; | |
924 | ||
925 | if(target_p->from->serial == current_serial) | |
926 | continue; | |
927 | ||
928 | if(match(mask, target_p->name)) | |
929 | { | |
930 | /* if we set the serial here, then we'll never do | |
931 | * a match() again if !IsCapable() | |
932 | */ | |
933 | target_p->from->serial = current_serial; | |
934 | ||
935 | if(cap && !IsCapable(target_p->from, cap)) | |
936 | continue; | |
937 | ||
938 | if(nocap && !NotCapable(target_p->from, nocap)) | |
939 | continue; | |
940 | ||
ba301eff | 941 | _send_linebuf(target_p->from, &rb_linebuf_id); |
212380e3 AC |
942 | } |
943 | } | |
944 | ||
3b2ebd04 | 945 | rb_linebuf_donebuf(&rb_linebuf_id); |
212380e3 AC |
946 | } |
947 | ||
8aba962d JT |
948 | /* sendto_monitor() |
949 | * | |
950 | * inputs - monitor nick to send to, format, va_args | |
951 | * outputs - message to local users monitoring the given nick | |
952 | * side effects - | |
953 | */ | |
954 | void | |
955 | sendto_monitor(struct monitor *monptr, const char *pattern, ...) | |
956 | { | |
957 | va_list args; | |
958 | buf_head_t linebuf; | |
959 | struct Client *target_p; | |
330fc5c1 | 960 | rb_dlink_node *ptr; |
637c4932 | 961 | rb_dlink_node *next_ptr; |
8aba962d | 962 | |
3b2ebd04 | 963 | rb_linebuf_newbuf(&linebuf); |
8aba962d JT |
964 | |
965 | va_start(args, pattern); | |
3b2ebd04 | 966 | rb_linebuf_putmsg(&linebuf, pattern, &args, NULL); |
8aba962d JT |
967 | va_end(args); |
968 | ||
637c4932 | 969 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, monptr->users.head) |
8aba962d JT |
970 | { |
971 | target_p = ptr->data; | |
972 | ||
973 | if(IsIOError(target_p)) | |
974 | continue; | |
975 | ||
976 | _send_linebuf(target_p, &linebuf); | |
977 | } | |
978 | ||
3b2ebd04 | 979 | rb_linebuf_donebuf(&linebuf); |
8aba962d JT |
980 | } |
981 | ||
212380e3 AC |
982 | /* sendto_anywhere() |
983 | * | |
984 | * inputs - target, source, va_args | |
985 | * outputs - | |
986 | * side effects - client is sent message with correct prefix. | |
987 | */ | |
988 | void | |
989 | sendto_anywhere(struct Client *target_p, struct Client *source_p, | |
990 | const char *command, const char *pattern, ...) | |
991 | { | |
992 | va_list args; | |
993 | buf_head_t linebuf; | |
994 | ||
3b2ebd04 | 995 | rb_linebuf_newbuf(&linebuf); |
212380e3 AC |
996 | |
997 | va_start(args, pattern); | |
998 | ||
999 | if(MyClient(target_p)) | |
1000 | { | |
1001 | if(IsServer(source_p)) | |
3b2ebd04 | 1002 | rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s %s %s ", |
212380e3 AC |
1003 | source_p->name, command, |
1004 | target_p->name); | |
1005 | else | |
3b2ebd04 | 1006 | rb_linebuf_putmsg(&linebuf, pattern, &args, |
212380e3 AC |
1007 | ":%s!%s@%s %s %s ", |
1008 | source_p->name, source_p->username, | |
1009 | source_p->host, command, | |
1010 | target_p->name); | |
1011 | } | |
1012 | else | |
3b2ebd04 | 1013 | rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s %s %s ", |
212380e3 AC |
1014 | get_id(source_p, target_p), command, |
1015 | get_id(target_p, target_p)); | |
1016 | va_end(args); | |
1017 | ||
1018 | if(MyClient(target_p)) | |
1019 | _send_linebuf(target_p, &linebuf); | |
1020 | else | |
1021 | send_linebuf_remote(target_p, source_p, &linebuf); | |
1022 | ||
3b2ebd04 | 1023 | rb_linebuf_donebuf(&linebuf); |
212380e3 AC |
1024 | } |
1025 | ||
212380e3 AC |
1026 | /* sendto_realops_snomask() |
1027 | * | |
1028 | * inputs - snomask needed, level (opers/admin), va_args | |
1029 | * output - | |
1030 | * side effects - message is sent to opers with matching snomasks | |
1031 | */ | |
1032 | void | |
1033 | sendto_realops_snomask(int flags, int level, const char *pattern, ...) | |
1034 | { | |
1035 | static char buf[BUFSIZE]; | |
1036 | char *snobuf; | |
1037 | struct Client *client_p; | |
330fc5c1 | 1038 | rb_dlink_node *ptr; |
637c4932 | 1039 | rb_dlink_node *next_ptr; |
212380e3 AC |
1040 | va_list args; |
1041 | buf_head_t linebuf; | |
1042 | ||
3b2ebd04 | 1043 | rb_linebuf_newbuf(&linebuf); |
212380e3 AC |
1044 | |
1045 | /* Be very sure not to do things like "Trying to send to myself" | |
1046 | * L_NETWIDE, otherwise infinite recursion may result! -- jilles */ | |
1047 | if (level & L_NETWIDE && ConfigFileEntry.global_snotices) | |
1048 | { | |
1049 | /* rather a lot of copying around, oh well -- jilles */ | |
1050 | va_start(args, pattern); | |
3b2ebd04 | 1051 | rb_vsnprintf(buf, sizeof(buf), pattern, args); |
212380e3 | 1052 | va_end(args); |
3b2ebd04 | 1053 | rb_linebuf_putmsg(&linebuf, pattern, NULL, |
212380e3 AC |
1054 | ":%s NOTICE * :*** Notice -- %s", me.name, buf); |
1055 | snobuf = construct_snobuf(flags); | |
1056 | if (snobuf[1] != '\0') | |
212380e3 AC |
1057 | sendto_server(NULL, NULL, CAP_ENCAP|CAP_TS6, NOCAPS, |
1058 | ":%s ENCAP * SNOTE %c :%s", | |
1059 | me.id, snobuf[1], buf); | |
212380e3 | 1060 | } |
ad13bb75 JT |
1061 | else if (remote_rehash_oper_p != NULL) |
1062 | { | |
1063 | /* rather a lot of copying around, oh well -- jilles */ | |
1064 | va_start(args, pattern); | |
1065 | rb_vsnprintf(buf, sizeof(buf), pattern, args); | |
1066 | va_end(args); | |
1067 | rb_linebuf_putmsg(&linebuf, pattern, NULL, | |
1068 | ":%s NOTICE * :*** Notice -- %s", me.name, buf); | |
1069 | sendto_one_notice(remote_rehash_oper_p, ":*** Notice -- %s", buf); | |
1070 | } | |
212380e3 AC |
1071 | else |
1072 | { | |
1073 | va_start(args, pattern); | |
3b2ebd04 | 1074 | rb_linebuf_putmsg(&linebuf, pattern, &args, |
212380e3 AC |
1075 | ":%s NOTICE * :*** Notice -- ", me.name); |
1076 | va_end(args); | |
1077 | } | |
1078 | level &= ~L_NETWIDE; | |
1079 | ||
637c4932 | 1080 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, local_oper_list.head) |
212380e3 AC |
1081 | { |
1082 | client_p = ptr->data; | |
1083 | ||
1084 | /* If we're sending it to opers and theyre an admin, skip. | |
1085 | * If we're sending it to admins, and theyre not, skip. | |
1086 | */ | |
1087 | if(((level == L_ADMIN) && !IsOperAdmin(client_p)) || | |
1088 | ((level == L_OPER) && IsOperAdmin(client_p))) | |
1089 | continue; | |
1090 | ||
1091 | if(client_p->snomask & flags) | |
1092 | _send_linebuf(client_p, &linebuf); | |
1093 | } | |
1094 | ||
3b2ebd04 | 1095 | rb_linebuf_donebuf(&linebuf); |
212380e3 AC |
1096 | } |
1097 | /* sendto_realops_snomask_from() | |
1098 | * | |
1099 | * inputs - snomask needed, level (opers/admin), source server, va_args | |
1100 | * output - | |
1101 | * side effects - message is sent to opers with matching snomask | |
1102 | */ | |
1103 | void | |
1104 | sendto_realops_snomask_from(int flags, int level, struct Client *source_p, | |
1105 | const char *pattern, ...) | |
1106 | { | |
1107 | struct Client *client_p; | |
330fc5c1 | 1108 | rb_dlink_node *ptr; |
637c4932 | 1109 | rb_dlink_node *next_ptr; |
212380e3 AC |
1110 | va_list args; |
1111 | buf_head_t linebuf; | |
1112 | ||
3b2ebd04 | 1113 | rb_linebuf_newbuf(&linebuf); |
212380e3 AC |
1114 | |
1115 | va_start(args, pattern); | |
3b2ebd04 | 1116 | rb_linebuf_putmsg(&linebuf, pattern, &args, |
212380e3 AC |
1117 | ":%s NOTICE * :*** Notice -- ", source_p->name); |
1118 | va_end(args); | |
1119 | ||
637c4932 | 1120 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, local_oper_list.head) |
212380e3 AC |
1121 | { |
1122 | client_p = ptr->data; | |
1123 | ||
1124 | /* If we're sending it to opers and theyre an admin, skip. | |
1125 | * If we're sending it to admins, and theyre not, skip. | |
1126 | */ | |
1127 | if(((level == L_ADMIN) && !IsOperAdmin(client_p)) || | |
1128 | ((level == L_OPER) && IsOperAdmin(client_p))) | |
1129 | continue; | |
1130 | ||
1131 | if(client_p->snomask & flags) | |
1132 | _send_linebuf(client_p, &linebuf); | |
1133 | } | |
1134 | ||
3b2ebd04 | 1135 | rb_linebuf_donebuf(&linebuf); |
212380e3 AC |
1136 | } |
1137 | ||
1138 | /* | |
1139 | * sendto_wallops_flags | |
1140 | * | |
1141 | * inputs - flag types of messages to show to real opers | |
1142 | * - client sending request | |
1143 | * - var args input message | |
1144 | * output - NONE | |
1145 | * side effects - Send a wallops to local opers | |
1146 | */ | |
1147 | void | |
1148 | sendto_wallops_flags(int flags, struct Client *source_p, const char *pattern, ...) | |
1149 | { | |
1150 | struct Client *client_p; | |
330fc5c1 | 1151 | rb_dlink_node *ptr; |
637c4932 | 1152 | rb_dlink_node *next_ptr; |
212380e3 AC |
1153 | va_list args; |
1154 | buf_head_t linebuf; | |
1155 | ||
3b2ebd04 | 1156 | rb_linebuf_newbuf(&linebuf); |
212380e3 AC |
1157 | |
1158 | va_start(args, pattern); | |
1159 | ||
1160 | if(IsPerson(source_p)) | |
3b2ebd04 | 1161 | rb_linebuf_putmsg(&linebuf, pattern, &args, |
212380e3 AC |
1162 | ":%s!%s@%s WALLOPS :", source_p->name, |
1163 | source_p->username, source_p->host); | |
1164 | else | |
3b2ebd04 | 1165 | rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s WALLOPS :", source_p->name); |
212380e3 AC |
1166 | |
1167 | va_end(args); | |
1168 | ||
637c4932 | 1169 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, IsPerson(source_p) && flags == UMODE_WALLOP ? lclient_list.head : local_oper_list.head) |
212380e3 AC |
1170 | { |
1171 | client_p = ptr->data; | |
1172 | ||
1173 | if(client_p->umodes & flags) | |
1174 | _send_linebuf(client_p, &linebuf); | |
1175 | } | |
1176 | ||
3b2ebd04 | 1177 | rb_linebuf_donebuf(&linebuf); |
212380e3 AC |
1178 | } |
1179 | ||
1180 | /* kill_client() | |
1181 | * | |
1182 | * input - client to send kill to, client to kill, va_args | |
1183 | * output - | |
1184 | * side effects - we issue a kill for the client | |
1185 | */ | |
1186 | void | |
1187 | kill_client(struct Client *target_p, struct Client *diedie, const char *pattern, ...) | |
1188 | { | |
1189 | va_list args; | |
1190 | buf_head_t linebuf; | |
1191 | ||
3b2ebd04 | 1192 | rb_linebuf_newbuf(&linebuf); |
212380e3 AC |
1193 | |
1194 | va_start(args, pattern); | |
3b2ebd04 | 1195 | rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s KILL %s :", |
212380e3 AC |
1196 | get_id(&me, target_p), get_id(diedie, target_p)); |
1197 | va_end(args); | |
1198 | ||
1199 | send_linebuf(target_p, &linebuf); | |
3b2ebd04 | 1200 | rb_linebuf_donebuf(&linebuf); |
212380e3 AC |
1201 | } |
1202 | ||
1203 | ||
1204 | /* | |
1205 | * kill_client_serv_butone | |
1206 | * | |
1207 | * inputs - pointer to client to not send to | |
1208 | * - pointer to client to kill | |
1209 | * output - NONE | |
1210 | * side effects - Send a KILL for the given client | |
1211 | * message to all connected servers | |
1212 | * except the client 'one'. Also deal with | |
1213 | * client being unknown to leaf, as in lazylink... | |
1214 | */ | |
1215 | void | |
1216 | kill_client_serv_butone(struct Client *one, struct Client *target_p, const char *pattern, ...) | |
1217 | { | |
1218 | static char buf[BUFSIZE]; | |
1219 | va_list args; | |
1220 | struct Client *client_p; | |
330fc5c1 | 1221 | rb_dlink_node *ptr; |
637c4932 | 1222 | rb_dlink_node *next_ptr; |
3b2ebd04 | 1223 | buf_head_t rb_linebuf_id; |
212380e3 | 1224 | |
3b2ebd04 | 1225 | rb_linebuf_newbuf(&rb_linebuf_id); |
212380e3 AC |
1226 | |
1227 | va_start(args, pattern); | |
3b2ebd04 | 1228 | rb_vsnprintf(buf, sizeof(buf), pattern, args); |
212380e3 AC |
1229 | va_end(args); |
1230 | ||
3b2ebd04 | 1231 | rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s KILL %s :%s", |
212380e3 AC |
1232 | use_id(&me), use_id(target_p), buf); |
1233 | ||
637c4932 | 1234 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, serv_list.head) |
212380e3 AC |
1235 | { |
1236 | client_p = ptr->data; | |
1237 | ||
1238 | /* ok, if the client we're supposed to not send to has an | |
1239 | * ID, then we still want to issue the kill there.. | |
1240 | */ | |
1241 | if(one != NULL && (client_p == one->from) && | |
1242 | (!has_id(client_p) || !has_id(target_p))) | |
1243 | continue; | |
1244 | ||
ba301eff | 1245 | _send_linebuf(client_p, &rb_linebuf_id); |
212380e3 AC |
1246 | } |
1247 | ||
3b2ebd04 | 1248 | rb_linebuf_donebuf(&rb_linebuf_id); |
212380e3 | 1249 | } |