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
36 #include "s_newconf.h"
42 /* send the message to the link the target is attached to */
43 #define send_linebuf(a,b) _send_linebuf((a->from ? a->from : a) ,b)
45 static void send_queued_write(rb_fde_t
*F
, void *data
);
47 unsigned long current_serial
= 0L;
49 struct Client
*remote_rehash_oper_p
;
53 * inputs - client to send to, linebuf to attach
55 * side effects - linebuf is attached to client
58 _send_linebuf(struct Client
*to
, buf_head_t
*linebuf
)
62 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send message to myself!");
66 if(!MyConnect(to
) || IsIOError(to
))
69 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > get_sendq(to
))
73 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
74 "Max SendQ limit exceeded for %s: %u > %lu",
76 rb_linebuf_len(&to
->localClient
->buf_sendq
),
79 ilog(L_SERVER
, "Max SendQ limit exceeded for %s: %u > %lu",
80 log_client_name(to
, SHOW_IP
),
81 rb_linebuf_len(&to
->localClient
->buf_sendq
),
90 /* just attach the linebuf to the sendq instead of
91 * generating a new one
93 rb_linebuf_attach(&to
->localClient
->buf_sendq
, linebuf
);
97 ** Update statistics. The following is slightly incorrect
98 ** because it counts messages even if queued, but bytes
99 ** only really sent. Queued bytes get updated in SendQueued.
101 to
->localClient
->sendM
+= 1;
102 me
.localClient
->sendM
+= 1;
103 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > 0)
108 /* send_linebuf_remote()
110 * inputs - client to attach to, sender, linebuf
112 * side effects - client has linebuf attached
115 send_linebuf_remote(struct Client
*to
, struct Client
*from
, buf_head_t
*linebuf
)
120 /* we assume the caller has already tested for fake direction */
121 _send_linebuf(to
, linebuf
);
124 /* send_queued_write()
126 * inputs - fd to have queue sent, client we're sending to
127 * outputs - contents of queue
128 * side effects - write is rescheduled if queue isnt emptied
131 send_queued(struct Client
*to
)
135 rb_fde_t
*F
= to
->localClient
->F
;
139 /* cant write anything to a dead socket. */
143 /* try to flush later when the write event resets this */
147 if(rb_linebuf_len(&to
->localClient
->buf_sendq
))
150 rb_linebuf_flush(F
, &to
->localClient
->buf_sendq
)) > 0)
152 /* We have some data written .. update counters */
155 to
->localClient
->sendB
+= retlen
;
156 me
.localClient
->sendB
+= retlen
;
157 if(to
->localClient
->sendB
> 1023)
159 to
->localClient
->sendK
+= (to
->localClient
->sendB
>> 10);
160 to
->localClient
->sendB
&= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */
162 else if(me
.localClient
->sendB
> 1023)
164 me
.localClient
->sendK
+= (me
.localClient
->sendB
>> 10);
165 me
.localClient
->sendB
&= 0x03ff;
169 if(retlen
== 0 || (retlen
< 0 && !rb_ignore_errno(errno
)))
176 if(rb_linebuf_len(&to
->localClient
->buf_sendq
))
179 rb_setselect(to
->localClient
->F
, RB_SELECT_WRITE
,
180 send_queued_write
, to
);
187 send_pop_queue(struct Client
*to
)
191 if(!MyConnect(to
) || IsIOError(to
))
193 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > 0)
197 /* send_queued_write()
199 * inputs - fd to have queue sent, client we're sending to
200 * outputs - contents of queue
201 * side effects - write is scheduled if queue isnt emptied
204 send_queued_write(rb_fde_t
*F
, void *data
)
206 struct Client
*to
= data
;
212 * linebuf_put_tags_prefix
214 * inputs - msgbuf header, linebuf object, capability mask, pattern, arguments
216 * side effects - the linebuf object is cleared, then populated using rb_linebuf_putprefix().
219 linebuf_put_tags_vprefix(struct MsgBuf
*msgbuf
, buf_head_t
*linebuf
, unsigned int capmask
, const char *pattern
, va_list *va
)
221 static char buf
[EXT_BUFSIZE
];
222 size_t buflen
= sizeof(buf
);
224 rb_linebuf_newbuf(linebuf
);
225 msgbuf_unparse_prefix(buf
, &buflen
, msgbuf
, capmask
);
226 rb_linebuf_put_vtags_prefix(linebuf
, pattern
, va
, buflen
, buf
);
229 /* linebuf_put_tags_prefixf
231 * inputs - msgbuf header, linebuf object, capability mask, pattern, arguments
233 * side effects - the linebuf object is cleared, then populated using rb_linebuf_putprefix().
236 linebuf_put_tags_prefixf(struct MsgBuf
*msgbuf
, buf_head_t
*linebuf
, unsigned int capmask
, const char *pattern
, ...)
240 va_start(va
, pattern
);
241 linebuf_put_tags_vprefix(msgbuf
, linebuf
, capmask
, pattern
, &va
);
247 * inputs - msgbuf object, client the message is from
249 * side effects - a msgbuf object is populated with an origin and relevant tags
250 * notes - to make this reentrant, find a solution for `buf` below
253 build_msgbuf_from(struct MsgBuf
*msgbuf
, struct Client
*from
, const char *cmd
)
255 static char buf
[BUFSIZE
];
260 msgbuf
->origin
= buf
;
263 if (from
!= NULL
&& IsPerson(from
))
264 snprintf(buf
, sizeof buf
, "%s!%s@%s", from
->name
, from
->username
, from
->host
);
265 else if (from
!= NULL
)
266 rb_strlcpy(buf
, from
->name
, sizeof buf
);
268 rb_strlcpy(buf
, me
.name
, sizeof buf
);
273 call_hook(h_outbound_msgbuf
, &hdata
);
278 * inputs - client to send to, va_args
279 * outputs - client has message put into its queue
283 sendto_one(struct Client
*target_p
, const char *pattern
, ...)
288 /* send remote if to->from non NULL */
289 if(target_p
->from
!= NULL
)
290 target_p
= target_p
->from
;
292 if(IsIOError(target_p
))
295 rb_linebuf_newbuf(&linebuf
);
297 va_start(args
, pattern
);
298 rb_linebuf_put_vmsg(&linebuf
, pattern
, &args
);
301 _send_linebuf(target_p
, &linebuf
);
303 rb_linebuf_donebuf(&linebuf
);
306 /* sendto_one_prefix()
308 * inputs - client to send to, va_args
309 * outputs - client has message put into its queue
310 * side effects - source(us)/target is chosen based on TS6 capability
313 sendto_one_prefix(struct Client
*target_p
, struct Client
*source_p
,
314 const char *command
, const char *pattern
, ...)
316 struct Client
*dest_p
= target_p
->from
;
320 if(IsIOError(dest_p
))
325 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
329 rb_linebuf_newbuf(&linebuf
);
330 va_start(args
, pattern
);
331 rb_linebuf_put_vmsg_prefixf(&linebuf
, pattern
, &args
,
333 get_id(source_p
, target_p
),
334 command
, get_id(target_p
, target_p
));
337 _send_linebuf(dest_p
, &linebuf
);
338 rb_linebuf_donebuf(&linebuf
);
341 /* sendto_one_notice()
343 * inputs - client to send to, va_args
344 * outputs - client has a NOTICE put into its queue
345 * side effects - source(us)/target is chosen based on TS6 capability
348 sendto_one_notice(struct Client
*target_p
, const char *pattern
, ...)
350 struct Client
*dest_p
= target_p
->from
;
355 if(IsIOError(dest_p
))
360 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
364 rb_linebuf_newbuf(&linebuf
);
365 va_start(args
, pattern
);
366 rb_linebuf_put_vmsg_prefixf(&linebuf
, pattern
, &args
,
368 get_id(&me
, target_p
), *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
371 _send_linebuf(dest_p
, &linebuf
);
372 rb_linebuf_donebuf(&linebuf
);
376 /* sendto_one_numeric()
378 * inputs - client to send to, va_args
379 * outputs - client has message put into its queue
380 * side effects - source/target is chosen based on TS6 capability
383 sendto_one_numeric(struct Client
*target_p
, int numeric
, const char *pattern
, ...)
385 struct Client
*dest_p
= target_p
->from
;
390 if(IsIOError(dest_p
))
395 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
399 rb_linebuf_newbuf(&linebuf
);
400 va_start(args
, pattern
);
401 rb_linebuf_put_vmsg_prefixf(&linebuf
, pattern
, &args
,
403 get_id(&me
, target_p
),
404 numeric
, *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
407 _send_linebuf(dest_p
, &linebuf
);
408 rb_linebuf_donebuf(&linebuf
);
414 * inputs - pointer to client to NOT send to
415 * - caps or'd together which must ALL be present
416 * - caps or'd together which must ALL NOT be present
417 * - printf style format string
418 * - args to format string
420 * side effects - Send a message to all connected servers, except the
421 * client 'one' (if non-NULL), as long as the servers
422 * support ALL capabs in 'caps', and NO capabs in 'nocaps'.
424 * This function was written in an attempt to merge together the other
425 * billion sendto_*serv*() functions, which sprung up with capabs, uids etc
429 sendto_server(struct Client
*one
, struct Channel
*chptr
, unsigned long caps
,
430 unsigned long nocaps
, const char *format
, ...)
433 struct Client
*target_p
;
435 rb_dlink_node
*next_ptr
;
438 /* noone to send to.. */
439 if(rb_dlink_list_length(&serv_list
) == 0)
442 if(chptr
!= NULL
&& *chptr
->chname
!= '#')
445 rb_linebuf_newbuf(&linebuf
);
446 va_start(args
, format
);
447 rb_linebuf_put_vmsg(&linebuf
, format
, &args
);
450 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
452 target_p
= ptr
->data
;
454 /* check against 'one' */
455 if(one
!= NULL
&& (target_p
== one
->from
))
458 /* check we have required capabs */
459 if(!IsCapable(target_p
, caps
))
462 /* check we don't have any forbidden capabs */
463 if(!NotCapable(target_p
, nocaps
))
466 _send_linebuf(target_p
, &linebuf
);
469 rb_linebuf_donebuf(&linebuf
);
472 /* sendto_channel_flags()
474 * inputs - server not to send to, flags needed, source, channel, va_args
475 * outputs - message is sent to channel members
479 sendto_channel_flags(struct Client
*one
, int type
, struct Client
*source_p
,
480 struct Channel
*chptr
, const char *pattern
, ...)
482 static char buf
[BUFSIZE
];
484 buf_head_t rb_linebuf_local
;
485 buf_head_t rb_linebuf_remote
;
486 struct Client
*target_p
;
487 struct membership
*msptr
;
489 rb_dlink_node
*next_ptr
;
490 int current_capmask
= NOCAPS
;
491 struct MsgBuf msgbuf
;
493 rb_linebuf_newbuf(&rb_linebuf_local
);
494 rb_linebuf_newbuf(&rb_linebuf_remote
);
498 build_msgbuf_from(&msgbuf
, source_p
, NULL
);
500 va_start(args
, pattern
);
501 vsnprintf(buf
, sizeof buf
, pattern
, args
);
504 linebuf_put_tags_prefixf(&msgbuf
, &rb_linebuf_local
, current_capmask
, "%s", buf
);
505 rb_linebuf_put_msgf(&rb_linebuf_remote
, ":%s %s", use_id(source_p
), buf
);
507 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->members
.head
)
510 target_p
= msptr
->client_p
;
512 if(!MyClient(source_p
) && (IsIOError(target_p
->from
) || target_p
->from
== one
))
515 if(MyClient(source_p
) && target_p
== one
)
518 if(type
&& ((msptr
->flags
& type
) == 0))
524 if(!MyClient(target_p
))
526 /* if we've got a specific type, target must support
529 if(type
&& NotCapable(target_p
->from
, CAP_CHW
))
532 if(target_p
->from
->serial
!= current_serial
)
534 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_remote
);
535 target_p
->from
->serial
= current_serial
;
540 if (target_p
->localClient
->caps
!= current_capmask
)
542 /* reset the linebuf */
543 rb_linebuf_donebuf(&rb_linebuf_local
);
544 rb_linebuf_newbuf(&rb_linebuf_local
);
546 /* render the new linebuf and attach it */
547 current_capmask
= target_p
->localClient
->caps
;
548 linebuf_put_tags_prefixf(&msgbuf
, &rb_linebuf_local
, current_capmask
, "%s", buf
);
551 _send_linebuf(target_p
, &rb_linebuf_local
);
555 /* source client may not be on the channel, send echo separately */
556 if(MyClient(source_p
) && IsCapable(source_p
, CLICAP_ECHO_MESSAGE
))
560 if (target_p
->localClient
->caps
!= current_capmask
)
562 /* reset the linebuf */
563 rb_linebuf_donebuf(&rb_linebuf_local
);
564 rb_linebuf_newbuf(&rb_linebuf_local
);
566 /* render the new linebuf and attach it */
567 current_capmask
= target_p
->localClient
->caps
;
568 linebuf_put_tags_prefixf(&msgbuf
, &rb_linebuf_local
, current_capmask
, "%s", buf
);
571 _send_linebuf(target_p
, &rb_linebuf_local
);
574 rb_linebuf_donebuf(&rb_linebuf_local
);
575 rb_linebuf_donebuf(&rb_linebuf_remote
);
578 /* sendto_channel_flags()
580 * inputs - server not to send to, flags needed, source, channel, va_args
581 * outputs - message is sent to channel members
585 sendto_channel_opmod(struct Client
*one
, struct Client
*source_p
,
586 struct Channel
*chptr
, const char *command
,
589 buf_head_t rb_linebuf_local
;
590 buf_head_t rb_linebuf_old
;
591 buf_head_t rb_linebuf_new
;
592 struct Client
*target_p
;
593 struct membership
*msptr
;
595 rb_dlink_node
*next_ptr
;
597 rb_linebuf_newbuf(&rb_linebuf_local
);
598 rb_linebuf_newbuf(&rb_linebuf_old
);
599 rb_linebuf_newbuf(&rb_linebuf_new
);
603 if(IsServer(source_p
))
604 rb_linebuf_put_msgf(&rb_linebuf_local
,
606 source_p
->name
, command
, chptr
->chname
, text
);
608 rb_linebuf_put_msgf(&rb_linebuf_local
,
609 ":%s!%s@%s %s %s :%s",
610 source_p
->name
, source_p
->username
,
611 source_p
->host
, command
, chptr
->chname
, text
);
613 if (chptr
->mode
.mode
& MODE_MODERATED
)
614 rb_linebuf_put_msgf(&rb_linebuf_old
,
616 use_id(source_p
), command
, chptr
->chname
, text
);
618 rb_linebuf_put_msgf(&rb_linebuf_old
,
619 ":%s NOTICE @%s :<%s:%s> %s",
620 use_id(source_p
->servptr
), chptr
->chname
,
621 source_p
->name
, chptr
->chname
, text
);
622 rb_linebuf_put_msgf(&rb_linebuf_new
,
624 use_id(source_p
), command
, chptr
->chname
, text
);
626 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->members
.head
)
629 target_p
= msptr
->client_p
;
631 if(!MyClient(source_p
) && (IsIOError(target_p
->from
) || target_p
->from
== one
))
634 if(MyClient(source_p
) && target_p
== one
)
637 if((msptr
->flags
& CHFL_CHANOP
) == 0)
643 if(!MyClient(target_p
))
645 /* if we've got a specific type, target must support
648 if(NotCapable(target_p
->from
, CAP_CHW
))
651 if(target_p
->from
->serial
!= current_serial
)
653 if (IsCapable(target_p
->from
, CAP_EOPMOD
))
654 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_new
);
656 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_old
);
657 target_p
->from
->serial
= current_serial
;
661 _send_linebuf(target_p
, &rb_linebuf_local
);
664 /* source client may not be on the channel, send echo separately */
665 if(MyClient(source_p
) && IsCapable(source_p
, CLICAP_ECHO_MESSAGE
))
669 _send_linebuf(target_p
, &rb_linebuf_local
);
672 rb_linebuf_donebuf(&rb_linebuf_local
);
673 rb_linebuf_donebuf(&rb_linebuf_old
);
674 rb_linebuf_donebuf(&rb_linebuf_new
);
677 /* sendto_channel_local()
679 * inputs - flags to send to, channel to send to, va_args
680 * outputs - message to local channel members
684 sendto_channel_local(int type
, struct Channel
*chptr
, const char *pattern
, ...)
688 struct membership
*msptr
;
689 struct Client
*target_p
;
691 rb_dlink_node
*next_ptr
;
693 rb_linebuf_newbuf(&linebuf
);
695 va_start(args
, pattern
);
696 rb_linebuf_put_vmsg(&linebuf
, pattern
, &args
);
699 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
702 target_p
= msptr
->client_p
;
704 if(IsIOError(target_p
))
707 if(type
== ONLY_OPERS
)
709 if (!IsOper(target_p
))
712 else if(type
&& ((msptr
->flags
& type
) == 0))
715 _send_linebuf(target_p
, &linebuf
);
718 rb_linebuf_donebuf(&linebuf
);
722 * _sendto_channel_local_with_capability_butone()
724 * Shared implementation of sendto_channel_local_with_capability and sendto_channel_local_with_capability_butone
727 _sendto_channel_local_with_capability_butone(struct Client
*one
, int type
, int caps
, int negcaps
, struct Channel
*chptr
,
728 const char *pattern
, va_list * args
)
731 struct membership
*msptr
;
732 struct Client
*target_p
;
734 rb_dlink_node
*next_ptr
;
736 rb_linebuf_newbuf(&linebuf
);
737 rb_linebuf_put_vmsg(&linebuf
, pattern
, args
);
739 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
742 target_p
= msptr
->client_p
;
747 if(IsIOError(target_p
) ||
748 !IsCapable(target_p
, caps
) ||
749 !NotCapable(target_p
, negcaps
))
752 if(type
&& ((msptr
->flags
& type
) == 0))
755 _send_linebuf(target_p
, &linebuf
);
758 rb_linebuf_donebuf(&linebuf
);
761 /* sendto_channel_local_with_capability()
763 * inputs - flags to send to, caps, negate caps, channel to send to, va_args
764 * outputs - message to local channel members
768 sendto_channel_local_with_capability(int type
, int caps
, int negcaps
, struct Channel
*chptr
, const char *pattern
, ...)
772 va_start(args
, pattern
);
773 _sendto_channel_local_with_capability_butone(NULL
, type
, caps
, negcaps
, chptr
, pattern
, &args
);
778 /* sendto_channel_local_with_capability()
780 * inputs - flags to send to, caps, negate caps, channel to send to, va_args
781 * outputs - message to local channel members
785 sendto_channel_local_with_capability_butone(struct Client
*one
, int type
, int caps
, int negcaps
, struct Channel
*chptr
,
786 const char *pattern
, ...)
790 va_start(args
, pattern
);
791 _sendto_channel_local_with_capability_butone(one
, type
, caps
, negcaps
, chptr
, pattern
, &args
);
796 /* sendto_channel_local_butone()
798 * inputs - flags to send to, channel to send to, va_args
799 * - user to ignore when sending
800 * outputs - message to local channel members
804 sendto_channel_local_butone(struct Client
*one
, int type
, struct Channel
*chptr
, const char *pattern
, ...)
808 struct membership
*msptr
;
809 struct Client
*target_p
;
810 struct MsgBuf msgbuf
;
812 rb_dlink_node
*next_ptr
;
814 rb_linebuf_newbuf(&linebuf
);
816 build_msgbuf_from(&msgbuf
, one
, NULL
);
818 va_start(args
, pattern
);
819 rb_linebuf_put_vmsg(&linebuf
, pattern
, &args
);
822 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
825 target_p
= msptr
->client_p
;
830 if(IsIOError(target_p
))
833 if(type
&& ((msptr
->flags
& type
) == 0))
836 /* attach the present linebuf to the target */
837 _send_linebuf(target_p
, &linebuf
);
840 rb_linebuf_donebuf(&linebuf
);
844 * sendto_common_channels_local()
846 * inputs - pointer to client
848 * - negated capability mask
851 * side effects - Sends a message to all people on local server who are
852 * in same channel with user.
853 * used by m_nick.c and exit_one_client.
856 sendto_common_channels_local(struct Client
*user
, int cap
, int negcap
, const char *pattern
, ...)
860 rb_dlink_node
*next_ptr
;
862 rb_dlink_node
*next_uptr
;
863 struct Channel
*chptr
;
864 struct Client
*target_p
;
865 struct membership
*msptr
;
866 struct membership
*mscptr
;
869 rb_linebuf_newbuf(&linebuf
);
870 va_start(args
, pattern
);
871 rb_linebuf_put_vmsg(&linebuf
, pattern
, &args
);
876 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
879 chptr
= mscptr
->chptr
;
881 RB_DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
884 target_p
= msptr
->client_p
;
886 if(IsIOError(target_p
) ||
887 target_p
->serial
== current_serial
||
888 !IsCapable(target_p
, cap
) ||
889 !NotCapable(target_p
, negcap
))
892 target_p
->serial
= current_serial
;
893 send_linebuf(target_p
, &linebuf
);
897 /* this can happen when the user isnt in any channels, but we still
898 * need to send them the data, ie a nick change
900 if(MyConnect(user
) && (user
->serial
!= current_serial
)
901 && IsCapable(user
, cap
) && NotCapable(user
, negcap
))
902 send_linebuf(user
, &linebuf
);
904 rb_linebuf_donebuf(&linebuf
);
908 * sendto_common_channels_local_butone()
910 * inputs - pointer to client
912 * - negated capability mask
915 * side effects - Sends a message to all people on local server who are
916 * in same channel with user, except for user itself.
919 sendto_common_channels_local_butone(struct Client
*user
, int cap
, int negcap
, const char *pattern
, ...)
923 rb_dlink_node
*next_ptr
;
925 rb_dlink_node
*next_uptr
;
926 struct Channel
*chptr
;
927 struct Client
*target_p
;
928 struct membership
*msptr
;
929 struct membership
*mscptr
;
932 rb_linebuf_newbuf(&linebuf
);
934 va_start(args
, pattern
);
935 rb_linebuf_put_vmsg(&linebuf
, pattern
, &args
);
939 /* Skip them -- jilles */
940 user
->serial
= current_serial
;
942 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
945 chptr
= mscptr
->chptr
;
947 RB_DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
950 target_p
= msptr
->client_p
;
952 if(IsIOError(target_p
) ||
953 target_p
->serial
== current_serial
||
954 !IsCapable(target_p
, cap
) ||
955 !NotCapable(target_p
, negcap
))
958 target_p
->serial
= current_serial
;
959 send_linebuf(target_p
, &linebuf
);
963 rb_linebuf_donebuf(&linebuf
);
966 /* sendto_match_butone()
968 * inputs - server not to send to, source, mask, type of mask, va_args
970 * side effects - message is sent to matching clients
973 sendto_match_butone(struct Client
*one
, struct Client
*source_p
,
974 const char *mask
, int what
, const char *pattern
, ...)
976 static char buf
[BUFSIZE
];
978 struct Client
*target_p
;
980 rb_dlink_node
*next_ptr
;
981 buf_head_t rb_linebuf_local
;
982 buf_head_t rb_linebuf_remote
;
984 rb_linebuf_newbuf(&rb_linebuf_local
);
985 rb_linebuf_newbuf(&rb_linebuf_remote
);
987 va_start(args
, pattern
);
988 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
991 if(IsServer(source_p
))
992 rb_linebuf_put_msgf(&rb_linebuf_local
,
993 ":%s %s", source_p
->name
, buf
);
995 rb_linebuf_put_msgf(&rb_linebuf_local
,
997 source_p
->name
, source_p
->username
,
998 source_p
->host
, buf
);
1000 rb_linebuf_put_msgf(&rb_linebuf_remote
, ":%s %s", use_id(source_p
), buf
);
1002 if(what
== MATCH_HOST
)
1004 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
1006 target_p
= ptr
->data
;
1008 if(match(mask
, target_p
->host
))
1009 _send_linebuf(target_p
, &rb_linebuf_local
);
1012 /* what = MATCH_SERVER, if it doesnt match us, just send remote */
1013 else if(match(mask
, me
.name
))
1015 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
1017 target_p
= ptr
->data
;
1018 _send_linebuf(target_p
, &rb_linebuf_local
);
1022 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
1024 target_p
= ptr
->data
;
1029 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_remote
);
1032 rb_linebuf_donebuf(&rb_linebuf_local
);
1033 rb_linebuf_donebuf(&rb_linebuf_remote
);
1036 /* sendto_match_servs()
1038 * inputs - source, mask to send to, caps needed, va_args
1040 * side effects - message is sent to matching servers with caps.
1043 sendto_match_servs(struct Client
*source_p
, const char *mask
, int cap
,
1044 int nocap
, const char *pattern
, ...)
1046 static char buf
[BUFSIZE
];
1049 struct Client
*target_p
;
1050 buf_head_t rb_linebuf_id
;
1052 if(EmptyString(mask
))
1055 rb_linebuf_newbuf(&rb_linebuf_id
);
1057 va_start(args
, pattern
);
1058 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1061 rb_linebuf_put_msgf(&rb_linebuf_id
, ":%s %s", use_id(source_p
), buf
);
1065 RB_DLINK_FOREACH(ptr
, global_serv_list
.head
)
1067 target_p
= ptr
->data
;
1069 /* dont send to ourselves, or back to where it came from.. */
1070 if(IsMe(target_p
) || target_p
->from
== source_p
->from
)
1073 if(target_p
->from
->serial
== current_serial
)
1076 if(match(mask
, target_p
->name
))
1078 /* if we set the serial here, then we'll never do
1079 * a match() again if !IsCapable()
1081 target_p
->from
->serial
= current_serial
;
1083 if(cap
&& !IsCapable(target_p
->from
, cap
))
1086 if(nocap
&& !NotCapable(target_p
->from
, nocap
))
1089 _send_linebuf(target_p
->from
, &rb_linebuf_id
);
1093 rb_linebuf_donebuf(&rb_linebuf_id
);
1096 /* sendto_local_clients_with_capability()
1098 * inputs - caps needed, pattern, va_args
1100 * side effects - message is sent to matching local clients with caps.
1103 sendto_local_clients_with_capability(int cap
, const char *pattern
, ...)
1107 struct Client
*target_p
;
1110 rb_linebuf_newbuf(&linebuf
);
1112 va_start(args
, pattern
);
1113 rb_linebuf_put_vmsg(&linebuf
, pattern
, &args
);
1116 RB_DLINK_FOREACH(ptr
, lclient_list
.head
)
1118 target_p
= ptr
->data
;
1120 if(IsIOError(target_p
) || !IsCapable(target_p
, cap
))
1123 send_linebuf(target_p
, &linebuf
);
1126 rb_linebuf_donebuf(&linebuf
);
1131 * inputs - monitor nick to send to, format, va_args
1132 * outputs - message to local users monitoring the given nick
1136 sendto_monitor(struct monitor
*monptr
, const char *pattern
, ...)
1140 struct Client
*target_p
;
1142 rb_dlink_node
*next_ptr
;
1144 rb_linebuf_newbuf(&linebuf
);
1146 va_start(args
, pattern
);
1147 rb_linebuf_put_vmsg(&linebuf
, pattern
, &args
);
1150 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, monptr
->users
.head
)
1152 target_p
= ptr
->data
;
1154 if(IsIOError(target_p
))
1157 _send_linebuf(target_p
, &linebuf
);
1160 rb_linebuf_donebuf(&linebuf
);
1163 /* _sendto_anywhere()
1165 * inputs - real_target, target, source, va_args
1167 * side effects - client is sent message/own message with correct prefix.
1170 _sendto_anywhere(struct Client
*dest_p
, struct Client
*target_p
,
1171 struct Client
*source_p
, const char *command
,
1172 const char *pattern
, va_list *args
)
1176 rb_linebuf_newbuf(&linebuf
);
1178 if(MyClient(dest_p
))
1180 if(IsServer(source_p
))
1181 rb_linebuf_put_vmsg_prefixf(&linebuf
, pattern
, args
, ":%s %s %s ",
1182 source_p
->name
, command
,
1186 struct MsgBuf msgbuf
;
1188 build_msgbuf_from(&msgbuf
, source_p
, command
);
1189 msgbuf
.target
= target_p
->name
;
1191 linebuf_put_tags_vprefix(&msgbuf
, &linebuf
, dest_p
->localClient
->caps
, pattern
, args
);
1195 rb_linebuf_put_vmsg_prefixf(&linebuf
, pattern
, args
, ":%s %s %s ",
1196 get_id(source_p
, target_p
), command
,
1197 get_id(target_p
, target_p
));
1199 if(MyClient(dest_p
))
1200 _send_linebuf(dest_p
, &linebuf
);
1202 send_linebuf_remote(dest_p
, source_p
, &linebuf
);
1204 rb_linebuf_donebuf(&linebuf
);
1207 /* sendto_anywhere()
1209 * inputs - target, source, va_args
1211 * side effects - client is sent message with correct prefix.
1214 sendto_anywhere(struct Client
*target_p
, struct Client
*source_p
,
1215 const char *command
, const char *pattern
, ...)
1219 va_start(args
, pattern
);
1220 _sendto_anywhere(target_p
, target_p
, source_p
, command
, pattern
, &args
);
1224 /* sendto_anywhere_echo()
1226 * inputs - target, source, va_args
1228 * side effects - client is sent own message with correct prefix.
1231 sendto_anywhere_echo(struct Client
*target_p
, struct Client
*source_p
,
1232 const char *command
, const char *pattern
, ...)
1236 s_assert(MyClient(source_p
));
1237 s_assert(!IsServer(source_p
));
1239 va_start(args
, pattern
);
1240 _sendto_anywhere(source_p
, target_p
, source_p
, command
, pattern
, &args
);
1244 /* sendto_realops_snomask()
1246 * inputs - snomask needed, level (opers/admin), va_args
1248 * side effects - message is sent to opers with matching snomasks
1251 sendto_realops_snomask(int flags
, int level
, const char *pattern
, ...)
1253 static char buf
[BUFSIZE
];
1255 struct Client
*client_p
;
1257 rb_dlink_node
*next_ptr
;
1261 rb_linebuf_newbuf(&linebuf
);
1263 /* Be very sure not to do things like "Trying to send to myself"
1264 * L_NETWIDE, otherwise infinite recursion may result! -- jilles */
1265 if (level
& L_NETWIDE
&& ConfigFileEntry
.global_snotices
)
1267 /* rather a lot of copying around, oh well -- jilles */
1268 va_start(args
, pattern
);
1269 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1272 rb_linebuf_put_msgf(&linebuf
,
1273 ":%s NOTICE * :*** Notice -- %s", me
.name
, buf
);
1274 snobuf
= construct_snobuf(flags
);
1275 if (snobuf
[1] != '\0')
1276 sendto_server(NULL
, NULL
, CAP_ENCAP
|CAP_TS6
, NOCAPS
,
1277 ":%s ENCAP * SNOTE %c :%s",
1278 me
.id
, snobuf
[1], buf
);
1280 else if (remote_rehash_oper_p
!= NULL
)
1282 /* rather a lot of copying around, oh well -- jilles */
1283 va_start(args
, pattern
);
1284 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1287 rb_linebuf_put_msgf(&linebuf
,
1288 ":%s NOTICE * :*** Notice -- %s", me
.name
, buf
);
1289 sendto_one_notice(remote_rehash_oper_p
, ":*** Notice -- %s", buf
);
1293 va_start(args
, pattern
);
1294 rb_linebuf_put_vmsg_prefixf(&linebuf
, pattern
, &args
,
1295 ":%s NOTICE * :*** Notice -- ", me
.name
);
1298 level
&= ~L_NETWIDE
;
1300 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1302 client_p
= ptr
->data
;
1304 /* If we're sending it to opers and theyre an admin, skip.
1305 * If we're sending it to admins, and theyre not, skip.
1307 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1308 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1311 if(client_p
->snomask
& flags
)
1312 _send_linebuf(client_p
, &linebuf
);
1315 rb_linebuf_donebuf(&linebuf
);
1317 /* sendto_realops_snomask_from()
1319 * inputs - snomask needed, level (opers/admin), source server, va_args
1321 * side effects - message is sent to opers with matching snomask
1324 sendto_realops_snomask_from(int flags
, int level
, struct Client
*source_p
,
1325 const char *pattern
, ...)
1327 struct Client
*client_p
;
1329 rb_dlink_node
*next_ptr
;
1333 rb_linebuf_newbuf(&linebuf
);
1335 va_start(args
, pattern
);
1336 rb_linebuf_put_vmsg_prefixf(&linebuf
, pattern
, &args
,
1337 ":%s NOTICE * :*** Notice -- ", source_p
->name
);
1340 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1342 client_p
= ptr
->data
;
1344 /* If we're sending it to opers and theyre an admin, skip.
1345 * If we're sending it to admins, and theyre not, skip.
1347 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1348 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1351 if(client_p
->snomask
& flags
)
1352 _send_linebuf(client_p
, &linebuf
);
1355 rb_linebuf_donebuf(&linebuf
);
1359 * sendto_wallops_flags
1361 * inputs - flag types of messages to show to real opers
1362 * - client sending request
1363 * - var args input message
1365 * side effects - Send a wallops to local opers
1368 sendto_wallops_flags(int flags
, struct Client
*source_p
, const char *pattern
, ...)
1370 struct Client
*client_p
;
1372 rb_dlink_node
*next_ptr
;
1376 rb_linebuf_newbuf(&linebuf
);
1378 va_start(args
, pattern
);
1380 if(IsPerson(source_p
))
1381 rb_linebuf_put_vmsg_prefixf(&linebuf
, pattern
, &args
,
1382 ":%s!%s@%s WALLOPS :", source_p
->name
,
1383 source_p
->username
, source_p
->host
);
1385 rb_linebuf_put_vmsg_prefixf(&linebuf
, pattern
, &args
, ":%s WALLOPS :", source_p
->name
);
1389 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, IsPerson(source_p
) && flags
== UMODE_WALLOP
? lclient_list
.head
: local_oper_list
.head
)
1391 client_p
= ptr
->data
;
1393 if(client_p
->umodes
& flags
)
1394 _send_linebuf(client_p
, &linebuf
);
1397 rb_linebuf_donebuf(&linebuf
);
1402 * input - client to send kill to, client to kill, va_args
1404 * side effects - we issue a kill for the client
1407 kill_client(struct Client
*target_p
, struct Client
*diedie
, const char *pattern
, ...)
1412 rb_linebuf_newbuf(&linebuf
);
1414 va_start(args
, pattern
);
1415 rb_linebuf_put_vmsg_prefixf(&linebuf
, pattern
, &args
, ":%s KILL %s :",
1416 get_id(&me
, target_p
), get_id(diedie
, target_p
));
1419 send_linebuf(target_p
, &linebuf
);
1420 rb_linebuf_donebuf(&linebuf
);
1425 * kill_client_serv_butone
1427 * inputs - pointer to client to not send to
1428 * - pointer to client to kill
1430 * side effects - Send a KILL for the given client
1431 * message to all connected servers
1432 * except the client 'one'. Also deal with
1433 * client being unknown to leaf, as in lazylink...
1436 kill_client_serv_butone(struct Client
*one
, struct Client
*target_p
, const char *pattern
, ...)
1438 static char buf
[BUFSIZE
];
1440 struct Client
*client_p
;
1442 rb_dlink_node
*next_ptr
;
1443 buf_head_t rb_linebuf_id
;
1445 rb_linebuf_newbuf(&rb_linebuf_id
);
1447 va_start(args
, pattern
);
1448 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1451 rb_linebuf_put_msgf(&rb_linebuf_id
, ":%s KILL %s :%s",
1452 use_id(&me
), use_id(target_p
), buf
);
1454 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
1456 client_p
= ptr
->data
;
1458 /* ok, if the client we're supposed to not send to has an
1459 * ID, then we still want to issue the kill there..
1461 if(one
!= NULL
&& (client_p
== one
->from
) &&
1462 (!has_id(client_p
) || !has_id(target_p
)))
1465 _send_linebuf(client_p
, &rb_linebuf_id
);
1468 rb_linebuf_donebuf(&rb_linebuf_id
);