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"
44 /* send the message to the link the target is attached to */
45 #define send_linebuf(a,b) _send_linebuf((a->from ? a->from : a) ,b)
47 static void send_queued_write(rb_fde_t
*F
, void *data
);
49 unsigned long current_serial
= 0L;
51 struct Client
*remote_rehash_oper_p
;
55 * inputs - client to send to, linebuf to attach
57 * side effects - linebuf is attached to client
60 _send_linebuf(struct Client
*to
, buf_head_t
*linebuf
)
64 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send message to myself!");
68 if(!MyConnect(to
) || IsIOError(to
))
71 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > get_sendq(to
))
75 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
76 "Max SendQ limit exceeded for %s: %u > %lu",
78 rb_linebuf_len(&to
->localClient
->buf_sendq
),
81 ilog(L_SERVER
, "Max SendQ limit exceeded for %s: %u > %lu",
82 log_client_name(to
, SHOW_IP
),
83 rb_linebuf_len(&to
->localClient
->buf_sendq
),
92 /* just attach the linebuf to the sendq instead of
93 * generating a new one
95 rb_linebuf_attach(&to
->localClient
->buf_sendq
, linebuf
);
99 ** Update statistics. The following is slightly incorrect
100 ** because it counts messages even if queued, but bytes
101 ** only really sent. Queued bytes get updated in SendQueued.
103 to
->localClient
->sendM
+= 1;
104 me
.localClient
->sendM
+= 1;
105 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > 0)
110 /* send_linebuf_remote()
112 * inputs - client to attach to, sender, linebuf
114 * side effects - client has linebuf attached
117 send_linebuf_remote(struct Client
*to
, struct Client
*from
, buf_head_t
*linebuf
)
122 /* we assume the caller has already tested for fake direction */
123 _send_linebuf(to
, linebuf
);
126 /* send_queued_write()
128 * inputs - fd to have queue sent, client we're sending to
129 * outputs - contents of queue
130 * side effects - write is rescheduled if queue isnt emptied
133 send_queued(struct Client
*to
)
137 rb_fde_t
*F
= to
->localClient
->F
;
141 /* cant write anything to a dead socket. */
145 /* try to flush later when the write event resets this */
149 if(rb_linebuf_len(&to
->localClient
->buf_sendq
))
152 rb_linebuf_flush(F
, &to
->localClient
->buf_sendq
)) > 0)
154 /* We have some data written .. update counters */
157 to
->localClient
->sendB
+= retlen
;
158 me
.localClient
->sendB
+= retlen
;
159 if(to
->localClient
->sendB
> 1023)
161 to
->localClient
->sendK
+= (to
->localClient
->sendB
>> 10);
162 to
->localClient
->sendB
&= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */
164 else if(me
.localClient
->sendB
> 1023)
166 me
.localClient
->sendK
+= (me
.localClient
->sendB
>> 10);
167 me
.localClient
->sendB
&= 0x03ff;
171 if(retlen
== 0 || (retlen
< 0 && !rb_ignore_errno(errno
)))
178 if(rb_linebuf_len(&to
->localClient
->buf_sendq
))
181 rb_setselect(to
->localClient
->F
, RB_SELECT_WRITE
,
182 send_queued_write
, to
);
189 send_pop_queue(struct Client
*to
)
193 if(!MyConnect(to
) || IsIOError(to
))
195 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > 0)
199 /* send_queued_write()
201 * inputs - fd to have queue sent, client we're sending to
202 * outputs - contents of queue
203 * side effects - write is scheduled if queue isnt emptied
206 send_queued_write(rb_fde_t
*F
, void *data
)
208 struct Client
*to
= data
;
213 /* linebuf_put_msgbuf
215 * inputs - msgbuf header, linebuf object, capability mask, pattern, arguments
217 * side effects - the linebuf object is cleared, then populated using rb_linebuf_putmsg().
220 linebuf_put_msgbuf(struct MsgBuf
*msgbuf
, buf_head_t
*linebuf
, unsigned int capmask
, const char *pattern
, ...)
222 char buf
[IRCD_BUFSIZE
];
225 rb_linebuf_newbuf(linebuf
);
227 msgbuf_unparse_prefix(buf
, sizeof buf
, msgbuf
, capmask
);
229 va_start(va
, pattern
);
230 rb_linebuf_putprefix(linebuf
, pattern
, &va
, buf
);
236 * inputs - msgbuf object, client the message is from
238 * side effects - a msgbuf object is populated with an origin and relevant tags
239 * notes - to make this reentrant, find a solution for `buf` below
242 build_msgbuf_from(struct MsgBuf
*msgbuf
, struct Client
*from
)
244 static char buf
[BUFSIZE
];
249 msgbuf
->origin
= buf
;
252 snprintf(buf
, sizeof buf
, "%s!%s@%s", from
->name
, from
->username
, from
->host
);
254 rb_strlcpy(buf
, from
->name
, sizeof buf
);
259 call_hook(h_outbound_msgbuf
, &hdata
);
264 * inputs - client to send to, va_args
265 * outputs - client has message put into its queue
269 sendto_one(struct Client
*target_p
, const char *pattern
, ...)
274 /* send remote if to->from non NULL */
275 if(target_p
->from
!= NULL
)
276 target_p
= target_p
->from
;
278 if(IsIOError(target_p
))
281 rb_linebuf_newbuf(&linebuf
);
283 va_start(args
, pattern
);
284 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
287 _send_linebuf(target_p
, &linebuf
);
289 rb_linebuf_donebuf(&linebuf
);
292 /* sendto_one_prefix()
294 * inputs - client to send to, va_args
295 * outputs - client has message put into its queue
296 * side effects - source(us)/target is chosen based on TS6 capability
299 sendto_one_prefix(struct Client
*target_p
, struct Client
*source_p
,
300 const char *command
, const char *pattern
, ...)
302 struct Client
*dest_p
;
306 /* send remote if to->from non NULL */
307 if(target_p
->from
!= NULL
)
308 dest_p
= target_p
->from
;
312 if(IsIOError(dest_p
))
317 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
321 rb_linebuf_newbuf(&linebuf
);
322 va_start(args
, pattern
);
323 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
325 get_id(source_p
, target_p
),
326 command
, get_id(target_p
, target_p
));
329 _send_linebuf(dest_p
, &linebuf
);
330 rb_linebuf_donebuf(&linebuf
);
333 /* sendto_one_notice()
335 * inputs - client to send to, va_args
336 * outputs - client has a NOTICE put into its queue
337 * side effects - source(us)/target is chosen based on TS6 capability
340 sendto_one_notice(struct Client
*target_p
, const char *pattern
, ...)
342 struct Client
*dest_p
;
347 /* send remote if to->from non NULL */
348 if(target_p
->from
!= NULL
)
349 dest_p
= target_p
->from
;
353 if(IsIOError(dest_p
))
358 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
362 rb_linebuf_newbuf(&linebuf
);
363 va_start(args
, pattern
);
364 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
366 get_id(&me
, target_p
), *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
369 _send_linebuf(dest_p
, &linebuf
);
370 rb_linebuf_donebuf(&linebuf
);
374 /* sendto_one_numeric()
376 * inputs - client to send to, va_args
377 * outputs - client has message put into its queue
378 * side effects - source/target is chosen based on TS6 capability
381 sendto_one_numeric(struct Client
*target_p
, int numeric
, const char *pattern
, ...)
383 struct Client
*dest_p
;
388 /* send remote if to->from non NULL */
389 if(target_p
->from
!= NULL
)
390 dest_p
= target_p
->from
;
394 if(IsIOError(dest_p
))
399 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
403 rb_linebuf_newbuf(&linebuf
);
404 va_start(args
, pattern
);
405 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
407 get_id(&me
, target_p
),
408 numeric
, *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
411 _send_linebuf(dest_p
, &linebuf
);
412 rb_linebuf_donebuf(&linebuf
);
418 * inputs - pointer to client to NOT send to
419 * - caps or'd together which must ALL be present
420 * - caps or'd together which must ALL NOT be present
421 * - printf style format string
422 * - args to format string
424 * side effects - Send a message to all connected servers, except the
425 * client 'one' (if non-NULL), as long as the servers
426 * support ALL capabs in 'caps', and NO capabs in 'nocaps'.
428 * This function was written in an attempt to merge together the other
429 * billion sendto_*serv*() functions, which sprung up with capabs, uids etc
433 sendto_server(struct Client
*one
, struct Channel
*chptr
, unsigned long caps
,
434 unsigned long nocaps
, const char *format
, ...)
437 struct Client
*target_p
;
439 rb_dlink_node
*next_ptr
;
442 /* noone to send to.. */
443 if(rb_dlink_list_length(&serv_list
) == 0)
446 if(chptr
!= NULL
&& *chptr
->chname
!= '#')
449 rb_linebuf_newbuf(&linebuf
);
450 va_start(args
, format
);
451 rb_linebuf_putmsg(&linebuf
, format
, &args
, NULL
);
454 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
456 target_p
= ptr
->data
;
458 /* check against 'one' */
459 if(one
!= NULL
&& (target_p
== one
->from
))
462 /* check we have required capabs */
463 if(!IsCapable(target_p
, caps
))
466 /* check we don't have any forbidden capabs */
467 if(!NotCapable(target_p
, nocaps
))
470 _send_linebuf(target_p
, &linebuf
);
473 rb_linebuf_donebuf(&linebuf
);
477 /* sendto_channel_flags()
479 * inputs - server not to send to, flags needed, source, channel, va_args
480 * outputs - message is sent to channel members
484 sendto_channel_flags(struct Client
*one
, int type
, struct Client
*source_p
,
485 struct Channel
*chptr
, const char *pattern
, ...)
487 static char buf
[BUFSIZE
];
489 buf_head_t rb_linebuf_local
;
490 buf_head_t rb_linebuf_id
;
491 struct Client
*target_p
;
492 struct membership
*msptr
;
494 rb_dlink_node
*next_ptr
;
496 rb_linebuf_newbuf(&rb_linebuf_local
);
497 rb_linebuf_newbuf(&rb_linebuf_id
);
501 va_start(args
, pattern
);
502 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
505 if(IsServer(source_p
))
506 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
507 ":%s %s", source_p
->name
, buf
);
509 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
511 source_p
->name
, source_p
->username
,
512 source_p
->host
, buf
);
514 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
516 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->members
.head
)
519 target_p
= msptr
->client_p
;
521 if(IsIOError(target_p
->from
) || target_p
->from
== one
)
524 if(type
&& ((msptr
->flags
& type
) == 0))
530 if(!MyClient(target_p
))
532 /* if we've got a specific type, target must support
535 if(type
&& NotCapable(target_p
->from
, CAP_CHW
))
538 if(target_p
->from
->serial
!= current_serial
)
540 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_id
);
541 target_p
->from
->serial
= current_serial
;
545 _send_linebuf(target_p
, &rb_linebuf_local
);
548 rb_linebuf_donebuf(&rb_linebuf_local
);
549 rb_linebuf_donebuf(&rb_linebuf_id
);
552 /* sendto_channel_flags()
554 * inputs - server not to send to, flags needed, source, channel, va_args
555 * outputs - message is sent to channel members
559 sendto_channel_opmod(struct Client
*one
, struct Client
*source_p
,
560 struct Channel
*chptr
, const char *command
,
563 buf_head_t rb_linebuf_local
;
564 buf_head_t rb_linebuf_old
;
565 buf_head_t rb_linebuf_new
;
566 struct Client
*target_p
;
567 struct membership
*msptr
;
569 rb_dlink_node
*next_ptr
;
571 rb_linebuf_newbuf(&rb_linebuf_local
);
572 rb_linebuf_newbuf(&rb_linebuf_old
);
573 rb_linebuf_newbuf(&rb_linebuf_new
);
577 if(IsServer(source_p
))
578 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
580 source_p
->name
, command
, chptr
->chname
, text
);
582 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
583 ":%s!%s@%s %s %s :%s",
584 source_p
->name
, source_p
->username
,
585 source_p
->host
, command
, chptr
->chname
, text
);
587 if (chptr
->mode
.mode
& MODE_MODERATED
)
588 rb_linebuf_putmsg(&rb_linebuf_old
, NULL
, NULL
,
590 use_id(source_p
), command
, chptr
->chname
, text
);
592 rb_linebuf_putmsg(&rb_linebuf_old
, NULL
, NULL
,
593 ":%s NOTICE @%s :<%s:%s> %s",
594 use_id(source_p
->servptr
), chptr
->chname
,
595 source_p
->name
, chptr
->chname
, text
);
596 rb_linebuf_putmsg(&rb_linebuf_new
, NULL
, NULL
,
598 use_id(source_p
), command
, chptr
->chname
, text
);
600 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->members
.head
)
603 target_p
= msptr
->client_p
;
605 if(IsIOError(target_p
->from
) || target_p
->from
== one
)
608 if((msptr
->flags
& CHFL_CHANOP
) == 0)
614 if(!MyClient(target_p
))
616 /* if we've got a specific type, target must support
619 if(NotCapable(target_p
->from
, CAP_CHW
))
622 if(target_p
->from
->serial
!= current_serial
)
624 if (IsCapable(target_p
->from
, CAP_EOPMOD
))
625 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_new
);
627 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_old
);
628 target_p
->from
->serial
= current_serial
;
632 _send_linebuf(target_p
, &rb_linebuf_local
);
635 rb_linebuf_donebuf(&rb_linebuf_local
);
636 rb_linebuf_donebuf(&rb_linebuf_old
);
637 rb_linebuf_donebuf(&rb_linebuf_new
);
640 /* sendto_channel_local()
642 * inputs - flags to send to, channel to send to, va_args
643 * outputs - message to local channel members
647 sendto_channel_local(int type
, struct Channel
*chptr
, const char *pattern
, ...)
651 struct membership
*msptr
;
652 struct Client
*target_p
;
654 rb_dlink_node
*next_ptr
;
656 rb_linebuf_newbuf(&linebuf
);
658 va_start(args
, pattern
);
659 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
662 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
665 target_p
= msptr
->client_p
;
667 if(IsIOError(target_p
))
670 if(type
== ONLY_OPERS
)
672 if (!IsOper(target_p
))
675 else if(type
&& ((msptr
->flags
& type
) == 0))
678 _send_linebuf(target_p
, &linebuf
);
681 rb_linebuf_donebuf(&linebuf
);
685 * _sendto_channel_local_with_capability_butone()
687 * Shared implementation of sendto_channel_local_with_capability and sendto_channel_local_with_capability_butone
690 _sendto_channel_local_with_capability_butone(struct Client
*one
, int type
, int caps
, int negcaps
, struct Channel
*chptr
,
691 const char *pattern
, va_list * args
)
694 struct membership
*msptr
;
695 struct Client
*target_p
;
697 rb_dlink_node
*next_ptr
;
699 rb_linebuf_newbuf(&linebuf
);
700 rb_linebuf_putmsg(&linebuf
, pattern
, args
, NULL
);
702 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
705 target_p
= msptr
->client_p
;
710 if(IsIOError(target_p
) ||
711 !IsCapable(target_p
, caps
) ||
712 !NotCapable(target_p
, negcaps
))
715 if(type
&& ((msptr
->flags
& type
) == 0))
718 _send_linebuf(target_p
, &linebuf
);
721 rb_linebuf_donebuf(&linebuf
);
724 /* sendto_channel_local_with_capability()
726 * inputs - flags to send to, caps, negate caps, channel to send to, va_args
727 * outputs - message to local channel members
731 sendto_channel_local_with_capability(int type
, int caps
, int negcaps
, struct Channel
*chptr
, const char *pattern
, ...)
735 va_start(args
, pattern
);
736 _sendto_channel_local_with_capability_butone(NULL
, type
, caps
, negcaps
, chptr
, pattern
, &args
);
741 /* sendto_channel_local_with_capability()
743 * inputs - flags to send to, caps, negate caps, channel to send to, va_args
744 * outputs - message to local channel members
748 sendto_channel_local_with_capability_butone(struct Client
*one
, int type
, int caps
, int negcaps
, struct Channel
*chptr
,
749 const char *pattern
, ...)
753 va_start(args
, pattern
);
754 _sendto_channel_local_with_capability_butone(one
, type
, caps
, negcaps
, chptr
, pattern
, &args
);
759 /* sendto_channel_local_butone()
761 * inputs - flags to send to, channel to send to, va_args
762 * - user to ignore when sending
763 * outputs - message to local channel members
767 sendto_channel_local_butone(struct Client
*one
, int type
, struct Channel
*chptr
, const char *pattern
, ...)
771 struct membership
*msptr
;
772 struct Client
*target_p
;
774 rb_dlink_node
*next_ptr
;
776 rb_linebuf_newbuf(&linebuf
);
778 va_start(args
, pattern
);
779 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
782 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
785 target_p
= msptr
->client_p
;
790 if(IsIOError(target_p
))
793 if(type
&& ((msptr
->flags
& type
) == 0))
796 _send_linebuf(target_p
, &linebuf
);
799 rb_linebuf_donebuf(&linebuf
);
803 * sendto_common_channels_local()
805 * inputs - pointer to client
807 * - negated capability mask
810 * side effects - Sends a message to all people on local server who are
811 * in same channel with user.
812 * used by m_nick.c and exit_one_client.
815 sendto_common_channels_local(struct Client
*user
, int cap
, int negcap
, const char *pattern
, ...)
819 rb_dlink_node
*next_ptr
;
821 rb_dlink_node
*next_uptr
;
822 struct Channel
*chptr
;
823 struct Client
*target_p
;
824 struct membership
*msptr
;
825 struct membership
*mscptr
;
828 rb_linebuf_newbuf(&linebuf
);
829 va_start(args
, pattern
);
830 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
835 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
838 chptr
= mscptr
->chptr
;
840 RB_DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
843 target_p
= msptr
->client_p
;
845 if(IsIOError(target_p
) ||
846 target_p
->serial
== current_serial
||
847 !IsCapable(target_p
, cap
) ||
848 !NotCapable(target_p
, negcap
))
851 target_p
->serial
= current_serial
;
852 send_linebuf(target_p
, &linebuf
);
856 /* this can happen when the user isnt in any channels, but we still
857 * need to send them the data, ie a nick change
859 if(MyConnect(user
) && (user
->serial
!= current_serial
))
860 send_linebuf(user
, &linebuf
);
862 rb_linebuf_donebuf(&linebuf
);
866 * sendto_common_channels_local_butone()
868 * inputs - pointer to client
870 * - negated capability mask
873 * side effects - Sends a message to all people on local server who are
874 * in same channel with user, except for user itself.
877 sendto_common_channels_local_butone(struct Client
*user
, int cap
, int negcap
, const char *pattern
, ...)
881 rb_dlink_node
*next_ptr
;
883 rb_dlink_node
*next_uptr
;
884 struct Channel
*chptr
;
885 struct Client
*target_p
;
886 struct membership
*msptr
;
887 struct membership
*mscptr
;
890 rb_linebuf_newbuf(&linebuf
);
891 va_start(args
, pattern
);
892 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
896 /* Skip them -- jilles */
897 user
->serial
= current_serial
;
899 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
902 chptr
= mscptr
->chptr
;
904 RB_DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
907 target_p
= msptr
->client_p
;
909 if(IsIOError(target_p
) ||
910 target_p
->serial
== current_serial
||
911 !IsCapable(target_p
, cap
) ||
912 !NotCapable(target_p
, negcap
))
915 target_p
->serial
= current_serial
;
916 send_linebuf(target_p
, &linebuf
);
920 rb_linebuf_donebuf(&linebuf
);
923 /* sendto_match_butone()
925 * inputs - server not to send to, source, mask, type of mask, va_args
927 * side effects - message is sent to matching clients
930 sendto_match_butone(struct Client
*one
, struct Client
*source_p
,
931 const char *mask
, int what
, const char *pattern
, ...)
933 static char buf
[BUFSIZE
];
935 struct Client
*target_p
;
937 rb_dlink_node
*next_ptr
;
938 buf_head_t rb_linebuf_local
;
939 buf_head_t rb_linebuf_id
;
941 rb_linebuf_newbuf(&rb_linebuf_local
);
942 rb_linebuf_newbuf(&rb_linebuf_id
);
944 va_start(args
, pattern
);
945 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
948 if(IsServer(source_p
))
949 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
950 ":%s %s", source_p
->name
, buf
);
952 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
954 source_p
->name
, source_p
->username
,
955 source_p
->host
, buf
);
957 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
959 if(what
== MATCH_HOST
)
961 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
963 target_p
= ptr
->data
;
965 if(match(mask
, target_p
->host
))
966 _send_linebuf(target_p
, &rb_linebuf_local
);
969 /* what = MATCH_SERVER, if it doesnt match us, just send remote */
970 else if(match(mask
, me
.name
))
972 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
974 target_p
= ptr
->data
;
975 _send_linebuf(target_p
, &rb_linebuf_local
);
979 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
981 target_p
= ptr
->data
;
986 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_id
);
989 rb_linebuf_donebuf(&rb_linebuf_local
);
990 rb_linebuf_donebuf(&rb_linebuf_id
);
993 /* sendto_match_servs()
995 * inputs - source, mask to send to, caps needed, va_args
997 * side effects - message is sent to matching servers with caps.
1000 sendto_match_servs(struct Client
*source_p
, const char *mask
, int cap
,
1001 int nocap
, const char *pattern
, ...)
1003 static char buf
[BUFSIZE
];
1006 struct Client
*target_p
;
1007 buf_head_t rb_linebuf_id
;
1009 if(EmptyString(mask
))
1012 rb_linebuf_newbuf(&rb_linebuf_id
);
1014 va_start(args
, pattern
);
1015 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1018 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
,
1019 ":%s %s", use_id(source_p
), buf
);
1023 RB_DLINK_FOREACH(ptr
, global_serv_list
.head
)
1025 target_p
= ptr
->data
;
1027 /* dont send to ourselves, or back to where it came from.. */
1028 if(IsMe(target_p
) || target_p
->from
== source_p
->from
)
1031 if(target_p
->from
->serial
== current_serial
)
1034 if(match(mask
, target_p
->name
))
1036 /* if we set the serial here, then we'll never do
1037 * a match() again if !IsCapable()
1039 target_p
->from
->serial
= current_serial
;
1041 if(cap
&& !IsCapable(target_p
->from
, cap
))
1044 if(nocap
&& !NotCapable(target_p
->from
, nocap
))
1047 _send_linebuf(target_p
->from
, &rb_linebuf_id
);
1051 rb_linebuf_donebuf(&rb_linebuf_id
);
1054 /* sendto_local_clients_with_capability()
1056 * inputs - caps needed, pattern, va_args
1058 * side effects - message is sent to matching local clients with caps.
1061 sendto_local_clients_with_capability(int cap
, const char *pattern
, ...)
1065 struct Client
*target_p
;
1068 rb_linebuf_newbuf(&linebuf
);
1070 va_start(args
, pattern
);
1071 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
1074 RB_DLINK_FOREACH(ptr
, lclient_list
.head
)
1076 target_p
= ptr
->data
;
1078 if(IsIOError(target_p
) || !IsCapable(target_p
, cap
))
1081 send_linebuf(target_p
, &linebuf
);
1084 rb_linebuf_donebuf(&linebuf
);
1089 * inputs - monitor nick to send to, format, va_args
1090 * outputs - message to local users monitoring the given nick
1094 sendto_monitor(struct monitor
*monptr
, const char *pattern
, ...)
1098 struct Client
*target_p
;
1100 rb_dlink_node
*next_ptr
;
1102 rb_linebuf_newbuf(&linebuf
);
1104 va_start(args
, pattern
);
1105 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
1108 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, monptr
->users
.head
)
1110 target_p
= ptr
->data
;
1112 if(IsIOError(target_p
))
1115 _send_linebuf(target_p
, &linebuf
);
1118 rb_linebuf_donebuf(&linebuf
);
1121 /* sendto_anywhere()
1123 * inputs - target, source, va_args
1125 * side effects - client is sent message with correct prefix.
1128 sendto_anywhere(struct Client
*target_p
, struct Client
*source_p
,
1129 const char *command
, const char *pattern
, ...)
1134 rb_linebuf_newbuf(&linebuf
);
1136 va_start(args
, pattern
);
1138 if(MyClient(target_p
))
1140 if(IsServer(source_p
))
1141 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
1142 source_p
->name
, command
,
1145 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1147 source_p
->name
, source_p
->username
,
1148 source_p
->host
, command
,
1152 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
1153 get_id(source_p
, target_p
), command
,
1154 get_id(target_p
, target_p
));
1157 if(MyClient(target_p
))
1158 _send_linebuf(target_p
, &linebuf
);
1160 send_linebuf_remote(target_p
, source_p
, &linebuf
);
1162 rb_linebuf_donebuf(&linebuf
);
1165 /* sendto_realops_snomask()
1167 * inputs - snomask needed, level (opers/admin), va_args
1169 * side effects - message is sent to opers with matching snomasks
1172 sendto_realops_snomask(int flags
, int level
, const char *pattern
, ...)
1174 static char buf
[BUFSIZE
];
1176 struct Client
*client_p
;
1178 rb_dlink_node
*next_ptr
;
1182 rb_linebuf_newbuf(&linebuf
);
1184 /* Be very sure not to do things like "Trying to send to myself"
1185 * L_NETWIDE, otherwise infinite recursion may result! -- jilles */
1186 if (level
& L_NETWIDE
&& ConfigFileEntry
.global_snotices
)
1188 /* rather a lot of copying around, oh well -- jilles */
1189 va_start(args
, pattern
);
1190 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1192 rb_linebuf_putmsg(&linebuf
, pattern
, NULL
,
1193 ":%s NOTICE * :*** Notice -- %s", me
.name
, buf
);
1194 snobuf
= construct_snobuf(flags
);
1195 if (snobuf
[1] != '\0')
1196 sendto_server(NULL
, NULL
, CAP_ENCAP
|CAP_TS6
, NOCAPS
,
1197 ":%s ENCAP * SNOTE %c :%s",
1198 me
.id
, snobuf
[1], buf
);
1200 else if (remote_rehash_oper_p
!= NULL
)
1202 /* rather a lot of copying around, oh well -- jilles */
1203 va_start(args
, pattern
);
1204 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1206 rb_linebuf_putmsg(&linebuf
, pattern
, NULL
,
1207 ":%s NOTICE * :*** Notice -- %s", me
.name
, buf
);
1208 sendto_one_notice(remote_rehash_oper_p
, ":*** Notice -- %s", buf
);
1212 va_start(args
, pattern
);
1213 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1214 ":%s NOTICE * :*** Notice -- ", me
.name
);
1217 level
&= ~L_NETWIDE
;
1219 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1221 client_p
= ptr
->data
;
1223 /* If we're sending it to opers and theyre an admin, skip.
1224 * If we're sending it to admins, and theyre not, skip.
1226 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1227 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1230 if(client_p
->snomask
& flags
)
1231 _send_linebuf(client_p
, &linebuf
);
1234 rb_linebuf_donebuf(&linebuf
);
1236 /* sendto_realops_snomask_from()
1238 * inputs - snomask needed, level (opers/admin), source server, va_args
1240 * side effects - message is sent to opers with matching snomask
1243 sendto_realops_snomask_from(int flags
, int level
, struct Client
*source_p
,
1244 const char *pattern
, ...)
1246 struct Client
*client_p
;
1248 rb_dlink_node
*next_ptr
;
1252 rb_linebuf_newbuf(&linebuf
);
1254 va_start(args
, pattern
);
1255 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1256 ":%s NOTICE * :*** Notice -- ", source_p
->name
);
1259 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1261 client_p
= ptr
->data
;
1263 /* If we're sending it to opers and theyre an admin, skip.
1264 * If we're sending it to admins, and theyre not, skip.
1266 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1267 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1270 if(client_p
->snomask
& flags
)
1271 _send_linebuf(client_p
, &linebuf
);
1274 rb_linebuf_donebuf(&linebuf
);
1278 * sendto_wallops_flags
1280 * inputs - flag types of messages to show to real opers
1281 * - client sending request
1282 * - var args input message
1284 * side effects - Send a wallops to local opers
1287 sendto_wallops_flags(int flags
, struct Client
*source_p
, const char *pattern
, ...)
1289 struct Client
*client_p
;
1291 rb_dlink_node
*next_ptr
;
1295 rb_linebuf_newbuf(&linebuf
);
1297 va_start(args
, pattern
);
1299 if(IsPerson(source_p
))
1300 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1301 ":%s!%s@%s WALLOPS :", source_p
->name
,
1302 source_p
->username
, source_p
->host
);
1304 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s WALLOPS :", source_p
->name
);
1308 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, IsPerson(source_p
) && flags
== UMODE_WALLOP
? lclient_list
.head
: local_oper_list
.head
)
1310 client_p
= ptr
->data
;
1312 if(client_p
->umodes
& flags
)
1313 _send_linebuf(client_p
, &linebuf
);
1316 rb_linebuf_donebuf(&linebuf
);
1321 * input - client to send kill to, client to kill, va_args
1323 * side effects - we issue a kill for the client
1326 kill_client(struct Client
*target_p
, struct Client
*diedie
, const char *pattern
, ...)
1331 rb_linebuf_newbuf(&linebuf
);
1333 va_start(args
, pattern
);
1334 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s KILL %s :",
1335 get_id(&me
, target_p
), get_id(diedie
, target_p
));
1338 send_linebuf(target_p
, &linebuf
);
1339 rb_linebuf_donebuf(&linebuf
);
1344 * kill_client_serv_butone
1346 * inputs - pointer to client to not send to
1347 * - pointer to client to kill
1349 * side effects - Send a KILL for the given client
1350 * message to all connected servers
1351 * except the client 'one'. Also deal with
1352 * client being unknown to leaf, as in lazylink...
1355 kill_client_serv_butone(struct Client
*one
, struct Client
*target_p
, const char *pattern
, ...)
1357 static char buf
[BUFSIZE
];
1359 struct Client
*client_p
;
1361 rb_dlink_node
*next_ptr
;
1362 buf_head_t rb_linebuf_id
;
1364 rb_linebuf_newbuf(&rb_linebuf_id
);
1366 va_start(args
, pattern
);
1367 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1370 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s KILL %s :%s",
1371 use_id(&me
), use_id(target_p
), buf
);
1373 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
1375 client_p
= ptr
->data
;
1377 /* ok, if the client we're supposed to not send to has an
1378 * ID, then we still want to issue the kill there..
1380 if(one
!= NULL
&& (client_p
== one
->from
) &&
1381 (!has_id(client_p
) || !has_id(target_p
)))
1384 _send_linebuf(client_p
, &rb_linebuf_id
);
1387 rb_linebuf_donebuf(&rb_linebuf_id
);