]> jfr.im git - irc/rqf/shadowircd.git/blame - src/send.c
Mention that @#chan/+#chan requires CHW capab.
[irc/rqf/shadowircd.git] / src / send.c
CommitLineData
212380e3 1/*
2 * ircd-ratbox: A slightly useful ircd.
3 * send.c: Functions for sending messages.
4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
23 *
8aba962d 24 * $Id: send.c 3520 2007-06-30 22:15:35Z jilles $
212380e3 25 */
26
27#include "stdinc.h"
212380e3 28#include "send.h"
29#include "channel.h"
30#include "class.h"
31#include "client.h"
32#include "common.h"
13ae2f4b 33#include "match.h"
212380e3 34#include "ircd.h"
35#include "numeric.h"
212380e3 36#include "s_serv.h"
212380e3 37#include "s_conf.h"
38#include "s_newconf.h"
d3455e2c 39#include "logger.h"
212380e3 40#include "hook.h"
8aba962d 41#include "monitor.h"
212380e3 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
780087dc
JT
48static void send_queued_write(rb_fde_t *F, void *data);
49
212380e3 50unsigned long current_serial = 0L;
51
dbbe21ed
JT
52struct Client *remote_rehash_oper_p;
53
212380e3 54/* send_linebuf()
55 *
56 * inputs - client to send to, linebuf to attach
57 * outputs -
58 * side effects - linebuf is attached to client
59 */
60static 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
780087dc 72 if(rb_linebuf_len(&to->localClient->buf_sendq) > get_sendq(to))
212380e3 73 {
74 if(IsServer(to))
75 {
76 sendto_realops_snomask(SNO_GENERAL, L_ALL,
77 "Max SendQ limit exceeded for %s: %u > %lu",
715b28fe 78 to->name,
780087dc 79 rb_linebuf_len(&to->localClient->buf_sendq),
212380e3 80 get_sendq(to));
81
82 ilog(L_SERVER, "Max SendQ limit exceeded for %s: %u > %lu",
83 log_client_name(to, SHOW_IP),
780087dc 84 rb_linebuf_len(&to->localClient->buf_sendq),
212380e3 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 */
780087dc 99 rb_linebuf_attach(&to->localClient->buf_sendq, linebuf);
212380e3 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;
780087dc
JT
109 if(rb_linebuf_len(&to->localClient->buf_sendq) > 0)
110 send_queued(to);
212380e3 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 */
120static void
121send_linebuf_remote(struct Client *to, struct Client *from, buf_head_t *linebuf)
122{
123 if(to->from)
124 to = to->from;
125
2386ae04 126 /* we assume the caller has already tested for fake direction */
212380e3 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 */
138void
780087dc 139send_queued(struct Client *to)
212380e3 140{
212380e3 141 int retlen;
212380e3 142#ifdef USE_IODEBUG_HOOKS
143 hook_data_int hd;
144#endif
780087dc 145 rb_fde_t *F = to->localClient->F;
5cd74a3b
WP
146 if (!F)
147 return;
148
212380e3 149 /* cant write anything to a dead socket. */
150 if(IsIOError(to))
151 return;
152
b717a466
JT
153 /* Something wants us to not send anything currently */
154 /* if(IsCork(to))
155 return; */
156
157 /* try to flush later when the write event resets this */
158 if(IsFlush(to))
8db00894
VY
159 return;
160
212380e3 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
780087dc 168 if(rb_linebuf_len(&to->localClient->buf_sendq))
212380e3 169 {
170 while ((retlen =
780087dc 171 rb_linebuf_flush(F, &to->localClient->buf_sendq)) > 0)
212380e3 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
8db00894
VY
185 ClearFlush(to);
186
212380e3 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
780087dc 201 if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno)))
212380e3 202 {
203 dead_link(to);
204 return;
205 }
206 }
8db00894 207
b717a466
JT
208 if(rb_linebuf_len(&to->localClient->buf_sendq))
209 {
210 SetFlush(to);
211 rb_setselect(to->localClient->F, RB_SELECT_WRITE,
212 send_queued_write, to);
213 }
214 else
8db00894
VY
215 ClearFlush(to);
216}
217
b717a466
JT
218void
219send_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);
780087dc
JT
227}
228
229/* send_queued_write()
230 *
231 * inputs - fd to have queue sent, client we're sending to
232 * outputs - contents of queue
233 * side effects - write is scheduled if queue isnt emptied
234 */
235static void
236send_queued_write(rb_fde_t *F, void *data)
237{
238 struct Client *to = data;
8db00894 239 ClearFlush(to);
780087dc 240 send_queued(to);
212380e3 241}
242
212380e3 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 */
249void
250sendto_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
780087dc 262 rb_linebuf_newbuf(&linebuf);
212380e3 263
264 va_start(args, pattern);
780087dc 265 rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
212380e3 266 va_end(args);
267
268 _send_linebuf(target_p, &linebuf);
269
780087dc 270 rb_linebuf_donebuf(&linebuf);
212380e3 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 */
280void
281sendto_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
780087dc 303 rb_linebuf_newbuf(&linebuf);
212380e3 304 va_start(args, pattern);
780087dc 305 rb_linebuf_putmsg(&linebuf, pattern, &args,
212380e3 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);
780087dc 312 rb_linebuf_donebuf(&linebuf);
212380e3 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 */
321void
322sendto_one_notice(struct Client *target_p, const char *pattern, ...)
323{
324 struct Client *dest_p;
325 va_list args;
326 buf_head_t linebuf;
5366977b 327 char *to;
212380e3 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
780087dc 344 rb_linebuf_newbuf(&linebuf);
212380e3 345 va_start(args, pattern);
780087dc 346 rb_linebuf_putmsg(&linebuf, pattern, &args,
212380e3 347 ":%s NOTICE %s ",
5366977b 348 get_id(&me, target_p), *(to = get_id(target_p, target_p)) != '\0' ? to : "*");
212380e3 349 va_end(args);
350
351 _send_linebuf(dest_p, &linebuf);
780087dc 352 rb_linebuf_donebuf(&linebuf);
212380e3 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 */
362void
363sendto_one_numeric(struct Client *target_p, int numeric, const char *pattern, ...)
364{
365 struct Client *dest_p;
366 va_list args;
367 buf_head_t linebuf;
5366977b 368 char *to;
212380e3 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
780087dc 385 rb_linebuf_newbuf(&linebuf);
212380e3 386 va_start(args, pattern);
780087dc 387 rb_linebuf_putmsg(&linebuf, pattern, &args,
212380e3 388 ":%s %03d %s ",
389 get_id(&me, target_p),
5366977b 390 numeric, *(to = get_id(target_p, target_p)) != '\0' ? to : "*");
212380e3 391 va_end(args);
392
393 _send_linebuf(dest_p, &linebuf);
780087dc 394 rb_linebuf_donebuf(&linebuf);
212380e3 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 */
414void
415sendto_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;
af81d5a0 420 rb_dlink_node *ptr;
90a3c35b 421 rb_dlink_node *next_ptr;
212380e3 422 buf_head_t linebuf;
423
424 /* noone to send to.. */
af81d5a0 425 if(rb_dlink_list_length(&serv_list) == 0)
212380e3 426 return;
427
428 if(chptr != NULL && *chptr->chname != '#')
429 return;
430
780087dc 431 rb_linebuf_newbuf(&linebuf);
212380e3 432 va_start(args, format);
780087dc 433 rb_linebuf_putmsg(&linebuf, format, &args, NULL);
212380e3 434 va_end(args);
435
90a3c35b 436 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, serv_list.head)
212380e3 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
780087dc 455 rb_linebuf_donebuf(&linebuf);
212380e3 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 */
465void
466sendto_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;
780087dc 471 buf_head_t rb_linebuf_local;
780087dc 472 buf_head_t rb_linebuf_id;
212380e3 473 struct Client *target_p;
474 struct membership *msptr;
af81d5a0 475 rb_dlink_node *ptr;
90a3c35b 476 rb_dlink_node *next_ptr;
212380e3 477
780087dc 478 rb_linebuf_newbuf(&rb_linebuf_local);
780087dc 479 rb_linebuf_newbuf(&rb_linebuf_id);
212380e3 480
481 current_serial++;
482
483 va_start(args, pattern);
780087dc 484 rb_vsnprintf(buf, sizeof(buf), pattern, args);
212380e3 485 va_end(args);
486
487 if(IsServer(source_p))
780087dc 488 rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
212380e3 489 ":%s %s", source_p->name, buf);
490 else
780087dc 491 rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
212380e3 492 ":%s!%s@%s %s",
493 source_p->name, source_p->username,
494 source_p->host, buf);
495
780087dc 496 rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s %s", use_id(source_p), buf);
212380e3 497
90a3c35b 498 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->members.head)
212380e3 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 {
ad884f93 522 send_linebuf_remote(target_p, source_p, &rb_linebuf_id);
212380e3 523 target_p->from->serial = current_serial;
524 }
525 }
526 else
780087dc 527 _send_linebuf(target_p, &rb_linebuf_local);
212380e3 528 }
529
780087dc 530 rb_linebuf_donebuf(&rb_linebuf_local);
780087dc 531 rb_linebuf_donebuf(&rb_linebuf_id);
212380e3 532}
533
534
535/* sendto_channel_local()
536 *
537 * inputs - flags to send to, channel to send to, va_args
538 * outputs - message to local channel members
539 * side effects -
540 */
541void
542sendto_channel_local(int type, struct Channel *chptr, const char *pattern, ...)
543{
544 va_list args;
545 buf_head_t linebuf;
546 struct membership *msptr;
547 struct Client *target_p;
af81d5a0 548 rb_dlink_node *ptr;
90a3c35b 549 rb_dlink_node *next_ptr;
212380e3 550
780087dc 551 rb_linebuf_newbuf(&linebuf);
212380e3 552
553 va_start(args, pattern);
780087dc 554 rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
212380e3 555 va_end(args);
556
90a3c35b 557 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head)
212380e3 558 {
559 msptr = ptr->data;
560 target_p = msptr->client_p;
561
562 if(IsIOError(target_p))
563 continue;
564
565 if(type && ((msptr->flags & type) == 0))
566 continue;
567
568 _send_linebuf(target_p, &linebuf);
569 }
570
780087dc 571 rb_linebuf_donebuf(&linebuf);
212380e3 572}
573
574/* sendto_channel_local_butone()
575 *
576 * inputs - flags to send to, channel to send to, va_args
577 * - user to ignore when sending
578 * outputs - message to local channel members
579 * side effects -
580 */
581void
582sendto_channel_local_butone(struct Client *one, int type, struct Channel *chptr, const char *pattern, ...)
583{
584 va_list args;
585 buf_head_t linebuf;
586 struct membership *msptr;
587 struct Client *target_p;
af81d5a0 588 rb_dlink_node *ptr;
90a3c35b 589 rb_dlink_node *next_ptr;
212380e3 590
780087dc 591 rb_linebuf_newbuf(&linebuf);
212380e3 592
593 va_start(args, pattern);
780087dc 594 rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
212380e3 595 va_end(args);
596
90a3c35b 597 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head)
212380e3 598 {
599 msptr = ptr->data;
600 target_p = msptr->client_p;
601
602 if(target_p == one)
603 continue;
604
605 if(IsIOError(target_p))
606 continue;
607
608 if(type && ((msptr->flags & type) == 0))
609 continue;
610
611 _send_linebuf(target_p, &linebuf);
612 }
613
780087dc 614 rb_linebuf_donebuf(&linebuf);
212380e3 615}
616
617/*
618 * sendto_common_channels_local()
619 *
620 * inputs - pointer to client
621 * - pattern to send
622 * output - NONE
623 * side effects - Sends a message to all people on local server who are
624 * in same channel with user.
625 * used by m_nick.c and exit_one_client.
626 */
627void
628sendto_common_channels_local(struct Client *user, const char *pattern, ...)
629{
630 va_list args;
af81d5a0 631 rb_dlink_node *ptr;
90a3c35b 632 rb_dlink_node *next_ptr;
af81d5a0
WP
633 rb_dlink_node *uptr;
634 rb_dlink_node *next_uptr;
212380e3 635 struct Channel *chptr;
636 struct Client *target_p;
637 struct membership *msptr;
638 struct membership *mscptr;
639 buf_head_t linebuf;
640
780087dc 641 rb_linebuf_newbuf(&linebuf);
212380e3 642 va_start(args, pattern);
780087dc 643 rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
212380e3 644 va_end(args);
645
646 ++current_serial;
647
90a3c35b 648 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, user->user->channel.head)
212380e3 649 {
650 mscptr = ptr->data;
651 chptr = mscptr->chptr;
652
8e69bb4e 653 RB_DLINK_FOREACH_SAFE(uptr, next_uptr, chptr->locmembers.head)
212380e3 654 {
655 msptr = uptr->data;
656 target_p = msptr->client_p;
657
658 if(IsIOError(target_p) ||
659 target_p->serial == current_serial)
660 continue;
661
662 target_p->serial = current_serial;
663 send_linebuf(target_p, &linebuf);
664 }
665 }
666
667 /* this can happen when the user isnt in any channels, but we still
668 * need to send them the data, ie a nick change
669 */
670 if(MyConnect(user) && (user->serial != current_serial))
671 send_linebuf(user, &linebuf);
672
780087dc 673 rb_linebuf_donebuf(&linebuf);
212380e3 674}
675
676/*
677 * sendto_common_channels_local_butone()
678 *
679 * inputs - pointer to client
680 * - pattern to send
681 * output - NONE
682 * side effects - Sends a message to all people on local server who are
683 * in same channel with user, except for user itself.
684 */
685void
686sendto_common_channels_local_butone(struct Client *user, const char *pattern, ...)
687{
688 va_list args;
af81d5a0 689 rb_dlink_node *ptr;
90a3c35b 690 rb_dlink_node *next_ptr;
af81d5a0
WP
691 rb_dlink_node *uptr;
692 rb_dlink_node *next_uptr;
212380e3 693 struct Channel *chptr;
694 struct Client *target_p;
695 struct membership *msptr;
696 struct membership *mscptr;
697 buf_head_t linebuf;
698
780087dc 699 rb_linebuf_newbuf(&linebuf);
212380e3 700 va_start(args, pattern);
780087dc 701 rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
212380e3 702 va_end(args);
703
704 ++current_serial;
705 /* Skip them -- jilles */
706 user->serial = current_serial;
707
90a3c35b 708 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, user->user->channel.head)
212380e3 709 {
710 mscptr = ptr->data;
711 chptr = mscptr->chptr;
712
8e69bb4e 713 RB_DLINK_FOREACH_SAFE(uptr, next_uptr, chptr->locmembers.head)
212380e3 714 {
715 msptr = uptr->data;
716 target_p = msptr->client_p;
717
718 if(IsIOError(target_p) ||
719 target_p->serial == current_serial)
720 continue;
721
722 target_p->serial = current_serial;
723 send_linebuf(target_p, &linebuf);
724 }
725 }
726
780087dc 727 rb_linebuf_donebuf(&linebuf);
212380e3 728}
729
730/* sendto_match_butone()
731 *
732 * inputs - server not to send to, source, mask, type of mask, va_args
733 * output -
734 * side effects - message is sent to matching clients
735 */
736void
737sendto_match_butone(struct Client *one, struct Client *source_p,
738 const char *mask, int what, const char *pattern, ...)
739{
740 static char buf[BUFSIZE];
741 va_list args;
742 struct Client *target_p;
af81d5a0 743 rb_dlink_node *ptr;
90a3c35b 744 rb_dlink_node *next_ptr;
780087dc 745 buf_head_t rb_linebuf_local;
780087dc 746 buf_head_t rb_linebuf_id;
212380e3 747
780087dc 748 rb_linebuf_newbuf(&rb_linebuf_local);
780087dc 749 rb_linebuf_newbuf(&rb_linebuf_id);
212380e3 750
751 va_start(args, pattern);
780087dc 752 rb_vsnprintf(buf, sizeof(buf), pattern, args);
212380e3 753 va_end(args);
754
755 if(IsServer(source_p))
780087dc 756 rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
212380e3 757 ":%s %s", source_p->name, buf);
758 else
780087dc 759 rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
212380e3 760 ":%s!%s@%s %s",
761 source_p->name, source_p->username,
762 source_p->host, buf);
763
780087dc 764 rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s %s", use_id(source_p), buf);
212380e3 765
766 if(what == MATCH_HOST)
767 {
90a3c35b 768 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head)
212380e3 769 {
770 target_p = ptr->data;
771
772 if(match(mask, target_p->host))
780087dc 773 _send_linebuf(target_p, &rb_linebuf_local);
212380e3 774 }
775 }
776 /* what = MATCH_SERVER, if it doesnt match us, just send remote */
777 else if(match(mask, me.name))
778 {
90a3c35b 779 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head)
212380e3 780 {
781 target_p = ptr->data;
780087dc 782 _send_linebuf(target_p, &rb_linebuf_local);
212380e3 783 }
784 }
785
8e69bb4e 786 RB_DLINK_FOREACH(ptr, serv_list.head)
212380e3 787 {
788 target_p = ptr->data;
789
790 if(target_p == one)
791 continue;
792
ad884f93 793 send_linebuf_remote(target_p, source_p, &rb_linebuf_id);
212380e3 794 }
795
780087dc
JT
796 rb_linebuf_donebuf(&rb_linebuf_local);
797 rb_linebuf_donebuf(&rb_linebuf_id);
212380e3 798}
799
800/* sendto_match_servs()
801 *
802 * inputs - source, mask to send to, caps needed, va_args
803 * outputs -
804 * side effects - message is sent to matching servers with caps.
805 */
806void
807sendto_match_servs(struct Client *source_p, const char *mask, int cap,
808 int nocap, const char *pattern, ...)
809{
810 static char buf[BUFSIZE];
811 va_list args;
af81d5a0 812 rb_dlink_node *ptr;
212380e3 813 struct Client *target_p;
780087dc 814 buf_head_t rb_linebuf_id;
212380e3 815
816 if(EmptyString(mask))
817 return;
818
780087dc 819 rb_linebuf_newbuf(&rb_linebuf_id);
212380e3 820
821 va_start(args, pattern);
780087dc 822 rb_vsnprintf(buf, sizeof(buf), pattern, args);
212380e3 823 va_end(args);
824
780087dc 825 rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL,
212380e3 826 ":%s %s", use_id(source_p), buf);
212380e3 827
828 current_serial++;
829
8e69bb4e 830 RB_DLINK_FOREACH(ptr, global_serv_list.head)
212380e3 831 {
832 target_p = ptr->data;
833
834 /* dont send to ourselves, or back to where it came from.. */
835 if(IsMe(target_p) || target_p->from == source_p->from)
836 continue;
837
838 if(target_p->from->serial == current_serial)
839 continue;
840
841 if(match(mask, target_p->name))
842 {
843 /* if we set the serial here, then we'll never do
844 * a match() again if !IsCapable()
845 */
846 target_p->from->serial = current_serial;
847
848 if(cap && !IsCapable(target_p->from, cap))
849 continue;
850
851 if(nocap && !NotCapable(target_p->from, nocap))
852 continue;
853
ad884f93 854 _send_linebuf(target_p->from, &rb_linebuf_id);
212380e3 855 }
856 }
857
780087dc 858 rb_linebuf_donebuf(&rb_linebuf_id);
212380e3 859}
860
8aba962d 861/* sendto_monitor()
862 *
863 * inputs - monitor nick to send to, format, va_args
864 * outputs - message to local users monitoring the given nick
865 * side effects -
866 */
867void
868sendto_monitor(struct monitor *monptr, const char *pattern, ...)
869{
870 va_list args;
871 buf_head_t linebuf;
872 struct Client *target_p;
af81d5a0 873 rb_dlink_node *ptr;
90a3c35b 874 rb_dlink_node *next_ptr;
8aba962d 875
780087dc 876 rb_linebuf_newbuf(&linebuf);
8aba962d 877
878 va_start(args, pattern);
780087dc 879 rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
8aba962d 880 va_end(args);
881
90a3c35b 882 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, monptr->users.head)
8aba962d 883 {
884 target_p = ptr->data;
885
886 if(IsIOError(target_p))
887 continue;
888
889 _send_linebuf(target_p, &linebuf);
890 }
891
780087dc 892 rb_linebuf_donebuf(&linebuf);
8aba962d 893}
894
212380e3 895/* sendto_anywhere()
896 *
897 * inputs - target, source, va_args
898 * outputs -
899 * side effects - client is sent message with correct prefix.
900 */
901void
902sendto_anywhere(struct Client *target_p, struct Client *source_p,
903 const char *command, const char *pattern, ...)
904{
905 va_list args;
906 buf_head_t linebuf;
907
780087dc 908 rb_linebuf_newbuf(&linebuf);
212380e3 909
910 va_start(args, pattern);
911
912 if(MyClient(target_p))
913 {
914 if(IsServer(source_p))
780087dc 915 rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s %s %s ",
212380e3 916 source_p->name, command,
917 target_p->name);
918 else
780087dc 919 rb_linebuf_putmsg(&linebuf, pattern, &args,
212380e3 920 ":%s!%s@%s %s %s ",
921 source_p->name, source_p->username,
922 source_p->host, command,
923 target_p->name);
924 }
925 else
780087dc 926 rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s %s %s ",
212380e3 927 get_id(source_p, target_p), command,
928 get_id(target_p, target_p));
929 va_end(args);
930
931 if(MyClient(target_p))
932 _send_linebuf(target_p, &linebuf);
933 else
934 send_linebuf_remote(target_p, source_p, &linebuf);
935
780087dc 936 rb_linebuf_donebuf(&linebuf);
212380e3 937}
938
212380e3 939/* sendto_realops_snomask()
940 *
941 * inputs - snomask needed, level (opers/admin), va_args
942 * output -
943 * side effects - message is sent to opers with matching snomasks
944 */
945void
946sendto_realops_snomask(int flags, int level, const char *pattern, ...)
947{
948 static char buf[BUFSIZE];
949 char *snobuf;
950 struct Client *client_p;
af81d5a0 951 rb_dlink_node *ptr;
90a3c35b 952 rb_dlink_node *next_ptr;
212380e3 953 va_list args;
954 buf_head_t linebuf;
955
780087dc 956 rb_linebuf_newbuf(&linebuf);
212380e3 957
958 /* Be very sure not to do things like "Trying to send to myself"
959 * L_NETWIDE, otherwise infinite recursion may result! -- jilles */
960 if (level & L_NETWIDE && ConfigFileEntry.global_snotices)
961 {
962 /* rather a lot of copying around, oh well -- jilles */
963 va_start(args, pattern);
780087dc 964 rb_vsnprintf(buf, sizeof(buf), pattern, args);
212380e3 965 va_end(args);
780087dc 966 rb_linebuf_putmsg(&linebuf, pattern, NULL,
212380e3 967 ":%s NOTICE * :*** Notice -- %s", me.name, buf);
968 snobuf = construct_snobuf(flags);
969 if (snobuf[1] != '\0')
212380e3 970 sendto_server(NULL, NULL, CAP_ENCAP|CAP_TS6, NOCAPS,
971 ":%s ENCAP * SNOTE %c :%s",
972 me.id, snobuf[1], buf);
212380e3 973 }
dbbe21ed
JT
974 else if (remote_rehash_oper_p != NULL)
975 {
976 /* rather a lot of copying around, oh well -- jilles */
977 va_start(args, pattern);
978 rb_vsnprintf(buf, sizeof(buf), pattern, args);
979 va_end(args);
980 rb_linebuf_putmsg(&linebuf, pattern, NULL,
981 ":%s NOTICE * :*** Notice -- %s", me.name, buf);
982 sendto_one_notice(remote_rehash_oper_p, ":*** Notice -- %s", buf);
983 }
212380e3 984 else
985 {
986 va_start(args, pattern);
780087dc 987 rb_linebuf_putmsg(&linebuf, pattern, &args,
212380e3 988 ":%s NOTICE * :*** Notice -- ", me.name);
989 va_end(args);
990 }
991 level &= ~L_NETWIDE;
992
90a3c35b 993 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, local_oper_list.head)
212380e3 994 {
995 client_p = ptr->data;
996
997 /* If we're sending it to opers and theyre an admin, skip.
998 * If we're sending it to admins, and theyre not, skip.
999 */
1000 if(((level == L_ADMIN) && !IsOperAdmin(client_p)) ||
1001 ((level == L_OPER) && IsOperAdmin(client_p)))
1002 continue;
1003
1004 if(client_p->snomask & flags)
1005 _send_linebuf(client_p, &linebuf);
1006 }
1007
780087dc 1008 rb_linebuf_donebuf(&linebuf);
212380e3 1009}
1010/* sendto_realops_snomask_from()
1011 *
1012 * inputs - snomask needed, level (opers/admin), source server, va_args
1013 * output -
1014 * side effects - message is sent to opers with matching snomask
1015 */
1016void
1017sendto_realops_snomask_from(int flags, int level, struct Client *source_p,
1018 const char *pattern, ...)
1019{
1020 struct Client *client_p;
af81d5a0 1021 rb_dlink_node *ptr;
90a3c35b 1022 rb_dlink_node *next_ptr;
212380e3 1023 va_list args;
1024 buf_head_t linebuf;
1025
780087dc 1026 rb_linebuf_newbuf(&linebuf);
212380e3 1027
1028 va_start(args, pattern);
780087dc 1029 rb_linebuf_putmsg(&linebuf, pattern, &args,
212380e3 1030 ":%s NOTICE * :*** Notice -- ", source_p->name);
1031 va_end(args);
1032
90a3c35b 1033 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, local_oper_list.head)
212380e3 1034 {
1035 client_p = ptr->data;
1036
1037 /* If we're sending it to opers and theyre an admin, skip.
1038 * If we're sending it to admins, and theyre not, skip.
1039 */
1040 if(((level == L_ADMIN) && !IsOperAdmin(client_p)) ||
1041 ((level == L_OPER) && IsOperAdmin(client_p)))
1042 continue;
1043
1044 if(client_p->snomask & flags)
1045 _send_linebuf(client_p, &linebuf);
1046 }
1047
780087dc 1048 rb_linebuf_donebuf(&linebuf);
212380e3 1049}
1050
1051/*
1052 * sendto_wallops_flags
1053 *
1054 * inputs - flag types of messages to show to real opers
1055 * - client sending request
1056 * - var args input message
1057 * output - NONE
1058 * side effects - Send a wallops to local opers
1059 */
1060void
1061sendto_wallops_flags(int flags, struct Client *source_p, const char *pattern, ...)
1062{
1063 struct Client *client_p;
af81d5a0 1064 rb_dlink_node *ptr;
90a3c35b 1065 rb_dlink_node *next_ptr;
212380e3 1066 va_list args;
1067 buf_head_t linebuf;
1068
780087dc 1069 rb_linebuf_newbuf(&linebuf);
212380e3 1070
1071 va_start(args, pattern);
1072
1073 if(IsPerson(source_p))
780087dc 1074 rb_linebuf_putmsg(&linebuf, pattern, &args,
212380e3 1075 ":%s!%s@%s WALLOPS :", source_p->name,
1076 source_p->username, source_p->host);
1077 else
780087dc 1078 rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s WALLOPS :", source_p->name);
212380e3 1079
1080 va_end(args);
1081
90a3c35b 1082 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, IsPerson(source_p) && flags == UMODE_WALLOP ? lclient_list.head : local_oper_list.head)
212380e3 1083 {
1084 client_p = ptr->data;
1085
1086 if(client_p->umodes & flags)
1087 _send_linebuf(client_p, &linebuf);
1088 }
1089
780087dc 1090 rb_linebuf_donebuf(&linebuf);
212380e3 1091}
1092
1093/* kill_client()
1094 *
1095 * input - client to send kill to, client to kill, va_args
1096 * output -
1097 * side effects - we issue a kill for the client
1098 */
1099void
1100kill_client(struct Client *target_p, struct Client *diedie, const char *pattern, ...)
1101{
1102 va_list args;
1103 buf_head_t linebuf;
1104
780087dc 1105 rb_linebuf_newbuf(&linebuf);
212380e3 1106
1107 va_start(args, pattern);
780087dc 1108 rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s KILL %s :",
212380e3 1109 get_id(&me, target_p), get_id(diedie, target_p));
1110 va_end(args);
1111
1112 send_linebuf(target_p, &linebuf);
780087dc 1113 rb_linebuf_donebuf(&linebuf);
212380e3 1114}
1115
1116
1117/*
1118 * kill_client_serv_butone
1119 *
1120 * inputs - pointer to client to not send to
1121 * - pointer to client to kill
1122 * output - NONE
1123 * side effects - Send a KILL for the given client
1124 * message to all connected servers
1125 * except the client 'one'. Also deal with
1126 * client being unknown to leaf, as in lazylink...
1127 */
1128void
1129kill_client_serv_butone(struct Client *one, struct Client *target_p, const char *pattern, ...)
1130{
1131 static char buf[BUFSIZE];
1132 va_list args;
1133 struct Client *client_p;
af81d5a0 1134 rb_dlink_node *ptr;
90a3c35b 1135 rb_dlink_node *next_ptr;
780087dc 1136 buf_head_t rb_linebuf_id;
212380e3 1137
780087dc 1138 rb_linebuf_newbuf(&rb_linebuf_id);
212380e3 1139
1140 va_start(args, pattern);
780087dc 1141 rb_vsnprintf(buf, sizeof(buf), pattern, args);
212380e3 1142 va_end(args);
1143
780087dc 1144 rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s KILL %s :%s",
212380e3 1145 use_id(&me), use_id(target_p), buf);
1146
90a3c35b 1147 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, serv_list.head)
212380e3 1148 {
1149 client_p = ptr->data;
1150
1151 /* ok, if the client we're supposed to not send to has an
1152 * ID, then we still want to issue the kill there..
1153 */
1154 if(one != NULL && (client_p == one->from) &&
1155 (!has_id(client_p) || !has_id(target_p)))
1156 continue;
1157
ad884f93 1158 _send_linebuf(client_p, &rb_linebuf_id);
212380e3 1159 }
1160
780087dc 1161 rb_linebuf_donebuf(&rb_linebuf_id);
212380e3 1162}