]> jfr.im git - irc/rqf/shadowircd.git/blame - src/send.c
We use Git now. Git is cool. Just like fezes.
[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 *
212380e3 24 */
25
26#include "stdinc.h"
212380e3 27#include "send.h"
28#include "channel.h"
29#include "class.h"
30#include "client.h"
31#include "common.h"
13ae2f4b 32#include "match.h"
212380e3 33#include "ircd.h"
34#include "numeric.h"
212380e3 35#include "s_serv.h"
212380e3 36#include "s_conf.h"
37#include "s_newconf.h"
d3455e2c 38#include "logger.h"
212380e3 39#include "hook.h"
8aba962d 40#include "monitor.h"
212380e3 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
780087dc
JT
47static void send_queued_write(rb_fde_t *F, void *data);
48
212380e3 49unsigned long current_serial = 0L;
50
dbbe21ed
JT
51struct Client *remote_rehash_oper_p;
52
212380e3 53/* send_linebuf()
54 *
55 * inputs - client to send to, linebuf to attach
56 * outputs -
57 * side effects - linebuf is attached to client
58 */
59static 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
780087dc 71 if(rb_linebuf_len(&to->localClient->buf_sendq) > get_sendq(to))
212380e3 72 {
73 if(IsServer(to))
74 {
75 sendto_realops_snomask(SNO_GENERAL, L_ALL,
76 "Max SendQ limit exceeded for %s: %u > %lu",
715b28fe 77 to->name,
780087dc 78 rb_linebuf_len(&to->localClient->buf_sendq),
212380e3 79 get_sendq(to));
80
81 ilog(L_SERVER, "Max SendQ limit exceeded for %s: %u > %lu",
82 log_client_name(to, SHOW_IP),
780087dc 83 rb_linebuf_len(&to->localClient->buf_sendq),
212380e3 84 get_sendq(to));
85 }
86
25b1f927 87 dead_link(to, 1);
212380e3 88 return -1;
89 }
90 else
91 {
92 /* just attach the linebuf to the sendq instead of
93 * generating a new one
94 */
780087dc 95 rb_linebuf_attach(&to->localClient->buf_sendq, linebuf);
212380e3 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;
780087dc
JT
105 if(rb_linebuf_len(&to->localClient->buf_sendq) > 0)
106 send_queued(to);
212380e3 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 */
116static void
117send_linebuf_remote(struct Client *to, struct Client *from, buf_head_t *linebuf)
118{
119 if(to->from)
120 to = to->from;
121
2386ae04 122 /* we assume the caller has already tested for fake direction */
212380e3 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 */
134void
780087dc 135send_queued(struct Client *to)
212380e3 136{
212380e3 137 int retlen;
212380e3 138#ifdef USE_IODEBUG_HOOKS
139 hook_data_int hd;
140#endif
780087dc 141 rb_fde_t *F = to->localClient->F;
5cd74a3b
WP
142 if (!F)
143 return;
144
212380e3 145 /* cant write anything to a dead socket. */
146 if(IsIOError(to))
147 return;
148
b717a466
JT
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))
8db00894
VY
155 return;
156
212380e3 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
780087dc 164 if(rb_linebuf_len(&to->localClient->buf_sendq))
212380e3 165 {
166 while ((retlen =
780087dc 167 rb_linebuf_flush(F, &to->localClient->buf_sendq)) > 0)
212380e3 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
8db00894
VY
181 ClearFlush(to);
182
212380e3 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
780087dc 197 if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno)))
212380e3 198 {
25b1f927 199 dead_link(to, 0);
212380e3 200 return;
201 }
202 }
8db00894 203
b717a466
JT
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
8db00894
VY
211 ClearFlush(to);
212}
213
b717a466
JT
214void
215send_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);
780087dc
JT
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 */
231static void
232send_queued_write(rb_fde_t *F, void *data)
233{
234 struct Client *to = data;
8db00894 235 ClearFlush(to);
780087dc 236 send_queued(to);
212380e3 237}
238
212380e3 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 */
245void
246sendto_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
780087dc 258 rb_linebuf_newbuf(&linebuf);
212380e3 259
260 va_start(args, pattern);
780087dc 261 rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
212380e3 262 va_end(args);
263
264 _send_linebuf(target_p, &linebuf);
265
780087dc 266 rb_linebuf_donebuf(&linebuf);
212380e3 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 */
276void
277sendto_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
780087dc 299 rb_linebuf_newbuf(&linebuf);
212380e3 300 va_start(args, pattern);
780087dc 301 rb_linebuf_putmsg(&linebuf, pattern, &args,
212380e3 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);
780087dc 308 rb_linebuf_donebuf(&linebuf);
212380e3 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 */
317void
318sendto_one_notice(struct Client *target_p, const char *pattern, ...)
319{
320 struct Client *dest_p;
321 va_list args;
322 buf_head_t linebuf;
5366977b 323 char *to;
212380e3 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
780087dc 340 rb_linebuf_newbuf(&linebuf);
212380e3 341 va_start(args, pattern);
780087dc 342 rb_linebuf_putmsg(&linebuf, pattern, &args,
212380e3 343 ":%s NOTICE %s ",
5366977b 344 get_id(&me, target_p), *(to = get_id(target_p, target_p)) != '\0' ? to : "*");
212380e3 345 va_end(args);
346
347 _send_linebuf(dest_p, &linebuf);
780087dc 348 rb_linebuf_donebuf(&linebuf);
212380e3 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 */
358void
359sendto_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;
5366977b 364 char *to;
212380e3 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
780087dc 381 rb_linebuf_newbuf(&linebuf);
212380e3 382 va_start(args, pattern);
780087dc 383 rb_linebuf_putmsg(&linebuf, pattern, &args,
212380e3 384 ":%s %03d %s ",
385 get_id(&me, target_p),
5366977b 386 numeric, *(to = get_id(target_p, target_p)) != '\0' ? to : "*");
212380e3 387 va_end(args);
388
389 _send_linebuf(dest_p, &linebuf);
780087dc 390 rb_linebuf_donebuf(&linebuf);
212380e3 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 */
410void
411sendto_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;
af81d5a0 416 rb_dlink_node *ptr;
90a3c35b 417 rb_dlink_node *next_ptr;
212380e3 418 buf_head_t linebuf;
419
420 /* noone to send to.. */
af81d5a0 421 if(rb_dlink_list_length(&serv_list) == 0)
212380e3 422 return;
423
424 if(chptr != NULL && *chptr->chname != '#')
425 return;
426
780087dc 427 rb_linebuf_newbuf(&linebuf);
212380e3 428 va_start(args, format);
780087dc 429 rb_linebuf_putmsg(&linebuf, format, &args, NULL);
212380e3 430 va_end(args);
431
90a3c35b 432 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, serv_list.head)
212380e3 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
780087dc 451 rb_linebuf_donebuf(&linebuf);
212380e3 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 */
461void
462sendto_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;
780087dc 467 buf_head_t rb_linebuf_local;
780087dc 468 buf_head_t rb_linebuf_id;
212380e3 469 struct Client *target_p;
470 struct membership *msptr;
af81d5a0 471 rb_dlink_node *ptr;
90a3c35b 472 rb_dlink_node *next_ptr;
212380e3 473
780087dc 474 rb_linebuf_newbuf(&rb_linebuf_local);
780087dc 475 rb_linebuf_newbuf(&rb_linebuf_id);
212380e3 476
477 current_serial++;
478
479 va_start(args, pattern);
780087dc 480 rb_vsnprintf(buf, sizeof(buf), pattern, args);
212380e3 481 va_end(args);
482
483 if(IsServer(source_p))
780087dc 484 rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
212380e3 485 ":%s %s", source_p->name, buf);
486 else
780087dc 487 rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
212380e3 488 ":%s!%s@%s %s",
489 source_p->name, source_p->username,
490 source_p->host, buf);
491
780087dc 492 rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s %s", use_id(source_p), buf);
212380e3 493
90a3c35b 494 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->members.head)
212380e3 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 {
ad884f93 518 send_linebuf_remote(target_p, source_p, &rb_linebuf_id);
212380e3 519 target_p->from->serial = current_serial;
520 }
521 }
522 else
780087dc 523 _send_linebuf(target_p, &rb_linebuf_local);
212380e3 524 }
525
780087dc 526 rb_linebuf_donebuf(&rb_linebuf_local);
780087dc 527 rb_linebuf_donebuf(&rb_linebuf_id);
212380e3 528}
529
6ce8910d
JT
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 */
536void
537sendto_channel_opmod(struct Client *one, struct Client *source_p,
538 struct Channel *chptr, const char *command,
539 const char *text)
540{
6ce8910d
JT
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
82f8e812 586 if(!is_any_op(msptr))
6ce8910d
JT
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}
212380e3 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 */
624void
625sendto_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;
af81d5a0 631 rb_dlink_node *ptr;
90a3c35b 632 rb_dlink_node *next_ptr;
212380e3 633
780087dc 634 rb_linebuf_newbuf(&linebuf);
212380e3 635
636 va_start(args, pattern);
780087dc 637 rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
212380e3 638 va_end(args);
639
90a3c35b 640 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head)
212380e3 641 {
642 msptr = ptr->data;
643 target_p = msptr->client_p;
644
645 if(IsIOError(target_p))
646 continue;
647
1cdd8fdf
JH
648 if(type == ONLY_OPERS)
649 {
650 if(!IsOper(target_p))
651 continue;
652 }
653 else if(type && ((msptr->flags & type) == 0))
212380e3 654 continue;
655
656 _send_linebuf(target_p, &linebuf);
657 }
658
780087dc 659 rb_linebuf_donebuf(&linebuf);
212380e3 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 */
669void
670sendto_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;
af81d5a0 676 rb_dlink_node *ptr;
90a3c35b 677 rb_dlink_node *next_ptr;
212380e3 678
780087dc 679 rb_linebuf_newbuf(&linebuf);
212380e3 680
681 va_start(args, pattern);
780087dc 682 rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
212380e3 683 va_end(args);
684
90a3c35b 685 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head)
212380e3 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
780087dc 702 rb_linebuf_donebuf(&linebuf);
212380e3 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 */
715void
716sendto_common_channels_local(struct Client *user, const char *pattern, ...)
717{
718 va_list args;
af81d5a0 719 rb_dlink_node *ptr;
90a3c35b 720 rb_dlink_node *next_ptr;
af81d5a0
WP
721 rb_dlink_node *uptr;
722 rb_dlink_node *next_uptr;
212380e3 723 struct Channel *chptr;
724 struct Client *target_p;
725 struct membership *msptr;
726 struct membership *mscptr;
727 buf_head_t linebuf;
728
780087dc 729 rb_linebuf_newbuf(&linebuf);
212380e3 730 va_start(args, pattern);
780087dc 731 rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
212380e3 732 va_end(args);
733
734 ++current_serial;
735
90a3c35b 736 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, user->user->channel.head)
212380e3 737 {
738 mscptr = ptr->data;
739 chptr = mscptr->chptr;
740
8e69bb4e 741 RB_DLINK_FOREACH_SAFE(uptr, next_uptr, chptr->locmembers.head)
212380e3 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
780087dc 761 rb_linebuf_donebuf(&linebuf);
212380e3 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 */
773void
774sendto_common_channels_local_butone(struct Client *user, const char *pattern, ...)
775{
776 va_list args;
af81d5a0 777 rb_dlink_node *ptr;
90a3c35b 778 rb_dlink_node *next_ptr;
af81d5a0
WP
779 rb_dlink_node *uptr;
780 rb_dlink_node *next_uptr;
212380e3 781 struct Channel *chptr;
782 struct Client *target_p;
783 struct membership *msptr;
784 struct membership *mscptr;
785 buf_head_t linebuf;
786
780087dc 787 rb_linebuf_newbuf(&linebuf);
212380e3 788 va_start(args, pattern);
780087dc 789 rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
212380e3 790 va_end(args);
791
792 ++current_serial;
793 /* Skip them -- jilles */
794 user->serial = current_serial;
795
90a3c35b 796 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, user->user->channel.head)
212380e3 797 {
798 mscptr = ptr->data;
799 chptr = mscptr->chptr;
800
8e69bb4e 801 RB_DLINK_FOREACH_SAFE(uptr, next_uptr, chptr->locmembers.head)
212380e3 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
780087dc 815 rb_linebuf_donebuf(&linebuf);
212380e3 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 */
824void
825sendto_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;
af81d5a0 831 rb_dlink_node *ptr;
90a3c35b 832 rb_dlink_node *next_ptr;
780087dc 833 buf_head_t rb_linebuf_local;
780087dc 834 buf_head_t rb_linebuf_id;
212380e3 835
780087dc 836 rb_linebuf_newbuf(&rb_linebuf_local);
780087dc 837 rb_linebuf_newbuf(&rb_linebuf_id);
212380e3 838
839 va_start(args, pattern);
780087dc 840 rb_vsnprintf(buf, sizeof(buf), pattern, args);
212380e3 841 va_end(args);
842
843 if(IsServer(source_p))
780087dc 844 rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
212380e3 845 ":%s %s", source_p->name, buf);
846 else
780087dc 847 rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
212380e3 848 ":%s!%s@%s %s",
849 source_p->name, source_p->username,
850 source_p->host, buf);
851
780087dc 852 rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s %s", use_id(source_p), buf);
212380e3 853
854 if(what == MATCH_HOST)
855 {
90a3c35b 856 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head)
212380e3 857 {
858 target_p = ptr->data;
859
860 if(match(mask, target_p->host))
780087dc 861 _send_linebuf(target_p, &rb_linebuf_local);
212380e3 862 }
863 }
864 /* what = MATCH_SERVER, if it doesnt match us, just send remote */
865 else if(match(mask, me.name))
866 {
90a3c35b 867 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head)
212380e3 868 {
869 target_p = ptr->data;
780087dc 870 _send_linebuf(target_p, &rb_linebuf_local);
212380e3 871 }
872 }
873
8e69bb4e 874 RB_DLINK_FOREACH(ptr, serv_list.head)
212380e3 875 {
876 target_p = ptr->data;
877
878 if(target_p == one)
879 continue;
880
ad884f93 881 send_linebuf_remote(target_p, source_p, &rb_linebuf_id);
212380e3 882 }
883
780087dc
JT
884 rb_linebuf_donebuf(&rb_linebuf_local);
885 rb_linebuf_donebuf(&rb_linebuf_id);
212380e3 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 */
894void
895sendto_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;
af81d5a0 900 rb_dlink_node *ptr;
212380e3 901 struct Client *target_p;
780087dc 902 buf_head_t rb_linebuf_id;
212380e3 903
904 if(EmptyString(mask))
905 return;
906
780087dc 907 rb_linebuf_newbuf(&rb_linebuf_id);
212380e3 908
909 va_start(args, pattern);
780087dc 910 rb_vsnprintf(buf, sizeof(buf), pattern, args);
212380e3 911 va_end(args);
912
780087dc 913 rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL,
212380e3 914 ":%s %s", use_id(source_p), buf);
212380e3 915
916 current_serial++;
917
8e69bb4e 918 RB_DLINK_FOREACH(ptr, global_serv_list.head)
212380e3 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
ad884f93 942 _send_linebuf(target_p->from, &rb_linebuf_id);
212380e3 943 }
944 }
945
780087dc 946 rb_linebuf_donebuf(&rb_linebuf_id);
212380e3 947}
948
8aba962d 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 */
955void
956sendto_monitor(struct monitor *monptr, const char *pattern, ...)
957{
958 va_list args;
959 buf_head_t linebuf;
960 struct Client *target_p;
af81d5a0 961 rb_dlink_node *ptr;
90a3c35b 962 rb_dlink_node *next_ptr;
8aba962d 963
780087dc 964 rb_linebuf_newbuf(&linebuf);
8aba962d 965
966 va_start(args, pattern);
780087dc 967 rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
8aba962d 968 va_end(args);
969
90a3c35b 970 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, monptr->users.head)
8aba962d 971 {
972 target_p = ptr->data;
973
974 if(IsIOError(target_p))
975 continue;
976
977 _send_linebuf(target_p, &linebuf);
978 }
979
780087dc 980 rb_linebuf_donebuf(&linebuf);
8aba962d 981}
982
212380e3 983/* sendto_anywhere()
984 *
985 * inputs - target, source, va_args
986 * outputs -
987 * side effects - client is sent message with correct prefix.
988 */
989void
990sendto_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
780087dc 996 rb_linebuf_newbuf(&linebuf);
212380e3 997
998 va_start(args, pattern);
999
1000 if(MyClient(target_p))
1001 {
1002 if(IsServer(source_p))
780087dc 1003 rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s %s %s ",
212380e3 1004 source_p->name, command,
1005 target_p->name);
1006 else
780087dc 1007 rb_linebuf_putmsg(&linebuf, pattern, &args,
212380e3 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
780087dc 1014 rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s %s %s ",
212380e3 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
780087dc 1024 rb_linebuf_donebuf(&linebuf);
212380e3 1025}
1026
212380e3 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 */
1033void
1034sendto_realops_snomask(int flags, int level, const char *pattern, ...)
1035{
1036 static char buf[BUFSIZE];
1037 char *snobuf;
1038 struct Client *client_p;
af81d5a0 1039 rb_dlink_node *ptr;
90a3c35b 1040 rb_dlink_node *next_ptr;
212380e3 1041 va_list args;
1042 buf_head_t linebuf;
1043
780087dc 1044 rb_linebuf_newbuf(&linebuf);
212380e3 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);
780087dc 1052 rb_vsnprintf(buf, sizeof(buf), pattern, args);
212380e3 1053 va_end(args);
780087dc 1054 rb_linebuf_putmsg(&linebuf, pattern, NULL,
212380e3 1055 ":%s NOTICE * :*** Notice -- %s", me.name, buf);
1056 snobuf = construct_snobuf(flags);
1057 if (snobuf[1] != '\0')
212380e3 1058 sendto_server(NULL, NULL, CAP_ENCAP|CAP_TS6, NOCAPS,
1059 ":%s ENCAP * SNOTE %c :%s",
1060 me.id, snobuf[1], buf);
212380e3 1061 }
dbbe21ed
JT
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 }
212380e3 1072 else
1073 {
1074 va_start(args, pattern);
780087dc 1075 rb_linebuf_putmsg(&linebuf, pattern, &args,
212380e3 1076 ":%s NOTICE * :*** Notice -- ", me.name);
1077 va_end(args);
1078 }
1079 level &= ~L_NETWIDE;
1080
90a3c35b 1081 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, local_oper_list.head)
212380e3 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
780087dc 1096 rb_linebuf_donebuf(&linebuf);
212380e3 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 */
1104void
1105sendto_realops_snomask_from(int flags, int level, struct Client *source_p,
1106 const char *pattern, ...)
1107{
1108 struct Client *client_p;
af81d5a0 1109 rb_dlink_node *ptr;
90a3c35b 1110 rb_dlink_node *next_ptr;
212380e3 1111 va_list args;
1112 buf_head_t linebuf;
1113
780087dc 1114 rb_linebuf_newbuf(&linebuf);
212380e3 1115
1116 va_start(args, pattern);
780087dc 1117 rb_linebuf_putmsg(&linebuf, pattern, &args,
212380e3 1118 ":%s NOTICE * :*** Notice -- ", source_p->name);
1119 va_end(args);
1120
90a3c35b 1121 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, local_oper_list.head)
212380e3 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
780087dc 1136 rb_linebuf_donebuf(&linebuf);
212380e3 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 */
1148void
1149sendto_wallops_flags(int flags, struct Client *source_p, const char *pattern, ...)
1150{
1151 struct Client *client_p;
af81d5a0 1152 rb_dlink_node *ptr;
90a3c35b 1153 rb_dlink_node *next_ptr;
212380e3 1154 va_list args;
1155 buf_head_t linebuf;
1156
780087dc 1157 rb_linebuf_newbuf(&linebuf);
212380e3 1158
1159 va_start(args, pattern);
1160
1161 if(IsPerson(source_p))
780087dc 1162 rb_linebuf_putmsg(&linebuf, pattern, &args,
212380e3 1163 ":%s!%s@%s WALLOPS :", source_p->name,
1164 source_p->username, source_p->host);
1165 else
780087dc 1166 rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s WALLOPS :", source_p->name);
212380e3 1167
1168 va_end(args);
1169
90a3c35b 1170 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, IsPerson(source_p) && flags == UMODE_WALLOP ? lclient_list.head : local_oper_list.head)
212380e3 1171 {
1172 client_p = ptr->data;
1173
1174 if(client_p->umodes & flags)
1175 _send_linebuf(client_p, &linebuf);
1176 }
1177
780087dc 1178 rb_linebuf_donebuf(&linebuf);
212380e3 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 */
1187void
1188kill_client(struct Client *target_p, struct Client *diedie, const char *pattern, ...)
1189{
1190 va_list args;
1191 buf_head_t linebuf;
1192
780087dc 1193 rb_linebuf_newbuf(&linebuf);
212380e3 1194
1195 va_start(args, pattern);
780087dc 1196 rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s KILL %s :",
212380e3 1197 get_id(&me, target_p), get_id(diedie, target_p));
1198 va_end(args);
1199
1200 send_linebuf(target_p, &linebuf);
780087dc 1201 rb_linebuf_donebuf(&linebuf);
212380e3 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 */
1216void
1217kill_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;
af81d5a0 1222 rb_dlink_node *ptr;
90a3c35b 1223 rb_dlink_node *next_ptr;
780087dc 1224 buf_head_t rb_linebuf_id;
212380e3 1225
780087dc 1226 rb_linebuf_newbuf(&rb_linebuf_id);
212380e3 1227
1228 va_start(args, pattern);
780087dc 1229 rb_vsnprintf(buf, sizeof(buf), pattern, args);
212380e3 1230 va_end(args);
1231
780087dc 1232 rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s KILL %s :%s",
212380e3 1233 use_id(&me), use_id(target_p), buf);
1234
90a3c35b 1235 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, serv_list.head)
212380e3 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
ad884f93 1246 _send_linebuf(client_p, &rb_linebuf_id);
212380e3 1247 }
1248
780087dc 1249 rb_linebuf_donebuf(&rb_linebuf_id);
212380e3 1250}