]> jfr.im git - irc/rqf/shadowircd.git/blob - src/send.c
Apply +z to messages blocked by +b and +q as well.
[irc/rqf/shadowircd.git] / src / send.c
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 *
24 * $Id: send.c 3520 2007-06-30 22:15:35Z jilles $
25 */
26
27 #include "stdinc.h"
28 #include "send.h"
29 #include "channel.h"
30 #include "class.h"
31 #include "client.h"
32 #include "common.h"
33 #include "match.h"
34 #include "ircd.h"
35 #include "numeric.h"
36 #include "s_serv.h"
37 #include "s_conf.h"
38 #include "s_newconf.h"
39 #include "logger.h"
40 #include "hook.h"
41 #include "monitor.h"
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
48 static void send_queued_write(rb_fde_t *F, void *data);
49
50 unsigned long current_serial = 0L;
51
52 struct Client *remote_rehash_oper_p;
53
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
72 if(rb_linebuf_len(&to->localClient->buf_sendq) > get_sendq(to))
73 {
74 if(IsServer(to))
75 {
76 sendto_realops_snomask(SNO_GENERAL, L_ALL,
77 "Max SendQ limit exceeded for %s: %u > %lu",
78 to->name,
79 rb_linebuf_len(&to->localClient->buf_sendq),
80 get_sendq(to));
81
82 ilog(L_SERVER, "Max SendQ limit exceeded for %s: %u > %lu",
83 log_client_name(to, SHOW_IP),
84 rb_linebuf_len(&to->localClient->buf_sendq),
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 */
99 rb_linebuf_attach(&to->localClient->buf_sendq, linebuf);
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;
109 if(rb_linebuf_len(&to->localClient->buf_sendq) > 0)
110 send_queued(to);
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
126 /* we assume the caller has already tested for fake direction */
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
139 send_queued(struct Client *to)
140 {
141 int retlen;
142 #ifdef USE_IODEBUG_HOOKS
143 hook_data_int hd;
144 #endif
145 rb_fde_t *F = to->localClient->F;
146 if (!F)
147 return;
148
149 /* cant write anything to a dead socket. */
150 if(IsIOError(to))
151 return;
152
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))
159 return;
160
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
168 if(rb_linebuf_len(&to->localClient->buf_sendq))
169 {
170 while ((retlen =
171 rb_linebuf_flush(F, &to->localClient->buf_sendq)) > 0)
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
185 ClearFlush(to);
186
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
201 if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno)))
202 {
203 dead_link(to);
204 return;
205 }
206 }
207
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
215 ClearFlush(to);
216 }
217
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);
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;
239 ClearFlush(to);
240 send_queued(to);
241 }
242
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
262 rb_linebuf_newbuf(&linebuf);
263
264 va_start(args, pattern);
265 rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
266 va_end(args);
267
268 _send_linebuf(target_p, &linebuf);
269
270 rb_linebuf_donebuf(&linebuf);
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
303 rb_linebuf_newbuf(&linebuf);
304 va_start(args, pattern);
305 rb_linebuf_putmsg(&linebuf, pattern, &args,
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);
312 rb_linebuf_donebuf(&linebuf);
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;
327 char *to;
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
344 rb_linebuf_newbuf(&linebuf);
345 va_start(args, pattern);
346 rb_linebuf_putmsg(&linebuf, pattern, &args,
347 ":%s NOTICE %s ",
348 get_id(&me, target_p), *(to = get_id(target_p, target_p)) != '\0' ? to : "*");
349 va_end(args);
350
351 _send_linebuf(dest_p, &linebuf);
352 rb_linebuf_donebuf(&linebuf);
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;
368 char *to;
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
385 rb_linebuf_newbuf(&linebuf);
386 va_start(args, pattern);
387 rb_linebuf_putmsg(&linebuf, pattern, &args,
388 ":%s %03d %s ",
389 get_id(&me, target_p),
390 numeric, *(to = get_id(target_p, target_p)) != '\0' ? to : "*");
391 va_end(args);
392
393 _send_linebuf(dest_p, &linebuf);
394 rb_linebuf_donebuf(&linebuf);
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;
420 rb_dlink_node *ptr;
421 rb_dlink_node *next_ptr;
422 buf_head_t linebuf;
423
424 /* noone to send to.. */
425 if(rb_dlink_list_length(&serv_list) == 0)
426 return;
427
428 if(chptr != NULL && *chptr->chname != '#')
429 return;
430
431 rb_linebuf_newbuf(&linebuf);
432 va_start(args, format);
433 rb_linebuf_putmsg(&linebuf, format, &args, NULL);
434 va_end(args);
435
436 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, serv_list.head)
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
455 rb_linebuf_donebuf(&linebuf);
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;
471 buf_head_t rb_linebuf_local;
472 buf_head_t rb_linebuf_id;
473 struct Client *target_p;
474 struct membership *msptr;
475 rb_dlink_node *ptr;
476 rb_dlink_node *next_ptr;
477
478 rb_linebuf_newbuf(&rb_linebuf_local);
479 rb_linebuf_newbuf(&rb_linebuf_id);
480
481 current_serial++;
482
483 va_start(args, pattern);
484 rb_vsnprintf(buf, sizeof(buf), pattern, args);
485 va_end(args);
486
487 if(IsServer(source_p))
488 rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
489 ":%s %s", source_p->name, buf);
490 else
491 rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
492 ":%s!%s@%s %s",
493 source_p->name, source_p->username,
494 source_p->host, buf);
495
496 rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s %s", use_id(source_p), buf);
497
498 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->members.head)
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 {
522 send_linebuf_remote(target_p, source_p, &rb_linebuf_id);
523 target_p->from->serial = current_serial;
524 }
525 }
526 else
527 _send_linebuf(target_p, &rb_linebuf_local);
528 }
529
530 rb_linebuf_donebuf(&rb_linebuf_local);
531 rb_linebuf_donebuf(&rb_linebuf_id);
532 }
533
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 {
545 static char buf[BUFSIZE];
546 va_list args;
547 buf_head_t rb_linebuf_local;
548 buf_head_t rb_linebuf_old;
549 buf_head_t rb_linebuf_new;
550 struct Client *target_p;
551 struct membership *msptr;
552 rb_dlink_node *ptr;
553 rb_dlink_node *next_ptr;
554
555 rb_linebuf_newbuf(&rb_linebuf_local);
556 rb_linebuf_newbuf(&rb_linebuf_old);
557 rb_linebuf_newbuf(&rb_linebuf_new);
558
559 current_serial++;
560
561 if(IsServer(source_p))
562 rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
563 ":%s %s %s :%s",
564 source_p->name, command, chptr->chname, text);
565 else
566 rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
567 ":%s!%s@%s %s %s :%s",
568 source_p->name, source_p->username,
569 source_p->host, command, chptr->chname, text);
570
571 if (chptr->mode.mode & MODE_MODERATED)
572 rb_linebuf_putmsg(&rb_linebuf_old, NULL, NULL,
573 ":%s %s %s :%s",
574 use_id(source_p), command, chptr->chname, text);
575 else
576 rb_linebuf_putmsg(&rb_linebuf_old, NULL, NULL,
577 ":%s NOTICE @%s :<%s:%s> %s",
578 use_id(source_p->servptr), chptr->chname,
579 source_p->name, chptr->chname, text);
580 rb_linebuf_putmsg(&rb_linebuf_new, NULL, NULL,
581 ":%s %s =%s :%s",
582 use_id(source_p), command, chptr->chname, text);
583
584 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->members.head)
585 {
586 msptr = ptr->data;
587 target_p = msptr->client_p;
588
589 if(IsIOError(target_p->from) || target_p->from == one)
590 continue;
591
592 if((msptr->flags & CHFL_CHANOP) == 0)
593 continue;
594
595 if(IsDeaf(target_p))
596 continue;
597
598 if(!MyClient(target_p))
599 {
600 /* if we've got a specific type, target must support
601 * CHW.. --fl
602 */
603 if(NotCapable(target_p->from, CAP_CHW))
604 continue;
605
606 if(target_p->from->serial != current_serial)
607 {
608 if (IsCapable(target_p->from, CAP_EOPMOD))
609 send_linebuf_remote(target_p, source_p, &rb_linebuf_new);
610 else
611 send_linebuf_remote(target_p, source_p, &rb_linebuf_old);
612 target_p->from->serial = current_serial;
613 }
614 }
615 else
616 _send_linebuf(target_p, &rb_linebuf_local);
617 }
618
619 rb_linebuf_donebuf(&rb_linebuf_local);
620 rb_linebuf_donebuf(&rb_linebuf_old);
621 rb_linebuf_donebuf(&rb_linebuf_new);
622 }
623
624 /* sendto_channel_local()
625 *
626 * inputs - flags to send to, channel to send to, va_args
627 * outputs - message to local channel members
628 * side effects -
629 */
630 void
631 sendto_channel_local(int type, struct Channel *chptr, const char *pattern, ...)
632 {
633 va_list args;
634 buf_head_t linebuf;
635 struct membership *msptr;
636 struct Client *target_p;
637 rb_dlink_node *ptr;
638 rb_dlink_node *next_ptr;
639
640 rb_linebuf_newbuf(&linebuf);
641
642 va_start(args, pattern);
643 rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
644 va_end(args);
645
646 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head)
647 {
648 msptr = ptr->data;
649 target_p = msptr->client_p;
650
651 if(IsIOError(target_p))
652 continue;
653
654 if(type && ((msptr->flags & type) == 0))
655 continue;
656
657 _send_linebuf(target_p, &linebuf);
658 }
659
660 rb_linebuf_donebuf(&linebuf);
661 }
662
663 /* sendto_channel_local_butone()
664 *
665 * inputs - flags to send to, channel to send to, va_args
666 * - user to ignore when sending
667 * outputs - message to local channel members
668 * side effects -
669 */
670 void
671 sendto_channel_local_butone(struct Client *one, int type, struct Channel *chptr, const char *pattern, ...)
672 {
673 va_list args;
674 buf_head_t linebuf;
675 struct membership *msptr;
676 struct Client *target_p;
677 rb_dlink_node *ptr;
678 rb_dlink_node *next_ptr;
679
680 rb_linebuf_newbuf(&linebuf);
681
682 va_start(args, pattern);
683 rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
684 va_end(args);
685
686 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head)
687 {
688 msptr = ptr->data;
689 target_p = msptr->client_p;
690
691 if(target_p == one)
692 continue;
693
694 if(IsIOError(target_p))
695 continue;
696
697 if(type && ((msptr->flags & type) == 0))
698 continue;
699
700 _send_linebuf(target_p, &linebuf);
701 }
702
703 rb_linebuf_donebuf(&linebuf);
704 }
705
706 /*
707 * sendto_common_channels_local()
708 *
709 * inputs - pointer to client
710 * - pattern to send
711 * output - NONE
712 * side effects - Sends a message to all people on local server who are
713 * in same channel with user.
714 * used by m_nick.c and exit_one_client.
715 */
716 void
717 sendto_common_channels_local(struct Client *user, const char *pattern, ...)
718 {
719 va_list args;
720 rb_dlink_node *ptr;
721 rb_dlink_node *next_ptr;
722 rb_dlink_node *uptr;
723 rb_dlink_node *next_uptr;
724 struct Channel *chptr;
725 struct Client *target_p;
726 struct membership *msptr;
727 struct membership *mscptr;
728 buf_head_t linebuf;
729
730 rb_linebuf_newbuf(&linebuf);
731 va_start(args, pattern);
732 rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
733 va_end(args);
734
735 ++current_serial;
736
737 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, user->user->channel.head)
738 {
739 mscptr = ptr->data;
740 chptr = mscptr->chptr;
741
742 RB_DLINK_FOREACH_SAFE(uptr, next_uptr, chptr->locmembers.head)
743 {
744 msptr = uptr->data;
745 target_p = msptr->client_p;
746
747 if(IsIOError(target_p) ||
748 target_p->serial == current_serial)
749 continue;
750
751 target_p->serial = current_serial;
752 send_linebuf(target_p, &linebuf);
753 }
754 }
755
756 /* this can happen when the user isnt in any channels, but we still
757 * need to send them the data, ie a nick change
758 */
759 if(MyConnect(user) && (user->serial != current_serial))
760 send_linebuf(user, &linebuf);
761
762 rb_linebuf_donebuf(&linebuf);
763 }
764
765 /*
766 * sendto_common_channels_local_butone()
767 *
768 * inputs - pointer to client
769 * - pattern to send
770 * output - NONE
771 * side effects - Sends a message to all people on local server who are
772 * in same channel with user, except for user itself.
773 */
774 void
775 sendto_common_channels_local_butone(struct Client *user, const char *pattern, ...)
776 {
777 va_list args;
778 rb_dlink_node *ptr;
779 rb_dlink_node *next_ptr;
780 rb_dlink_node *uptr;
781 rb_dlink_node *next_uptr;
782 struct Channel *chptr;
783 struct Client *target_p;
784 struct membership *msptr;
785 struct membership *mscptr;
786 buf_head_t linebuf;
787
788 rb_linebuf_newbuf(&linebuf);
789 va_start(args, pattern);
790 rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
791 va_end(args);
792
793 ++current_serial;
794 /* Skip them -- jilles */
795 user->serial = current_serial;
796
797 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, user->user->channel.head)
798 {
799 mscptr = ptr->data;
800 chptr = mscptr->chptr;
801
802 RB_DLINK_FOREACH_SAFE(uptr, next_uptr, chptr->locmembers.head)
803 {
804 msptr = uptr->data;
805 target_p = msptr->client_p;
806
807 if(IsIOError(target_p) ||
808 target_p->serial == current_serial)
809 continue;
810
811 target_p->serial = current_serial;
812 send_linebuf(target_p, &linebuf);
813 }
814 }
815
816 rb_linebuf_donebuf(&linebuf);
817 }
818
819 /* sendto_match_butone()
820 *
821 * inputs - server not to send to, source, mask, type of mask, va_args
822 * output -
823 * side effects - message is sent to matching clients
824 */
825 void
826 sendto_match_butone(struct Client *one, struct Client *source_p,
827 const char *mask, int what, const char *pattern, ...)
828 {
829 static char buf[BUFSIZE];
830 va_list args;
831 struct Client *target_p;
832 rb_dlink_node *ptr;
833 rb_dlink_node *next_ptr;
834 buf_head_t rb_linebuf_local;
835 buf_head_t rb_linebuf_id;
836
837 rb_linebuf_newbuf(&rb_linebuf_local);
838 rb_linebuf_newbuf(&rb_linebuf_id);
839
840 va_start(args, pattern);
841 rb_vsnprintf(buf, sizeof(buf), pattern, args);
842 va_end(args);
843
844 if(IsServer(source_p))
845 rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
846 ":%s %s", source_p->name, buf);
847 else
848 rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
849 ":%s!%s@%s %s",
850 source_p->name, source_p->username,
851 source_p->host, buf);
852
853 rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s %s", use_id(source_p), buf);
854
855 if(what == MATCH_HOST)
856 {
857 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head)
858 {
859 target_p = ptr->data;
860
861 if(match(mask, target_p->host))
862 _send_linebuf(target_p, &rb_linebuf_local);
863 }
864 }
865 /* what = MATCH_SERVER, if it doesnt match us, just send remote */
866 else if(match(mask, me.name))
867 {
868 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head)
869 {
870 target_p = ptr->data;
871 _send_linebuf(target_p, &rb_linebuf_local);
872 }
873 }
874
875 RB_DLINK_FOREACH(ptr, serv_list.head)
876 {
877 target_p = ptr->data;
878
879 if(target_p == one)
880 continue;
881
882 send_linebuf_remote(target_p, source_p, &rb_linebuf_id);
883 }
884
885 rb_linebuf_donebuf(&rb_linebuf_local);
886 rb_linebuf_donebuf(&rb_linebuf_id);
887 }
888
889 /* sendto_match_servs()
890 *
891 * inputs - source, mask to send to, caps needed, va_args
892 * outputs -
893 * side effects - message is sent to matching servers with caps.
894 */
895 void
896 sendto_match_servs(struct Client *source_p, const char *mask, int cap,
897 int nocap, const char *pattern, ...)
898 {
899 static char buf[BUFSIZE];
900 va_list args;
901 rb_dlink_node *ptr;
902 struct Client *target_p;
903 buf_head_t rb_linebuf_id;
904
905 if(EmptyString(mask))
906 return;
907
908 rb_linebuf_newbuf(&rb_linebuf_id);
909
910 va_start(args, pattern);
911 rb_vsnprintf(buf, sizeof(buf), pattern, args);
912 va_end(args);
913
914 rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL,
915 ":%s %s", use_id(source_p), buf);
916
917 current_serial++;
918
919 RB_DLINK_FOREACH(ptr, global_serv_list.head)
920 {
921 target_p = ptr->data;
922
923 /* dont send to ourselves, or back to where it came from.. */
924 if(IsMe(target_p) || target_p->from == source_p->from)
925 continue;
926
927 if(target_p->from->serial == current_serial)
928 continue;
929
930 if(match(mask, target_p->name))
931 {
932 /* if we set the serial here, then we'll never do
933 * a match() again if !IsCapable()
934 */
935 target_p->from->serial = current_serial;
936
937 if(cap && !IsCapable(target_p->from, cap))
938 continue;
939
940 if(nocap && !NotCapable(target_p->from, nocap))
941 continue;
942
943 _send_linebuf(target_p->from, &rb_linebuf_id);
944 }
945 }
946
947 rb_linebuf_donebuf(&rb_linebuf_id);
948 }
949
950 /* sendto_monitor()
951 *
952 * inputs - monitor nick to send to, format, va_args
953 * outputs - message to local users monitoring the given nick
954 * side effects -
955 */
956 void
957 sendto_monitor(struct monitor *monptr, const char *pattern, ...)
958 {
959 va_list args;
960 buf_head_t linebuf;
961 struct Client *target_p;
962 rb_dlink_node *ptr;
963 rb_dlink_node *next_ptr;
964
965 rb_linebuf_newbuf(&linebuf);
966
967 va_start(args, pattern);
968 rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
969 va_end(args);
970
971 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, monptr->users.head)
972 {
973 target_p = ptr->data;
974
975 if(IsIOError(target_p))
976 continue;
977
978 _send_linebuf(target_p, &linebuf);
979 }
980
981 rb_linebuf_donebuf(&linebuf);
982 }
983
984 /* sendto_anywhere()
985 *
986 * inputs - target, source, va_args
987 * outputs -
988 * side effects - client is sent message with correct prefix.
989 */
990 void
991 sendto_anywhere(struct Client *target_p, struct Client *source_p,
992 const char *command, const char *pattern, ...)
993 {
994 va_list args;
995 buf_head_t linebuf;
996
997 rb_linebuf_newbuf(&linebuf);
998
999 va_start(args, pattern);
1000
1001 if(MyClient(target_p))
1002 {
1003 if(IsServer(source_p))
1004 rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s %s %s ",
1005 source_p->name, command,
1006 target_p->name);
1007 else
1008 rb_linebuf_putmsg(&linebuf, pattern, &args,
1009 ":%s!%s@%s %s %s ",
1010 source_p->name, source_p->username,
1011 source_p->host, command,
1012 target_p->name);
1013 }
1014 else
1015 rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s %s %s ",
1016 get_id(source_p, target_p), command,
1017 get_id(target_p, target_p));
1018 va_end(args);
1019
1020 if(MyClient(target_p))
1021 _send_linebuf(target_p, &linebuf);
1022 else
1023 send_linebuf_remote(target_p, source_p, &linebuf);
1024
1025 rb_linebuf_donebuf(&linebuf);
1026 }
1027
1028 /* sendto_realops_snomask()
1029 *
1030 * inputs - snomask needed, level (opers/admin), va_args
1031 * output -
1032 * side effects - message is sent to opers with matching snomasks
1033 */
1034 void
1035 sendto_realops_snomask(int flags, int level, const char *pattern, ...)
1036 {
1037 static char buf[BUFSIZE];
1038 char *snobuf;
1039 struct Client *client_p;
1040 rb_dlink_node *ptr;
1041 rb_dlink_node *next_ptr;
1042 va_list args;
1043 buf_head_t linebuf;
1044
1045 rb_linebuf_newbuf(&linebuf);
1046
1047 /* Be very sure not to do things like "Trying to send to myself"
1048 * L_NETWIDE, otherwise infinite recursion may result! -- jilles */
1049 if (level & L_NETWIDE && ConfigFileEntry.global_snotices)
1050 {
1051 /* rather a lot of copying around, oh well -- jilles */
1052 va_start(args, pattern);
1053 rb_vsnprintf(buf, sizeof(buf), pattern, args);
1054 va_end(args);
1055 rb_linebuf_putmsg(&linebuf, pattern, NULL,
1056 ":%s NOTICE * :*** Notice -- %s", me.name, buf);
1057 snobuf = construct_snobuf(flags);
1058 if (snobuf[1] != '\0')
1059 sendto_server(NULL, NULL, CAP_ENCAP|CAP_TS6, NOCAPS,
1060 ":%s ENCAP * SNOTE %c :%s",
1061 me.id, snobuf[1], buf);
1062 }
1063 else if (remote_rehash_oper_p != NULL)
1064 {
1065 /* rather a lot of copying around, oh well -- jilles */
1066 va_start(args, pattern);
1067 rb_vsnprintf(buf, sizeof(buf), pattern, args);
1068 va_end(args);
1069 rb_linebuf_putmsg(&linebuf, pattern, NULL,
1070 ":%s NOTICE * :*** Notice -- %s", me.name, buf);
1071 sendto_one_notice(remote_rehash_oper_p, ":*** Notice -- %s", buf);
1072 }
1073 else
1074 {
1075 va_start(args, pattern);
1076 rb_linebuf_putmsg(&linebuf, pattern, &args,
1077 ":%s NOTICE * :*** Notice -- ", me.name);
1078 va_end(args);
1079 }
1080 level &= ~L_NETWIDE;
1081
1082 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, local_oper_list.head)
1083 {
1084 client_p = ptr->data;
1085
1086 /* If we're sending it to opers and theyre an admin, skip.
1087 * If we're sending it to admins, and theyre not, skip.
1088 */
1089 if(((level == L_ADMIN) && !IsOperAdmin(client_p)) ||
1090 ((level == L_OPER) && IsOperAdmin(client_p)))
1091 continue;
1092
1093 if(client_p->snomask & flags)
1094 _send_linebuf(client_p, &linebuf);
1095 }
1096
1097 rb_linebuf_donebuf(&linebuf);
1098 }
1099 /* sendto_realops_snomask_from()
1100 *
1101 * inputs - snomask needed, level (opers/admin), source server, va_args
1102 * output -
1103 * side effects - message is sent to opers with matching snomask
1104 */
1105 void
1106 sendto_realops_snomask_from(int flags, int level, struct Client *source_p,
1107 const char *pattern, ...)
1108 {
1109 struct Client *client_p;
1110 rb_dlink_node *ptr;
1111 rb_dlink_node *next_ptr;
1112 va_list args;
1113 buf_head_t linebuf;
1114
1115 rb_linebuf_newbuf(&linebuf);
1116
1117 va_start(args, pattern);
1118 rb_linebuf_putmsg(&linebuf, pattern, &args,
1119 ":%s NOTICE * :*** Notice -- ", source_p->name);
1120 va_end(args);
1121
1122 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, local_oper_list.head)
1123 {
1124 client_p = ptr->data;
1125
1126 /* If we're sending it to opers and theyre an admin, skip.
1127 * If we're sending it to admins, and theyre not, skip.
1128 */
1129 if(((level == L_ADMIN) && !IsOperAdmin(client_p)) ||
1130 ((level == L_OPER) && IsOperAdmin(client_p)))
1131 continue;
1132
1133 if(client_p->snomask & flags)
1134 _send_linebuf(client_p, &linebuf);
1135 }
1136
1137 rb_linebuf_donebuf(&linebuf);
1138 }
1139
1140 /*
1141 * sendto_wallops_flags
1142 *
1143 * inputs - flag types of messages to show to real opers
1144 * - client sending request
1145 * - var args input message
1146 * output - NONE
1147 * side effects - Send a wallops to local opers
1148 */
1149 void
1150 sendto_wallops_flags(int flags, struct Client *source_p, const char *pattern, ...)
1151 {
1152 struct Client *client_p;
1153 rb_dlink_node *ptr;
1154 rb_dlink_node *next_ptr;
1155 va_list args;
1156 buf_head_t linebuf;
1157
1158 rb_linebuf_newbuf(&linebuf);
1159
1160 va_start(args, pattern);
1161
1162 if(IsPerson(source_p))
1163 rb_linebuf_putmsg(&linebuf, pattern, &args,
1164 ":%s!%s@%s WALLOPS :", source_p->name,
1165 source_p->username, source_p->host);
1166 else
1167 rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s WALLOPS :", source_p->name);
1168
1169 va_end(args);
1170
1171 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, IsPerson(source_p) && flags == UMODE_WALLOP ? lclient_list.head : local_oper_list.head)
1172 {
1173 client_p = ptr->data;
1174
1175 if(client_p->umodes & flags)
1176 _send_linebuf(client_p, &linebuf);
1177 }
1178
1179 rb_linebuf_donebuf(&linebuf);
1180 }
1181
1182 /* kill_client()
1183 *
1184 * input - client to send kill to, client to kill, va_args
1185 * output -
1186 * side effects - we issue a kill for the client
1187 */
1188 void
1189 kill_client(struct Client *target_p, struct Client *diedie, const char *pattern, ...)
1190 {
1191 va_list args;
1192 buf_head_t linebuf;
1193
1194 rb_linebuf_newbuf(&linebuf);
1195
1196 va_start(args, pattern);
1197 rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s KILL %s :",
1198 get_id(&me, target_p), get_id(diedie, target_p));
1199 va_end(args);
1200
1201 send_linebuf(target_p, &linebuf);
1202 rb_linebuf_donebuf(&linebuf);
1203 }
1204
1205
1206 /*
1207 * kill_client_serv_butone
1208 *
1209 * inputs - pointer to client to not send to
1210 * - pointer to client to kill
1211 * output - NONE
1212 * side effects - Send a KILL for the given client
1213 * message to all connected servers
1214 * except the client 'one'. Also deal with
1215 * client being unknown to leaf, as in lazylink...
1216 */
1217 void
1218 kill_client_serv_butone(struct Client *one, struct Client *target_p, const char *pattern, ...)
1219 {
1220 static char buf[BUFSIZE];
1221 va_list args;
1222 struct Client *client_p;
1223 rb_dlink_node *ptr;
1224 rb_dlink_node *next_ptr;
1225 buf_head_t rb_linebuf_id;
1226
1227 rb_linebuf_newbuf(&rb_linebuf_id);
1228
1229 va_start(args, pattern);
1230 rb_vsnprintf(buf, sizeof(buf), pattern, args);
1231 va_end(args);
1232
1233 rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s KILL %s :%s",
1234 use_id(&me), use_id(target_p), buf);
1235
1236 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, serv_list.head)
1237 {
1238 client_p = ptr->data;
1239
1240 /* ok, if the client we're supposed to not send to has an
1241 * ID, then we still want to issue the kill there..
1242 */
1243 if(one != NULL && (client_p == one->from) &&
1244 (!has_id(client_p) || !has_id(target_p)))
1245 continue;
1246
1247 _send_linebuf(client_p, &rb_linebuf_id);
1248 }
1249
1250 rb_linebuf_donebuf(&rb_linebuf_id);
1251 }