]> jfr.im git - solanum.git/blob - ircd/send.c
extensions/helpops: implement DEHELPER command
[solanum.git] / ircd / send.c
1 /*
2 * ircd-ratbox: A slightly useful ircd.
3 * send.c: Functions for sending messages.
4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
23 *
24 * $Id: send.c 3520 2007-06-30 22:15:35Z jilles $
25 */
26
27 #include "stdinc.h"
28 #include "send.h"
29 #include "channel.h"
30 #include "class.h"
31 #include "client.h"
32 #include "common.h"
33 #include "match.h"
34 #include "ircd.h"
35 #include "numeric.h"
36 #include "s_serv.h"
37 #include "s_conf.h"
38 #include "s_newconf.h"
39 #include "logger.h"
40 #include "hook.h"
41 #include "monitor.h"
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
48 static void send_queued_write(rb_fde_t *F, void *data);
49
50 unsigned long current_serial = 0L;
51
52 struct Client *remote_rehash_oper_p;
53
54 /* send_linebuf()
55 *
56 * inputs - client to send to, linebuf to attach
57 * outputs -
58 * side effects - linebuf is attached to client
59 */
60 static 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
72 if(rb_linebuf_len(&to->localClient->buf_sendq) > get_sendq_hard(to))
73 {
74 if(IsServer(to))
75 {
76 sendto_realops_snomask(SNO_GENERAL, L_ALL,
77 "Hard SendQ limit exceeded for %s: %u > %lu",
78 to->name,
79 rb_linebuf_len(&to->localClient->buf_sendq),
80 get_sendq_hard(to));
81
82 ilog(L_SERVER, "Hard SendQ limit exceeded for %s: %u > %lu",
83 log_client_name(to, SHOW_IP),
84 rb_linebuf_len(&to->localClient->buf_sendq),
85 get_sendq_hard(to));
86 }
87
88 dead_link(to, 1);
89 return -1;
90 }
91 else
92 {
93 /* just attach the linebuf to the sendq instead of
94 * generating a new one
95 */
96 rb_linebuf_attach(&to->localClient->buf_sendq, linebuf);
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;
106 if(rb_linebuf_len(&to->localClient->buf_sendq) > 0)
107 send_queued(to);
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 */
117 static void
118 send_linebuf_remote(struct Client *to, struct Client *from, buf_head_t *linebuf)
119 {
120 if(to->from)
121 to = to->from;
122
123 /* we assume the caller has already tested for fake direction */
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 */
135 void
136 send_queued(struct Client *to)
137 {
138 int retlen;
139 #ifdef USE_IODEBUG_HOOKS
140 hook_data_int hd;
141 #endif
142 rb_fde_t *F = to->localClient->F;
143 if (!F)
144 return;
145
146 /* cant write anything to a dead socket. */
147 if(IsIOError(to))
148 return;
149
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))
156 return;
157
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
165 if(rb_linebuf_len(&to->localClient->buf_sendq))
166 {
167 while ((retlen =
168 rb_linebuf_flush(F, &to->localClient->buf_sendq)) > 0)
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
182 ClearFlush(to);
183
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
198 if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno)))
199 {
200 dead_link(to, 0);
201 return;
202 }
203 }
204
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
212 ClearFlush(to);
213 }
214
215 void
216 send_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);
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 */
232 static void
233 send_queued_write(rb_fde_t *F, void *data)
234 {
235 struct Client *to = data;
236 ClearFlush(to);
237 send_queued(to);
238 }
239
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 */
246 void
247 sendto_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
259 rb_linebuf_newbuf(&linebuf);
260
261 va_start(args, pattern);
262 rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
263 va_end(args);
264
265 _send_linebuf(target_p, &linebuf);
266
267 rb_linebuf_donebuf(&linebuf);
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 */
277 void
278 sendto_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
300 rb_linebuf_newbuf(&linebuf);
301 va_start(args, pattern);
302 rb_linebuf_putmsg(&linebuf, pattern, &args,
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);
309 rb_linebuf_donebuf(&linebuf);
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 */
318 void
319 sendto_one_notice(struct Client *target_p, const char *pattern, ...)
320 {
321 struct Client *dest_p;
322 va_list args;
323 buf_head_t linebuf;
324 char *to;
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
341 rb_linebuf_newbuf(&linebuf);
342 va_start(args, pattern);
343 rb_linebuf_putmsg(&linebuf, pattern, &args,
344 ":%s NOTICE %s ",
345 get_id(&me, target_p), *(to = get_id(target_p, target_p)) != '\0' ? to : "*");
346 va_end(args);
347
348 _send_linebuf(dest_p, &linebuf);
349 rb_linebuf_donebuf(&linebuf);
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 */
359 void
360 sendto_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;
365 char *to;
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
382 rb_linebuf_newbuf(&linebuf);
383 va_start(args, pattern);
384 rb_linebuf_putmsg(&linebuf, pattern, &args,
385 ":%s %03d %s ",
386 get_id(&me, target_p),
387 numeric, *(to = get_id(target_p, target_p)) != '\0' ? to : "*");
388 va_end(args);
389
390 _send_linebuf(dest_p, &linebuf);
391 rb_linebuf_donebuf(&linebuf);
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 */
411 void
412 sendto_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;
417 rb_dlink_node *ptr;
418 rb_dlink_node *next_ptr;
419 buf_head_t linebuf;
420
421 /* noone to send to.. */
422 if(rb_dlink_list_length(&serv_list) == 0)
423 return;
424
425 if(chptr != NULL && *chptr->chname != '#')
426 return;
427
428 rb_linebuf_newbuf(&linebuf);
429 va_start(args, format);
430 rb_linebuf_putmsg(&linebuf, format, &args, NULL);
431 va_end(args);
432
433 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, serv_list.head)
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
452 rb_linebuf_donebuf(&linebuf);
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 */
462 void
463 sendto_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;
468 buf_head_t rb_linebuf_local;
469 buf_head_t rb_linebuf_id;
470 struct Client *target_p;
471 struct membership *msptr;
472 rb_dlink_node *ptr;
473 rb_dlink_node *next_ptr;
474
475 rb_linebuf_newbuf(&rb_linebuf_local);
476 rb_linebuf_newbuf(&rb_linebuf_id);
477
478 current_serial++;
479
480 va_start(args, pattern);
481 rb_vsnprintf(buf, sizeof(buf), pattern, args);
482 va_end(args);
483
484 if(IsServer(source_p))
485 rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
486 ":%s %s", source_p->name, buf);
487 else
488 rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
489 ":%s!%s@%s %s",
490 source_p->name, source_p->username,
491 source_p->host, buf);
492
493 rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s %s", use_id(source_p), buf);
494
495 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->members.head)
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 {
519 send_linebuf_remote(target_p, source_p, &rb_linebuf_id);
520 target_p->from->serial = current_serial;
521 }
522 }
523 else
524 _send_linebuf(target_p, &rb_linebuf_local);
525 }
526
527 rb_linebuf_donebuf(&rb_linebuf_local);
528 rb_linebuf_donebuf(&rb_linebuf_id);
529 }
530
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 */
537 void
538 sendto_channel_opmod(struct Client *one, struct Client *source_p,
539 struct Channel *chptr, const char *command,
540 const char *text)
541 {
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
587 if((msptr->flags & CHFL_CHANOP) == 0)
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 }
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 */
625 void
626 sendto_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;
632 rb_dlink_node *ptr;
633 rb_dlink_node *next_ptr;
634
635 rb_linebuf_newbuf(&linebuf);
636
637 va_start(args, pattern);
638 rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
639 va_end(args);
640
641 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head)
642 {
643 msptr = ptr->data;
644 target_p = msptr->client_p;
645
646 if(IsIOError(target_p))
647 continue;
648
649 if(type == ONLY_OPERS)
650 {
651 if (!IsOper(target_p))
652 continue;
653 }
654 else if(type && ((msptr->flags & type) == 0))
655 continue;
656
657 _send_linebuf(target_p, &linebuf);
658 }
659
660 rb_linebuf_donebuf(&linebuf);
661 }
662
663 /*
664 * _sendto_channel_local_with_capability_butone()
665 *
666 * Shared implementation of sendto_channel_local_with_capability and sendto_channel_local_with_capability_butone
667 */
668 static void
669 _sendto_channel_local_with_capability_butone(struct Client *one, int type, int caps, int negcaps, struct Channel *chptr,
670 const char *pattern, va_list * args)
671 {
672 buf_head_t linebuf;
673 struct membership *msptr;
674 struct Client *target_p;
675 rb_dlink_node *ptr;
676 rb_dlink_node *next_ptr;
677
678 rb_linebuf_newbuf(&linebuf);
679 rb_linebuf_putmsg(&linebuf, pattern, args, NULL);
680
681 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head)
682 {
683 msptr = ptr->data;
684 target_p = msptr->client_p;
685
686 if (target_p == one)
687 continue;
688
689 if(IsIOError(target_p) ||
690 !IsCapable(target_p, caps) ||
691 !NotCapable(target_p, negcaps))
692 continue;
693
694 if(type && ((msptr->flags & type) == 0))
695 continue;
696
697 _send_linebuf(target_p, &linebuf);
698 }
699
700 rb_linebuf_donebuf(&linebuf);
701 }
702
703 /* sendto_channel_local_with_capability()
704 *
705 * inputs - flags to send to, caps, negate caps, channel to send to, va_args
706 * outputs - message to local channel members
707 * side effects -
708 */
709 void
710 sendto_channel_local_with_capability(int type, int caps, int negcaps, struct Channel *chptr, const char *pattern, ...)
711 {
712 va_list args;
713
714 va_start(args, pattern);
715 _sendto_channel_local_with_capability_butone(NULL, type, caps, negcaps, chptr, pattern, &args);
716 va_end(args);
717 }
718
719
720 /* sendto_channel_local_with_capability()
721 *
722 * inputs - flags to send to, caps, negate caps, channel to send to, va_args
723 * outputs - message to local channel members
724 * side effects -
725 */
726 void
727 sendto_channel_local_with_capability_butone(struct Client *one, int type, int caps, int negcaps, struct Channel *chptr,
728 const char *pattern, ...)
729 {
730 va_list args;
731
732 va_start(args, pattern);
733 _sendto_channel_local_with_capability_butone(one, type, caps, negcaps, chptr, pattern, &args);
734 va_end(args);
735 }
736
737
738 /* sendto_channel_local_butone()
739 *
740 * inputs - flags to send to, channel to send to, va_args
741 * - user to ignore when sending
742 * outputs - message to local channel members
743 * side effects -
744 */
745 void
746 sendto_channel_local_butone(struct Client *one, int type, struct Channel *chptr, const char *pattern, ...)
747 {
748 va_list args;
749 buf_head_t linebuf;
750 struct membership *msptr;
751 struct Client *target_p;
752 rb_dlink_node *ptr;
753 rb_dlink_node *next_ptr;
754
755 rb_linebuf_newbuf(&linebuf);
756
757 va_start(args, pattern);
758 rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
759 va_end(args);
760
761 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head)
762 {
763 msptr = ptr->data;
764 target_p = msptr->client_p;
765
766 if(target_p == one)
767 continue;
768
769 if(IsIOError(target_p))
770 continue;
771
772 if(type && ((msptr->flags & type) == 0))
773 continue;
774
775 _send_linebuf(target_p, &linebuf);
776 }
777
778 rb_linebuf_donebuf(&linebuf);
779 }
780
781 /*
782 * sendto_common_channels_local()
783 *
784 * inputs - pointer to client
785 * - capability mask
786 * - negated capability mask
787 * - pattern to send
788 * output - NONE
789 * side effects - Sends a message to all people on local server who are
790 * in same channel with user.
791 * used by m_nick.c and exit_one_client.
792 */
793 void
794 sendto_common_channels_local(struct Client *user, int cap, int negcap, const char *pattern, ...)
795 {
796 va_list args;
797 rb_dlink_node *ptr;
798 rb_dlink_node *next_ptr;
799 rb_dlink_node *uptr;
800 rb_dlink_node *next_uptr;
801 struct Channel *chptr;
802 struct Client *target_p;
803 struct membership *msptr;
804 struct membership *mscptr;
805 buf_head_t linebuf;
806
807 rb_linebuf_newbuf(&linebuf);
808 va_start(args, pattern);
809 rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
810 va_end(args);
811
812 ++current_serial;
813
814 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, user->user->channel.head)
815 {
816 mscptr = ptr->data;
817 chptr = mscptr->chptr;
818
819 RB_DLINK_FOREACH_SAFE(uptr, next_uptr, chptr->locmembers.head)
820 {
821 msptr = uptr->data;
822 target_p = msptr->client_p;
823
824 if(IsIOError(target_p) ||
825 target_p->serial == current_serial ||
826 !IsCapable(target_p, cap) ||
827 !NotCapable(target_p, negcap))
828 continue;
829
830 target_p->serial = current_serial;
831 send_linebuf(target_p, &linebuf);
832 }
833 }
834
835 /* this can happen when the user isnt in any channels, but we still
836 * need to send them the data, ie a nick change
837 */
838 if(MyConnect(user) && (user->serial != current_serial))
839 send_linebuf(user, &linebuf);
840
841 rb_linebuf_donebuf(&linebuf);
842 }
843
844 /*
845 * sendto_common_channels_local_butone()
846 *
847 * inputs - pointer to client
848 * - capability mask
849 * - negated capability mask
850 * - pattern to send
851 * output - NONE
852 * side effects - Sends a message to all people on local server who are
853 * in same channel with user, except for user itself.
854 */
855 void
856 sendto_common_channels_local_butone(struct Client *user, int cap, int negcap, const char *pattern, ...)
857 {
858 va_list args;
859 rb_dlink_node *ptr;
860 rb_dlink_node *next_ptr;
861 rb_dlink_node *uptr;
862 rb_dlink_node *next_uptr;
863 struct Channel *chptr;
864 struct Client *target_p;
865 struct membership *msptr;
866 struct membership *mscptr;
867 buf_head_t linebuf;
868
869 rb_linebuf_newbuf(&linebuf);
870 va_start(args, pattern);
871 rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
872 va_end(args);
873
874 ++current_serial;
875 /* Skip them -- jilles */
876 user->serial = current_serial;
877
878 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, user->user->channel.head)
879 {
880 mscptr = ptr->data;
881 chptr = mscptr->chptr;
882
883 RB_DLINK_FOREACH_SAFE(uptr, next_uptr, chptr->locmembers.head)
884 {
885 msptr = uptr->data;
886 target_p = msptr->client_p;
887
888 if(IsIOError(target_p) ||
889 target_p->serial == current_serial ||
890 !IsCapable(target_p, cap) ||
891 !NotCapable(target_p, negcap))
892 continue;
893
894 target_p->serial = current_serial;
895 send_linebuf(target_p, &linebuf);
896 }
897 }
898
899 rb_linebuf_donebuf(&linebuf);
900 }
901
902 /* sendto_match_butone()
903 *
904 * inputs - server not to send to, source, mask, type of mask, va_args
905 * output -
906 * side effects - message is sent to matching clients
907 */
908 void
909 sendto_match_butone(struct Client *one, struct Client *source_p,
910 const char *mask, int what, const char *pattern, ...)
911 {
912 static char buf[BUFSIZE];
913 va_list args;
914 struct Client *target_p;
915 rb_dlink_node *ptr;
916 rb_dlink_node *next_ptr;
917 buf_head_t rb_linebuf_local;
918 buf_head_t rb_linebuf_id;
919
920 rb_linebuf_newbuf(&rb_linebuf_local);
921 rb_linebuf_newbuf(&rb_linebuf_id);
922
923 va_start(args, pattern);
924 rb_vsnprintf(buf, sizeof(buf), pattern, args);
925 va_end(args);
926
927 if(IsServer(source_p))
928 rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
929 ":%s %s", source_p->name, buf);
930 else
931 rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
932 ":%s!%s@%s %s",
933 source_p->name, source_p->username,
934 source_p->host, buf);
935
936 rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s %s", use_id(source_p), buf);
937
938 if(what == MATCH_HOST)
939 {
940 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head)
941 {
942 target_p = ptr->data;
943
944 if(match(mask, target_p->host))
945 _send_linebuf(target_p, &rb_linebuf_local);
946 }
947 }
948 /* what = MATCH_SERVER, if it doesnt match us, just send remote */
949 else if(match(mask, me.name))
950 {
951 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head)
952 {
953 target_p = ptr->data;
954 _send_linebuf(target_p, &rb_linebuf_local);
955 }
956 }
957
958 RB_DLINK_FOREACH(ptr, serv_list.head)
959 {
960 target_p = ptr->data;
961
962 if(target_p == one)
963 continue;
964
965 send_linebuf_remote(target_p, source_p, &rb_linebuf_id);
966 }
967
968 rb_linebuf_donebuf(&rb_linebuf_local);
969 rb_linebuf_donebuf(&rb_linebuf_id);
970 }
971
972 /* sendto_match_servs()
973 *
974 * inputs - source, mask to send to, caps needed, va_args
975 * outputs -
976 * side effects - message is sent to matching servers with caps.
977 */
978 void
979 sendto_match_servs(struct Client *source_p, const char *mask, int cap,
980 int nocap, const char *pattern, ...)
981 {
982 static char buf[BUFSIZE];
983 va_list args;
984 rb_dlink_node *ptr;
985 struct Client *target_p;
986 buf_head_t rb_linebuf_id;
987
988 if(EmptyString(mask))
989 return;
990
991 rb_linebuf_newbuf(&rb_linebuf_id);
992
993 va_start(args, pattern);
994 rb_vsnprintf(buf, sizeof(buf), pattern, args);
995 va_end(args);
996
997 rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL,
998 ":%s %s", use_id(source_p), buf);
999
1000 current_serial++;
1001
1002 RB_DLINK_FOREACH(ptr, global_serv_list.head)
1003 {
1004 target_p = ptr->data;
1005
1006 /* dont send to ourselves, or back to where it came from.. */
1007 if(IsMe(target_p) || target_p->from == source_p->from)
1008 continue;
1009
1010 if(target_p->from->serial == current_serial)
1011 continue;
1012
1013 if(match(mask, target_p->name))
1014 {
1015 /* if we set the serial here, then we'll never do
1016 * a match() again if !IsCapable()
1017 */
1018 target_p->from->serial = current_serial;
1019
1020 if(cap && !IsCapable(target_p->from, cap))
1021 continue;
1022
1023 if(nocap && !NotCapable(target_p->from, nocap))
1024 continue;
1025
1026 _send_linebuf(target_p->from, &rb_linebuf_id);
1027 }
1028 }
1029
1030 rb_linebuf_donebuf(&rb_linebuf_id);
1031 }
1032
1033 /* sendto_local_clients_with_capability()
1034 *
1035 * inputs - caps needed, pattern, va_args
1036 * outputs -
1037 * side effects - message is sent to matching local clients with caps.
1038 */
1039 void
1040 sendto_local_clients_with_capability(int cap, const char *pattern, ...)
1041 {
1042 va_list args;
1043 rb_dlink_node *ptr;
1044 struct Client *target_p;
1045 buf_head_t linebuf;
1046
1047 rb_linebuf_newbuf(&linebuf);
1048
1049 va_start(args, pattern);
1050 rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
1051 va_end(args);
1052
1053 RB_DLINK_FOREACH(ptr, lclient_list.head)
1054 {
1055 target_p = ptr->data;
1056
1057 if(IsIOError(target_p) || !IsCapable(target_p, cap))
1058 continue;
1059
1060 send_linebuf(target_p, &linebuf);
1061 }
1062
1063 rb_linebuf_donebuf(&linebuf);
1064 }
1065
1066 /* sendto_monitor()
1067 *
1068 * inputs - monitor nick to send to, format, va_args
1069 * outputs - message to local users monitoring the given nick
1070 * side effects -
1071 */
1072 void
1073 sendto_monitor(struct monitor *monptr, const char *pattern, ...)
1074 {
1075 va_list args;
1076 buf_head_t linebuf;
1077 struct Client *target_p;
1078 rb_dlink_node *ptr;
1079 rb_dlink_node *next_ptr;
1080
1081 rb_linebuf_newbuf(&linebuf);
1082
1083 va_start(args, pattern);
1084 rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
1085 va_end(args);
1086
1087 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, monptr->users.head)
1088 {
1089 target_p = ptr->data;
1090
1091 if(IsIOError(target_p))
1092 continue;
1093
1094 _send_linebuf(target_p, &linebuf);
1095 }
1096
1097 rb_linebuf_donebuf(&linebuf);
1098 }
1099
1100 /* sendto_anywhere()
1101 *
1102 * inputs - target, source, va_args
1103 * outputs -
1104 * side effects - client is sent message with correct prefix.
1105 */
1106 void
1107 sendto_anywhere(struct Client *target_p, struct Client *source_p,
1108 const char *command, const char *pattern, ...)
1109 {
1110 va_list args;
1111 buf_head_t linebuf;
1112
1113 rb_linebuf_newbuf(&linebuf);
1114
1115 va_start(args, pattern);
1116
1117 if(MyClient(target_p))
1118 {
1119 if(IsServer(source_p))
1120 rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s %s %s ",
1121 source_p->name, command,
1122 target_p->name);
1123 else
1124 rb_linebuf_putmsg(&linebuf, pattern, &args,
1125 ":%s!%s@%s %s %s ",
1126 source_p->name, source_p->username,
1127 source_p->host, command,
1128 target_p->name);
1129 }
1130 else
1131 rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s %s %s ",
1132 get_id(source_p, target_p), command,
1133 get_id(target_p, target_p));
1134 va_end(args);
1135
1136 if(MyClient(target_p))
1137 _send_linebuf(target_p, &linebuf);
1138 else
1139 send_linebuf_remote(target_p, source_p, &linebuf);
1140
1141 rb_linebuf_donebuf(&linebuf);
1142 }
1143
1144 /* sendto_realops_snomask()
1145 *
1146 * inputs - snomask needed, level (opers/admin), va_args
1147 * output -
1148 * side effects - message is sent to opers with matching snomasks
1149 */
1150 void
1151 sendto_realops_snomask(int flags, int level, const char *pattern, ...)
1152 {
1153 static char buf[BUFSIZE];
1154 char *snobuf;
1155 struct Client *client_p;
1156 rb_dlink_node *ptr;
1157 rb_dlink_node *next_ptr;
1158 va_list args;
1159 buf_head_t linebuf;
1160
1161 rb_linebuf_newbuf(&linebuf);
1162
1163 /* Be very sure not to do things like "Trying to send to myself"
1164 * L_NETWIDE, otherwise infinite recursion may result! -- jilles */
1165 if (level & L_NETWIDE && ConfigFileEntry.global_snotices)
1166 {
1167 /* rather a lot of copying around, oh well -- jilles */
1168 va_start(args, pattern);
1169 rb_vsnprintf(buf, sizeof(buf), pattern, args);
1170 va_end(args);
1171 rb_linebuf_putmsg(&linebuf, pattern, NULL,
1172 ":%s NOTICE * :*** Notice -- %s", me.name, buf);
1173 snobuf = construct_snobuf(flags);
1174 if (snobuf[1] != '\0')
1175 sendto_server(NULL, NULL, CAP_ENCAP|CAP_TS6, NOCAPS,
1176 ":%s ENCAP * SNOTE %c :%s",
1177 me.id, snobuf[1], buf);
1178 }
1179 else if (remote_rehash_oper_p != NULL)
1180 {
1181 /* rather a lot of copying around, oh well -- jilles */
1182 va_start(args, pattern);
1183 rb_vsnprintf(buf, sizeof(buf), pattern, args);
1184 va_end(args);
1185 rb_linebuf_putmsg(&linebuf, pattern, NULL,
1186 ":%s NOTICE * :*** Notice -- %s", me.name, buf);
1187 sendto_one_notice(remote_rehash_oper_p, ":*** Notice -- %s", buf);
1188 }
1189 else
1190 {
1191 va_start(args, pattern);
1192 rb_linebuf_putmsg(&linebuf, pattern, &args,
1193 ":%s NOTICE * :*** Notice -- ", me.name);
1194 va_end(args);
1195 }
1196 level &= ~L_NETWIDE;
1197
1198 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, local_oper_list.head)
1199 {
1200 client_p = ptr->data;
1201
1202 /* If we're sending it to opers and theyre an admin, skip.
1203 * If we're sending it to admins, and theyre not, skip.
1204 */
1205 if(((level == L_ADMIN) && !IsOperAdmin(client_p)) ||
1206 ((level == L_OPER) && IsOperAdmin(client_p)))
1207 continue;
1208
1209 if(client_p->snomask & flags)
1210 _send_linebuf(client_p, &linebuf);
1211 }
1212
1213 rb_linebuf_donebuf(&linebuf);
1214 }
1215 /* sendto_realops_snomask_from()
1216 *
1217 * inputs - snomask needed, level (opers/admin), source server, va_args
1218 * output -
1219 * side effects - message is sent to opers with matching snomask
1220 */
1221 void
1222 sendto_realops_snomask_from(int flags, int level, struct Client *source_p,
1223 const char *pattern, ...)
1224 {
1225 struct Client *client_p;
1226 rb_dlink_node *ptr;
1227 rb_dlink_node *next_ptr;
1228 va_list args;
1229 buf_head_t linebuf;
1230
1231 rb_linebuf_newbuf(&linebuf);
1232
1233 va_start(args, pattern);
1234 rb_linebuf_putmsg(&linebuf, pattern, &args,
1235 ":%s NOTICE * :*** Notice -- ", source_p->name);
1236 va_end(args);
1237
1238 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, local_oper_list.head)
1239 {
1240 client_p = ptr->data;
1241
1242 /* If we're sending it to opers and theyre an admin, skip.
1243 * If we're sending it to admins, and theyre not, skip.
1244 */
1245 if(((level == L_ADMIN) && !IsOperAdmin(client_p)) ||
1246 ((level == L_OPER) && IsOperAdmin(client_p)))
1247 continue;
1248
1249 if(client_p->snomask & flags)
1250 _send_linebuf(client_p, &linebuf);
1251 }
1252
1253 rb_linebuf_donebuf(&linebuf);
1254 }
1255
1256 /*
1257 * sendto_wallops_flags
1258 *
1259 * inputs - flag types of messages to show to real opers
1260 * - client sending request
1261 * - var args input message
1262 * output - NONE
1263 * side effects - Send a wallops to local opers
1264 */
1265 void
1266 sendto_wallops_flags(int flags, struct Client *source_p, const char *pattern, ...)
1267 {
1268 struct Client *client_p;
1269 rb_dlink_node *ptr;
1270 rb_dlink_node *next_ptr;
1271 va_list args;
1272 buf_head_t linebuf;
1273
1274 rb_linebuf_newbuf(&linebuf);
1275
1276 va_start(args, pattern);
1277
1278 if(IsPerson(source_p))
1279 rb_linebuf_putmsg(&linebuf, pattern, &args,
1280 ":%s!%s@%s WALLOPS :", source_p->name,
1281 source_p->username, source_p->host);
1282 else
1283 rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s WALLOPS :", source_p->name);
1284
1285 va_end(args);
1286
1287 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, IsPerson(source_p) && flags == UMODE_WALLOP ? lclient_list.head : local_oper_list.head)
1288 {
1289 client_p = ptr->data;
1290
1291 if(client_p->umodes & flags)
1292 _send_linebuf(client_p, &linebuf);
1293 }
1294
1295 rb_linebuf_donebuf(&linebuf);
1296 }
1297
1298 /* kill_client()
1299 *
1300 * input - client to send kill to, client to kill, va_args
1301 * output -
1302 * side effects - we issue a kill for the client
1303 */
1304 void
1305 kill_client(struct Client *target_p, struct Client *diedie, const char *pattern, ...)
1306 {
1307 va_list args;
1308 buf_head_t linebuf;
1309
1310 rb_linebuf_newbuf(&linebuf);
1311
1312 va_start(args, pattern);
1313 rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s KILL %s :",
1314 get_id(&me, target_p), get_id(diedie, target_p));
1315 va_end(args);
1316
1317 send_linebuf(target_p, &linebuf);
1318 rb_linebuf_donebuf(&linebuf);
1319 }
1320
1321
1322 /*
1323 * kill_client_serv_butone
1324 *
1325 * inputs - pointer to client to not send to
1326 * - pointer to client to kill
1327 * output - NONE
1328 * side effects - Send a KILL for the given client
1329 * message to all connected servers
1330 * except the client 'one'. Also deal with
1331 * client being unknown to leaf, as in lazylink...
1332 */
1333 void
1334 kill_client_serv_butone(struct Client *one, struct Client *target_p, const char *pattern, ...)
1335 {
1336 static char buf[BUFSIZE];
1337 va_list args;
1338 struct Client *client_p;
1339 rb_dlink_node *ptr;
1340 rb_dlink_node *next_ptr;
1341 buf_head_t rb_linebuf_id;
1342
1343 rb_linebuf_newbuf(&rb_linebuf_id);
1344
1345 va_start(args, pattern);
1346 rb_vsnprintf(buf, sizeof(buf), pattern, args);
1347 va_end(args);
1348
1349 rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s KILL %s :%s",
1350 use_id(&me), use_id(target_p), buf);
1351
1352 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, serv_list.head)
1353 {
1354 client_p = ptr->data;
1355
1356 /* ok, if the client we're supposed to not send to has an
1357 * ID, then we still want to issue the kill there..
1358 */
1359 if(one != NULL && (client_p == one->from) &&
1360 (!has_id(client_p) || !has_id(target_p)))
1361 continue;
1362
1363 _send_linebuf(client_p, &rb_linebuf_id);
1364 }
1365
1366 rb_linebuf_donebuf(&rb_linebuf_id);
1367 }