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