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