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