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