2 * ircd-ratbox: A slightly useful ircd.
3 * send.c: Functions for sending messages.
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
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.
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.
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
24 * $Id: send.c 3520 2007-06-30 22:15:35Z jilles $
38 #include "s_newconf.h"
43 #define LOG_BUFSIZE 2048
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)
48 static void send_queued_write(rb_fde_t
*F
, void *data
);
50 unsigned long current_serial
= 0L;
52 struct Client
*remote_rehash_oper_p
;
56 * inputs - client to send to, linebuf to attach
58 * side effects - linebuf is attached to client
61 _send_linebuf(struct Client
*to
, buf_head_t
*linebuf
)
65 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send message to myself!");
69 if(!MyConnect(to
) || IsIOError(to
))
72 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > get_sendq(to
))
76 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
77 "Max SendQ limit exceeded for %s: %u > %lu",
79 rb_linebuf_len(&to
->localClient
->buf_sendq
),
82 ilog(L_SERVER
, "Max SendQ limit exceeded for %s: %u > %lu",
83 log_client_name(to
, SHOW_IP
),
84 rb_linebuf_len(&to
->localClient
->buf_sendq
),
93 /* just attach the linebuf to the sendq instead of
94 * generating a new one
96 rb_linebuf_attach(&to
->localClient
->buf_sendq
, linebuf
);
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.
104 to
->localClient
->sendM
+= 1;
105 me
.localClient
->sendM
+= 1;
106 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > 0)
111 /* send_linebuf_remote()
113 * inputs - client to attach to, sender, linebuf
115 * side effects - client has linebuf attached
118 send_linebuf_remote(struct Client
*to
, struct Client
*from
, buf_head_t
*linebuf
)
123 /* we assume the caller has already tested for fake direction */
125 _send_linebuf(to
, linebuf
);
129 /* send_queued_write()
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
136 send_queued(struct Client
*to
)
139 #ifdef USE_IODEBUG_HOOKS
142 rb_fde_t
*F
= to
->localClient
->F
;
146 /* cant write anything to a dead socket. */
150 /* Something wants us to not send anything currently */
154 /* try to flush later when the write event resets this */
158 #ifdef USE_IODEBUG_HOOKS
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
;
165 if(rb_linebuf_len(&to
->localClient
->buf_sendq
))
168 rb_linebuf_flush(F
, &to
->localClient
->buf_sendq
)) > 0)
170 /* We have some data written .. update counters */
171 #ifdef USE_IODEBUG_HOOKS
173 call_hook(h_iosend_id
, &hd
);
175 if(to
->localClient
->buf_sendq
.list
.head
)
177 ((buf_line_t
*) to
->localClient
->buf_sendq
.list
.head
->
178 data
)->buf
+ to
->localClient
->buf_sendq
.writeofs
;
184 to
->localClient
->sendB
+= retlen
;
185 me
.localClient
->sendB
+= retlen
;
186 if(to
->localClient
->sendB
> 1023)
188 to
->localClient
->sendK
+= (to
->localClient
->sendB
>> 10);
189 to
->localClient
->sendB
&= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */
191 else if(me
.localClient
->sendB
> 1023)
193 me
.localClient
->sendK
+= (me
.localClient
->sendB
>> 10);
194 me
.localClient
->sendB
&= 0x03ff;
198 if(retlen
== 0 || (retlen
< 0 && !rb_ignore_errno(errno
)))
205 if(rb_linebuf_len(&to
->localClient
->buf_sendq
))
208 rb_setselect(to
->localClient
->F
, RB_SELECT_WRITE
,
209 send_queued_write
, to
);
216 send_pop_queue(struct Client
*to
)
220 if(!MyConnect(to
) || IsIOError(to
))
222 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > 0)
226 /* send_queued_write()
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
233 send_queued_write(rb_fde_t
*F
, void *data
)
235 struct Client
*to
= data
;
242 * inputs - client to send to, va_args
243 * outputs - client has message put into its queue
247 sendto_one(struct Client
*target_p
, const char *pattern
, ...)
252 /* send remote if to->from non NULL */
253 if(target_p
->from
!= NULL
)
254 target_p
= target_p
->from
;
256 if(IsIOError(target_p
))
259 rb_linebuf_newbuf(&linebuf
);
261 va_start(args
, pattern
);
262 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
265 _send_linebuf(target_p
, &linebuf
);
267 rb_linebuf_donebuf(&linebuf
);
271 /* sendto_one_prefix()
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
278 sendto_one_prefix(struct Client
*target_p
, struct Client
*source_p
,
279 const char *command
, const char *pattern
, ...)
281 struct Client
*dest_p
;
285 /* send remote if to->from non NULL */
286 if(target_p
->from
!= NULL
)
287 dest_p
= target_p
->from
;
291 if(IsIOError(dest_p
))
296 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
300 rb_linebuf_newbuf(&linebuf
);
301 va_start(args
, pattern
);
302 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
304 get_id(source_p
, target_p
),
305 command
, get_id(target_p
, target_p
));
308 _send_linebuf(dest_p
, &linebuf
);
309 rb_linebuf_donebuf(&linebuf
);
312 /* sendto_one_notice()
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
319 sendto_one_notice(struct Client
*target_p
, const char *pattern
, ...)
321 struct Client
*dest_p
;
326 /* send remote if to->from non NULL */
327 if(target_p
->from
!= NULL
)
328 dest_p
= target_p
->from
;
332 if(IsIOError(dest_p
))
337 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
341 rb_linebuf_newbuf(&linebuf
);
342 va_start(args
, pattern
);
343 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
345 get_id(&me
, target_p
), *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
348 _send_linebuf(dest_p
, &linebuf
);
349 rb_linebuf_donebuf(&linebuf
);
353 /* sendto_one_numeric()
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
360 sendto_one_numeric(struct Client
*target_p
, int numeric
, const char *pattern
, ...)
362 struct Client
*dest_p
;
367 /* send remote if to->from non NULL */
368 if(target_p
->from
!= NULL
)
369 dest_p
= target_p
->from
;
373 if(IsIOError(dest_p
))
378 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
382 rb_linebuf_newbuf(&linebuf
);
383 va_start(args
, pattern
);
384 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
386 get_id(&me
, target_p
),
387 numeric
, *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
390 _send_linebuf(dest_p
, &linebuf
);
391 rb_linebuf_donebuf(&linebuf
);
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
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'.
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
412 sendto_server(struct Client
*one
, struct Channel
*chptr
, unsigned long caps
,
413 unsigned long nocaps
, const char *format
, ...)
416 struct Client
*target_p
;
418 rb_dlink_node
*next_ptr
;
421 /* noone to send to.. */
422 if(rb_dlink_list_length(&serv_list
) == 0)
425 if(chptr
!= NULL
&& *chptr
->chname
!= '#')
428 rb_linebuf_newbuf(&linebuf
);
429 va_start(args
, format
);
430 rb_linebuf_putmsg(&linebuf
, format
, &args
, NULL
);
433 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
435 target_p
= ptr
->data
;
437 /* check against 'one' */
438 if(one
!= NULL
&& (target_p
== one
->from
))
441 /* check we have required capabs */
442 if(!IsCapable(target_p
, caps
))
445 /* check we don't have any forbidden capabs */
446 if(!NotCapable(target_p
, nocaps
))
449 _send_linebuf(target_p
, &linebuf
);
452 rb_linebuf_donebuf(&linebuf
);
456 /* sendto_channel_flags()
458 * inputs - server not to send to, flags needed, source, channel, va_args
459 * outputs - message is sent to channel members
463 sendto_channel_flags(struct Client
*one
, int type
, struct Client
*source_p
,
464 struct Channel
*chptr
, const char *pattern
, ...)
466 static char buf
[BUFSIZE
];
468 buf_head_t rb_linebuf_local
;
469 buf_head_t rb_linebuf_id
;
470 struct Client
*target_p
;
471 struct membership
*msptr
;
473 rb_dlink_node
*next_ptr
;
475 rb_linebuf_newbuf(&rb_linebuf_local
);
476 rb_linebuf_newbuf(&rb_linebuf_id
);
480 va_start(args
, pattern
);
481 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
484 if(IsServer(source_p
))
485 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
486 ":%s %s", source_p
->name
, buf
);
488 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
490 source_p
->name
, source_p
->username
,
491 source_p
->host
, buf
);
493 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
495 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->members
.head
)
498 target_p
= msptr
->client_p
;
500 if(IsIOError(target_p
->from
) || target_p
->from
== one
)
503 if(type
&& ((msptr
->flags
& type
) == 0))
509 if(!MyClient(target_p
))
511 /* if we've got a specific type, target must support
514 if(type
&& NotCapable(target_p
->from
, CAP_CHW
))
517 if(target_p
->from
->serial
!= current_serial
)
519 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_id
);
520 target_p
->from
->serial
= current_serial
;
524 _send_linebuf(target_p
, &rb_linebuf_local
);
527 rb_linebuf_donebuf(&rb_linebuf_local
);
528 rb_linebuf_donebuf(&rb_linebuf_id
);
531 /* sendto_channel_flags()
533 * inputs - server not to send to, flags needed, source, channel, va_args
534 * outputs - message is sent to channel members
538 sendto_channel_opmod(struct Client
*one
, struct Client
*source_p
,
539 struct Channel
*chptr
, const char *command
,
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
;
548 rb_dlink_node
*next_ptr
;
550 rb_linebuf_newbuf(&rb_linebuf_local
);
551 rb_linebuf_newbuf(&rb_linebuf_old
);
552 rb_linebuf_newbuf(&rb_linebuf_new
);
556 if(IsServer(source_p
))
557 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
559 source_p
->name
, command
, chptr
->chname
, text
);
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
);
566 if (chptr
->mode
.mode
& MODE_MODERATED
)
567 rb_linebuf_putmsg(&rb_linebuf_old
, NULL
, NULL
,
569 use_id(source_p
), command
, chptr
->chname
, text
);
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
,
577 use_id(source_p
), command
, chptr
->chname
, text
);
579 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->members
.head
)
582 target_p
= msptr
->client_p
;
584 if(IsIOError(target_p
->from
) || target_p
->from
== one
)
587 if((msptr
->flags
& CHFL_CHANOP
) == 0)
593 if(!MyClient(target_p
))
595 /* if we've got a specific type, target must support
598 if(NotCapable(target_p
->from
, CAP_CHW
))
601 if(target_p
->from
->serial
!= current_serial
)
603 if (IsCapable(target_p
->from
, CAP_EOPMOD
))
604 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_new
);
606 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_old
);
607 target_p
->from
->serial
= current_serial
;
611 _send_linebuf(target_p
, &rb_linebuf_local
);
614 rb_linebuf_donebuf(&rb_linebuf_local
);
615 rb_linebuf_donebuf(&rb_linebuf_old
);
616 rb_linebuf_donebuf(&rb_linebuf_new
);
619 /* sendto_channel_local()
621 * inputs - flags to send to, channel to send to, va_args
622 * outputs - message to local channel members
626 sendto_channel_local(int type
, struct Channel
*chptr
, const char *pattern
, ...)
630 struct membership
*msptr
;
631 struct Client
*target_p
;
633 rb_dlink_node
*next_ptr
;
635 rb_linebuf_newbuf(&linebuf
);
637 va_start(args
, pattern
);
638 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
641 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
644 target_p
= msptr
->client_p
;
646 if(IsIOError(target_p
))
649 if(type
&& ((msptr
->flags
& type
) == 0))
652 _send_linebuf(target_p
, &linebuf
);
655 rb_linebuf_donebuf(&linebuf
);
659 * _sendto_channel_local_with_capability_butone()
661 * Shared implementation of sendto_channel_local_with_capability and sendto_channel_local_with_capability_butone
664 _sendto_channel_local_with_capability_butone(struct Client
*one
, int type
, int caps
, int negcaps
, struct Channel
*chptr
,
665 const char *pattern
, va_list * args
)
668 struct membership
*msptr
;
669 struct Client
*target_p
;
671 rb_dlink_node
*next_ptr
;
673 rb_linebuf_newbuf(&linebuf
);
674 rb_linebuf_putmsg(&linebuf
, pattern
, args
, NULL
);
676 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
679 target_p
= msptr
->client_p
;
684 if(IsIOError(target_p
) ||
685 !IsCapable(target_p
, caps
) ||
686 !NotCapable(target_p
, negcaps
))
689 if(type
&& ((msptr
->flags
& type
) == 0))
692 _send_linebuf(target_p
, &linebuf
);
695 rb_linebuf_donebuf(&linebuf
);
698 /* sendto_channel_local_with_capability()
700 * inputs - flags to send to, caps, negate caps, channel to send to, va_args
701 * outputs - message to local channel members
705 sendto_channel_local_with_capability(int type
, int caps
, int negcaps
, struct Channel
*chptr
, const char *pattern
, ...)
709 va_start(args
, pattern
);
710 _sendto_channel_local_with_capability_butone(NULL
, type
, caps
, negcaps
, chptr
, pattern
, &args
);
715 /* sendto_channel_local_with_capability()
717 * inputs - flags to send to, caps, negate caps, channel to send to, va_args
718 * outputs - message to local channel members
722 sendto_channel_local_with_capability_butone(struct Client
*one
, int type
, int caps
, int negcaps
, struct Channel
*chptr
,
723 const char *pattern
, ...)
727 va_start(args
, pattern
);
728 _sendto_channel_local_with_capability_butone(one
, type
, caps
, negcaps
, chptr
, pattern
, &args
);
733 /* sendto_channel_local_butone()
735 * inputs - flags to send to, channel to send to, va_args
736 * - user to ignore when sending
737 * outputs - message to local channel members
741 sendto_channel_local_butone(struct Client
*one
, int type
, struct Channel
*chptr
, const char *pattern
, ...)
745 struct membership
*msptr
;
746 struct Client
*target_p
;
748 rb_dlink_node
*next_ptr
;
750 rb_linebuf_newbuf(&linebuf
);
752 va_start(args
, pattern
);
753 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
756 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
759 target_p
= msptr
->client_p
;
764 if(IsIOError(target_p
))
767 if(type
&& ((msptr
->flags
& type
) == 0))
770 _send_linebuf(target_p
, &linebuf
);
773 rb_linebuf_donebuf(&linebuf
);
777 * sendto_common_channels_local()
779 * inputs - pointer to client
783 * side effects - Sends a message to all people on local server who are
784 * in same channel with user.
785 * used by m_nick.c and exit_one_client.
788 sendto_common_channels_local(struct Client
*user
, int cap
, const char *pattern
, ...)
792 rb_dlink_node
*next_ptr
;
794 rb_dlink_node
*next_uptr
;
795 struct Channel
*chptr
;
796 struct Client
*target_p
;
797 struct membership
*msptr
;
798 struct membership
*mscptr
;
801 rb_linebuf_newbuf(&linebuf
);
802 va_start(args
, pattern
);
803 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
808 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
811 chptr
= mscptr
->chptr
;
813 RB_DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
816 target_p
= msptr
->client_p
;
818 if(IsIOError(target_p
) ||
819 target_p
->serial
== current_serial
||
820 !IsCapable(target_p
, cap
))
823 target_p
->serial
= current_serial
;
824 send_linebuf(target_p
, &linebuf
);
828 /* this can happen when the user isnt in any channels, but we still
829 * need to send them the data, ie a nick change
831 if(MyConnect(user
) && (user
->serial
!= current_serial
))
832 send_linebuf(user
, &linebuf
);
834 rb_linebuf_donebuf(&linebuf
);
838 * sendto_common_channels_local_butone()
840 * inputs - pointer to client
844 * side effects - Sends a message to all people on local server who are
845 * in same channel with user, except for user itself.
848 sendto_common_channels_local_butone(struct Client
*user
, int cap
, const char *pattern
, ...)
852 rb_dlink_node
*next_ptr
;
854 rb_dlink_node
*next_uptr
;
855 struct Channel
*chptr
;
856 struct Client
*target_p
;
857 struct membership
*msptr
;
858 struct membership
*mscptr
;
861 rb_linebuf_newbuf(&linebuf
);
862 va_start(args
, pattern
);
863 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
867 /* Skip them -- jilles */
868 user
->serial
= current_serial
;
870 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
873 chptr
= mscptr
->chptr
;
875 RB_DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
878 target_p
= msptr
->client_p
;
880 if(IsIOError(target_p
) ||
881 target_p
->serial
== current_serial
||
882 !IsCapable(target_p
, cap
))
885 target_p
->serial
= current_serial
;
886 send_linebuf(target_p
, &linebuf
);
890 rb_linebuf_donebuf(&linebuf
);
893 /* sendto_match_butone()
895 * inputs - server not to send to, source, mask, type of mask, va_args
897 * side effects - message is sent to matching clients
900 sendto_match_butone(struct Client
*one
, struct Client
*source_p
,
901 const char *mask
, int what
, const char *pattern
, ...)
903 static char buf
[BUFSIZE
];
905 struct Client
*target_p
;
907 rb_dlink_node
*next_ptr
;
908 buf_head_t rb_linebuf_local
;
909 buf_head_t rb_linebuf_id
;
911 rb_linebuf_newbuf(&rb_linebuf_local
);
912 rb_linebuf_newbuf(&rb_linebuf_id
);
914 va_start(args
, pattern
);
915 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
918 if(IsServer(source_p
))
919 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
920 ":%s %s", source_p
->name
, buf
);
922 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
924 source_p
->name
, source_p
->username
,
925 source_p
->host
, buf
);
927 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
929 if(what
== MATCH_HOST
)
931 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
933 target_p
= ptr
->data
;
935 if(match(mask
, target_p
->host
))
936 _send_linebuf(target_p
, &rb_linebuf_local
);
939 /* what = MATCH_SERVER, if it doesnt match us, just send remote */
940 else if(match(mask
, me
.name
))
942 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
944 target_p
= ptr
->data
;
945 _send_linebuf(target_p
, &rb_linebuf_local
);
949 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
951 target_p
= ptr
->data
;
956 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_id
);
959 rb_linebuf_donebuf(&rb_linebuf_local
);
960 rb_linebuf_donebuf(&rb_linebuf_id
);
963 /* sendto_match_servs()
965 * inputs - source, mask to send to, caps needed, va_args
967 * side effects - message is sent to matching servers with caps.
970 sendto_match_servs(struct Client
*source_p
, const char *mask
, int cap
,
971 int nocap
, const char *pattern
, ...)
973 static char buf
[BUFSIZE
];
976 struct Client
*target_p
;
977 buf_head_t rb_linebuf_id
;
979 if(EmptyString(mask
))
982 rb_linebuf_newbuf(&rb_linebuf_id
);
984 va_start(args
, pattern
);
985 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
988 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
,
989 ":%s %s", use_id(source_p
), buf
);
993 RB_DLINK_FOREACH(ptr
, global_serv_list
.head
)
995 target_p
= ptr
->data
;
997 /* dont send to ourselves, or back to where it came from.. */
998 if(IsMe(target_p
) || target_p
->from
== source_p
->from
)
1001 if(target_p
->from
->serial
== current_serial
)
1004 if(match(mask
, target_p
->name
))
1006 /* if we set the serial here, then we'll never do
1007 * a match() again if !IsCapable()
1009 target_p
->from
->serial
= current_serial
;
1011 if(cap
&& !IsCapable(target_p
->from
, cap
))
1014 if(nocap
&& !NotCapable(target_p
->from
, nocap
))
1017 _send_linebuf(target_p
->from
, &rb_linebuf_id
);
1021 rb_linebuf_donebuf(&rb_linebuf_id
);
1026 * inputs - monitor nick to send to, format, va_args
1027 * outputs - message to local users monitoring the given nick
1031 sendto_monitor(struct monitor
*monptr
, const char *pattern
, ...)
1035 struct Client
*target_p
;
1037 rb_dlink_node
*next_ptr
;
1039 rb_linebuf_newbuf(&linebuf
);
1041 va_start(args
, pattern
);
1042 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
1045 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, monptr
->users
.head
)
1047 target_p
= ptr
->data
;
1049 if(IsIOError(target_p
))
1052 _send_linebuf(target_p
, &linebuf
);
1055 rb_linebuf_donebuf(&linebuf
);
1058 /* sendto_anywhere()
1060 * inputs - target, source, va_args
1062 * side effects - client is sent message with correct prefix.
1065 sendto_anywhere(struct Client
*target_p
, struct Client
*source_p
,
1066 const char *command
, const char *pattern
, ...)
1071 rb_linebuf_newbuf(&linebuf
);
1073 va_start(args
, pattern
);
1075 if(MyClient(target_p
))
1077 if(IsServer(source_p
))
1078 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
1079 source_p
->name
, command
,
1082 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1084 source_p
->name
, source_p
->username
,
1085 source_p
->host
, command
,
1089 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
1090 get_id(source_p
, target_p
), command
,
1091 get_id(target_p
, target_p
));
1094 if(MyClient(target_p
))
1095 _send_linebuf(target_p
, &linebuf
);
1097 send_linebuf_remote(target_p
, source_p
, &linebuf
);
1099 rb_linebuf_donebuf(&linebuf
);
1102 /* sendto_realops_snomask()
1104 * inputs - snomask needed, level (opers/admin), va_args
1106 * side effects - message is sent to opers with matching snomasks
1109 sendto_realops_snomask(int flags
, int level
, const char *pattern
, ...)
1111 static char buf
[BUFSIZE
];
1113 struct Client
*client_p
;
1115 rb_dlink_node
*next_ptr
;
1119 rb_linebuf_newbuf(&linebuf
);
1121 /* Be very sure not to do things like "Trying to send to myself"
1122 * L_NETWIDE, otherwise infinite recursion may result! -- jilles */
1123 if (level
& L_NETWIDE
&& ConfigFileEntry
.global_snotices
)
1125 /* rather a lot of copying around, oh well -- jilles */
1126 va_start(args
, pattern
);
1127 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1129 rb_linebuf_putmsg(&linebuf
, pattern
, NULL
,
1130 ":%s NOTICE * :*** Notice -- %s", me
.name
, buf
);
1131 snobuf
= construct_snobuf(flags
);
1132 if (snobuf
[1] != '\0')
1133 sendto_server(NULL
, NULL
, CAP_ENCAP
|CAP_TS6
, NOCAPS
,
1134 ":%s ENCAP * SNOTE %c :%s",
1135 me
.id
, snobuf
[1], buf
);
1137 else if (remote_rehash_oper_p
!= NULL
)
1139 /* rather a lot of copying around, oh well -- jilles */
1140 va_start(args
, pattern
);
1141 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1143 rb_linebuf_putmsg(&linebuf
, pattern
, NULL
,
1144 ":%s NOTICE * :*** Notice -- %s", me
.name
, buf
);
1145 sendto_one_notice(remote_rehash_oper_p
, ":*** Notice -- %s", buf
);
1149 va_start(args
, pattern
);
1150 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1151 ":%s NOTICE * :*** Notice -- ", me
.name
);
1154 level
&= ~L_NETWIDE
;
1156 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1158 client_p
= ptr
->data
;
1160 /* If we're sending it to opers and theyre an admin, skip.
1161 * If we're sending it to admins, and theyre not, skip.
1163 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1164 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1167 if(client_p
->snomask
& flags
)
1168 _send_linebuf(client_p
, &linebuf
);
1171 rb_linebuf_donebuf(&linebuf
);
1173 /* sendto_realops_snomask_from()
1175 * inputs - snomask needed, level (opers/admin), source server, va_args
1177 * side effects - message is sent to opers with matching snomask
1180 sendto_realops_snomask_from(int flags
, int level
, struct Client
*source_p
,
1181 const char *pattern
, ...)
1183 struct Client
*client_p
;
1185 rb_dlink_node
*next_ptr
;
1189 rb_linebuf_newbuf(&linebuf
);
1191 va_start(args
, pattern
);
1192 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1193 ":%s NOTICE * :*** Notice -- ", source_p
->name
);
1196 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1198 client_p
= ptr
->data
;
1200 /* If we're sending it to opers and theyre an admin, skip.
1201 * If we're sending it to admins, and theyre not, skip.
1203 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1204 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1207 if(client_p
->snomask
& flags
)
1208 _send_linebuf(client_p
, &linebuf
);
1211 rb_linebuf_donebuf(&linebuf
);
1215 * sendto_wallops_flags
1217 * inputs - flag types of messages to show to real opers
1218 * - client sending request
1219 * - var args input message
1221 * side effects - Send a wallops to local opers
1224 sendto_wallops_flags(int flags
, struct Client
*source_p
, const char *pattern
, ...)
1226 struct Client
*client_p
;
1228 rb_dlink_node
*next_ptr
;
1232 rb_linebuf_newbuf(&linebuf
);
1234 va_start(args
, pattern
);
1236 if(IsPerson(source_p
))
1237 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1238 ":%s!%s@%s WALLOPS :", source_p
->name
,
1239 source_p
->username
, source_p
->host
);
1241 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s WALLOPS :", source_p
->name
);
1245 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, IsPerson(source_p
) && flags
== UMODE_WALLOP
? lclient_list
.head
: local_oper_list
.head
)
1247 client_p
= ptr
->data
;
1249 if(client_p
->umodes
& flags
)
1250 _send_linebuf(client_p
, &linebuf
);
1253 rb_linebuf_donebuf(&linebuf
);
1258 * input - client to send kill to, client to kill, va_args
1260 * side effects - we issue a kill for the client
1263 kill_client(struct Client
*target_p
, struct Client
*diedie
, const char *pattern
, ...)
1268 rb_linebuf_newbuf(&linebuf
);
1270 va_start(args
, pattern
);
1271 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s KILL %s :",
1272 get_id(&me
, target_p
), get_id(diedie
, target_p
));
1275 send_linebuf(target_p
, &linebuf
);
1276 rb_linebuf_donebuf(&linebuf
);
1281 * kill_client_serv_butone
1283 * inputs - pointer to client to not send to
1284 * - pointer to client to kill
1286 * side effects - Send a KILL for the given client
1287 * message to all connected servers
1288 * except the client 'one'. Also deal with
1289 * client being unknown to leaf, as in lazylink...
1292 kill_client_serv_butone(struct Client
*one
, struct Client
*target_p
, const char *pattern
, ...)
1294 static char buf
[BUFSIZE
];
1296 struct Client
*client_p
;
1298 rb_dlink_node
*next_ptr
;
1299 buf_head_t rb_linebuf_id
;
1301 rb_linebuf_newbuf(&rb_linebuf_id
);
1303 va_start(args
, pattern
);
1304 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1307 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s KILL %s :%s",
1308 use_id(&me
), use_id(target_p
), buf
);
1310 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
1312 client_p
= ptr
->data
;
1314 /* ok, if the client we're supposed to not send to has an
1315 * ID, then we still want to issue the kill there..
1317 if(one
!= NULL
&& (client_p
== one
->from
) &&
1318 (!has_id(client_p
) || !has_id(target_p
)))
1321 _send_linebuf(client_p
, &rb_linebuf_id
);
1324 rb_linebuf_donebuf(&rb_linebuf_id
);