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 send_linebuf(user
, &linebuf
);
903 rb_linebuf_donebuf(&linebuf
);
907 * sendto_common_channels_local_butone()
909 * inputs - pointer to client
911 * - negated capability mask
914 * side effects - Sends a message to all people on local server who are
915 * in same channel with user, except for user itself.
918 sendto_common_channels_local_butone(struct Client
*user
, int cap
, int negcap
, const char *pattern
, ...)
922 rb_dlink_node
*next_ptr
;
924 rb_dlink_node
*next_uptr
;
925 struct Channel
*chptr
;
926 struct Client
*target_p
;
927 struct membership
*msptr
;
928 struct membership
*mscptr
;
931 rb_linebuf_newbuf(&linebuf
);
933 va_start(args
, pattern
);
934 rb_linebuf_put_vmsg(&linebuf
, pattern
, &args
);
938 /* Skip them -- jilles */
939 user
->serial
= current_serial
;
941 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
944 chptr
= mscptr
->chptr
;
946 RB_DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
949 target_p
= msptr
->client_p
;
951 if(IsIOError(target_p
) ||
952 target_p
->serial
== current_serial
||
953 !IsCapable(target_p
, cap
) ||
954 !NotCapable(target_p
, negcap
))
957 target_p
->serial
= current_serial
;
958 send_linebuf(target_p
, &linebuf
);
962 rb_linebuf_donebuf(&linebuf
);
965 /* sendto_match_butone()
967 * inputs - server not to send to, source, mask, type of mask, va_args
969 * side effects - message is sent to matching clients
972 sendto_match_butone(struct Client
*one
, struct Client
*source_p
,
973 const char *mask
, int what
, const char *pattern
, ...)
975 static char buf
[BUFSIZE
];
977 struct Client
*target_p
;
979 rb_dlink_node
*next_ptr
;
980 buf_head_t rb_linebuf_local
;
981 buf_head_t rb_linebuf_remote
;
983 rb_linebuf_newbuf(&rb_linebuf_local
);
984 rb_linebuf_newbuf(&rb_linebuf_remote
);
986 va_start(args
, pattern
);
987 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
990 if(IsServer(source_p
))
991 rb_linebuf_put_msgf(&rb_linebuf_local
,
992 ":%s %s", source_p
->name
, buf
);
994 rb_linebuf_put_msgf(&rb_linebuf_local
,
996 source_p
->name
, source_p
->username
,
997 source_p
->host
, buf
);
999 rb_linebuf_put_msgf(&rb_linebuf_remote
, ":%s %s", use_id(source_p
), buf
);
1001 if(what
== MATCH_HOST
)
1003 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
1005 target_p
= ptr
->data
;
1007 if(match(mask
, target_p
->host
))
1008 _send_linebuf(target_p
, &rb_linebuf_local
);
1011 /* what = MATCH_SERVER, if it doesnt match us, just send remote */
1012 else if(match(mask
, me
.name
))
1014 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
1016 target_p
= ptr
->data
;
1017 _send_linebuf(target_p
, &rb_linebuf_local
);
1021 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
1023 target_p
= ptr
->data
;
1028 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_remote
);
1031 rb_linebuf_donebuf(&rb_linebuf_local
);
1032 rb_linebuf_donebuf(&rb_linebuf_remote
);
1035 /* sendto_match_servs()
1037 * inputs - source, mask to send to, caps needed, va_args
1039 * side effects - message is sent to matching servers with caps.
1042 sendto_match_servs(struct Client
*source_p
, const char *mask
, int cap
,
1043 int nocap
, const char *pattern
, ...)
1045 static char buf
[BUFSIZE
];
1048 struct Client
*target_p
;
1049 buf_head_t rb_linebuf_id
;
1051 if(EmptyString(mask
))
1054 rb_linebuf_newbuf(&rb_linebuf_id
);
1056 va_start(args
, pattern
);
1057 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1060 rb_linebuf_put_msgf(&rb_linebuf_id
, ":%s %s", use_id(source_p
), buf
);
1064 RB_DLINK_FOREACH(ptr
, global_serv_list
.head
)
1066 target_p
= ptr
->data
;
1068 /* dont send to ourselves, or back to where it came from.. */
1069 if(IsMe(target_p
) || target_p
->from
== source_p
->from
)
1072 if(target_p
->from
->serial
== current_serial
)
1075 if(match(mask
, target_p
->name
))
1077 /* if we set the serial here, then we'll never do
1078 * a match() again if !IsCapable()
1080 target_p
->from
->serial
= current_serial
;
1082 if(cap
&& !IsCapable(target_p
->from
, cap
))
1085 if(nocap
&& !NotCapable(target_p
->from
, nocap
))
1088 _send_linebuf(target_p
->from
, &rb_linebuf_id
);
1092 rb_linebuf_donebuf(&rb_linebuf_id
);
1095 /* sendto_local_clients_with_capability()
1097 * inputs - caps needed, pattern, va_args
1099 * side effects - message is sent to matching local clients with caps.
1102 sendto_local_clients_with_capability(int cap
, const char *pattern
, ...)
1106 struct Client
*target_p
;
1109 rb_linebuf_newbuf(&linebuf
);
1111 va_start(args
, pattern
);
1112 rb_linebuf_put_vmsg(&linebuf
, pattern
, &args
);
1115 RB_DLINK_FOREACH(ptr
, lclient_list
.head
)
1117 target_p
= ptr
->data
;
1119 if(IsIOError(target_p
) || !IsCapable(target_p
, cap
))
1122 send_linebuf(target_p
, &linebuf
);
1125 rb_linebuf_donebuf(&linebuf
);
1130 * inputs - monitor nick to send to, format, va_args
1131 * outputs - message to local users monitoring the given nick
1135 sendto_monitor(struct monitor
*monptr
, const char *pattern
, ...)
1139 struct Client
*target_p
;
1141 rb_dlink_node
*next_ptr
;
1143 rb_linebuf_newbuf(&linebuf
);
1145 va_start(args
, pattern
);
1146 rb_linebuf_put_vmsg(&linebuf
, pattern
, &args
);
1149 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, monptr
->users
.head
)
1151 target_p
= ptr
->data
;
1153 if(IsIOError(target_p
))
1156 _send_linebuf(target_p
, &linebuf
);
1159 rb_linebuf_donebuf(&linebuf
);
1162 /* _sendto_anywhere()
1164 * inputs - real_target, target, source, va_args
1166 * side effects - client is sent message/own message with correct prefix.
1169 _sendto_anywhere(struct Client
*dest_p
, struct Client
*target_p
,
1170 struct Client
*source_p
, const char *command
,
1171 const char *pattern
, va_list *args
)
1175 rb_linebuf_newbuf(&linebuf
);
1177 if(MyClient(dest_p
))
1179 if(IsServer(source_p
))
1180 rb_linebuf_put_vmsg_prefixf(&linebuf
, pattern
, args
, ":%s %s %s ",
1181 source_p
->name
, command
,
1185 struct MsgBuf msgbuf
;
1187 build_msgbuf_from(&msgbuf
, source_p
, command
);
1188 msgbuf
.target
= target_p
->name
;
1190 linebuf_put_tags_vprefix(&msgbuf
, &linebuf
, dest_p
->localClient
->caps
, pattern
, args
);
1194 rb_linebuf_put_vmsg_prefixf(&linebuf
, pattern
, args
, ":%s %s %s ",
1195 get_id(source_p
, target_p
), command
,
1196 get_id(target_p
, target_p
));
1198 if(MyClient(dest_p
))
1199 _send_linebuf(dest_p
, &linebuf
);
1201 send_linebuf_remote(dest_p
, source_p
, &linebuf
);
1203 rb_linebuf_donebuf(&linebuf
);
1206 /* sendto_anywhere()
1208 * inputs - target, source, va_args
1210 * side effects - client is sent message with correct prefix.
1213 sendto_anywhere(struct Client
*target_p
, struct Client
*source_p
,
1214 const char *command
, const char *pattern
, ...)
1218 va_start(args
, pattern
);
1219 _sendto_anywhere(target_p
, target_p
, source_p
, command
, pattern
, &args
);
1223 /* sendto_anywhere_echo()
1225 * inputs - target, source, va_args
1227 * side effects - client is sent own message with correct prefix.
1230 sendto_anywhere_echo(struct Client
*target_p
, struct Client
*source_p
,
1231 const char *command
, const char *pattern
, ...)
1235 s_assert(MyClient(source_p
));
1236 s_assert(!IsServer(source_p
));
1238 va_start(args
, pattern
);
1239 _sendto_anywhere(source_p
, target_p
, source_p
, command
, pattern
, &args
);
1243 /* sendto_realops_snomask()
1245 * inputs - snomask needed, level (opers/admin), va_args
1247 * side effects - message is sent to opers with matching snomasks
1250 sendto_realops_snomask(int flags
, int level
, const char *pattern
, ...)
1252 static char buf
[BUFSIZE
];
1254 struct Client
*client_p
;
1256 rb_dlink_node
*next_ptr
;
1260 rb_linebuf_newbuf(&linebuf
);
1262 /* Be very sure not to do things like "Trying to send to myself"
1263 * L_NETWIDE, otherwise infinite recursion may result! -- jilles */
1264 if (level
& L_NETWIDE
&& ConfigFileEntry
.global_snotices
)
1266 /* rather a lot of copying around, oh well -- jilles */
1267 va_start(args
, pattern
);
1268 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1271 rb_linebuf_put_msgf(&linebuf
,
1272 ":%s NOTICE * :*** Notice -- %s", me
.name
, buf
);
1273 snobuf
= construct_snobuf(flags
);
1274 if (snobuf
[1] != '\0')
1275 sendto_server(NULL
, NULL
, CAP_ENCAP
|CAP_TS6
, NOCAPS
,
1276 ":%s ENCAP * SNOTE %c :%s",
1277 me
.id
, snobuf
[1], buf
);
1279 else if (remote_rehash_oper_p
!= NULL
)
1281 /* rather a lot of copying around, oh well -- jilles */
1282 va_start(args
, pattern
);
1283 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1286 rb_linebuf_put_msgf(&linebuf
,
1287 ":%s NOTICE * :*** Notice -- %s", me
.name
, buf
);
1288 sendto_one_notice(remote_rehash_oper_p
, ":*** Notice -- %s", buf
);
1292 va_start(args
, pattern
);
1293 rb_linebuf_put_vmsg_prefixf(&linebuf
, pattern
, &args
,
1294 ":%s NOTICE * :*** Notice -- ", me
.name
);
1297 level
&= ~L_NETWIDE
;
1299 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1301 client_p
= ptr
->data
;
1303 /* If we're sending it to opers and theyre an admin, skip.
1304 * If we're sending it to admins, and theyre not, skip.
1306 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1307 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1310 if(client_p
->snomask
& flags
)
1311 _send_linebuf(client_p
, &linebuf
);
1314 rb_linebuf_donebuf(&linebuf
);
1316 /* sendto_realops_snomask_from()
1318 * inputs - snomask needed, level (opers/admin), source server, va_args
1320 * side effects - message is sent to opers with matching snomask
1323 sendto_realops_snomask_from(int flags
, int level
, struct Client
*source_p
,
1324 const char *pattern
, ...)
1326 struct Client
*client_p
;
1328 rb_dlink_node
*next_ptr
;
1332 rb_linebuf_newbuf(&linebuf
);
1334 va_start(args
, pattern
);
1335 rb_linebuf_put_vmsg_prefixf(&linebuf
, pattern
, &args
,
1336 ":%s NOTICE * :*** Notice -- ", source_p
->name
);
1339 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1341 client_p
= ptr
->data
;
1343 /* If we're sending it to opers and theyre an admin, skip.
1344 * If we're sending it to admins, and theyre not, skip.
1346 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1347 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1350 if(client_p
->snomask
& flags
)
1351 _send_linebuf(client_p
, &linebuf
);
1354 rb_linebuf_donebuf(&linebuf
);
1358 * sendto_wallops_flags
1360 * inputs - flag types of messages to show to real opers
1361 * - client sending request
1362 * - var args input message
1364 * side effects - Send a wallops to local opers
1367 sendto_wallops_flags(int flags
, struct Client
*source_p
, const char *pattern
, ...)
1369 struct Client
*client_p
;
1371 rb_dlink_node
*next_ptr
;
1375 rb_linebuf_newbuf(&linebuf
);
1377 va_start(args
, pattern
);
1379 if(IsPerson(source_p
))
1380 rb_linebuf_put_vmsg_prefixf(&linebuf
, pattern
, &args
,
1381 ":%s!%s@%s WALLOPS :", source_p
->name
,
1382 source_p
->username
, source_p
->host
);
1384 rb_linebuf_put_vmsg_prefixf(&linebuf
, pattern
, &args
, ":%s WALLOPS :", source_p
->name
);
1388 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, IsPerson(source_p
) && flags
== UMODE_WALLOP
? lclient_list
.head
: local_oper_list
.head
)
1390 client_p
= ptr
->data
;
1392 if(client_p
->umodes
& flags
)
1393 _send_linebuf(client_p
, &linebuf
);
1396 rb_linebuf_donebuf(&linebuf
);
1401 * input - client to send kill to, client to kill, va_args
1403 * side effects - we issue a kill for the client
1406 kill_client(struct Client
*target_p
, struct Client
*diedie
, const char *pattern
, ...)
1411 rb_linebuf_newbuf(&linebuf
);
1413 va_start(args
, pattern
);
1414 rb_linebuf_put_vmsg_prefixf(&linebuf
, pattern
, &args
, ":%s KILL %s :",
1415 get_id(&me
, target_p
), get_id(diedie
, target_p
));
1418 send_linebuf(target_p
, &linebuf
);
1419 rb_linebuf_donebuf(&linebuf
);
1424 * kill_client_serv_butone
1426 * inputs - pointer to client to not send to
1427 * - pointer to client to kill
1429 * side effects - Send a KILL for the given client
1430 * message to all connected servers
1431 * except the client 'one'. Also deal with
1432 * client being unknown to leaf, as in lazylink...
1435 kill_client_serv_butone(struct Client
*one
, struct Client
*target_p
, const char *pattern
, ...)
1437 static char buf
[BUFSIZE
];
1439 struct Client
*client_p
;
1441 rb_dlink_node
*next_ptr
;
1442 buf_head_t rb_linebuf_id
;
1444 rb_linebuf_newbuf(&rb_linebuf_id
);
1446 va_start(args
, pattern
);
1447 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1450 rb_linebuf_put_msgf(&rb_linebuf_id
, ":%s KILL %s :%s",
1451 use_id(&me
), use_id(target_p
), buf
);
1453 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
1455 client_p
= ptr
->data
;
1457 /* ok, if the client we're supposed to not send to has an
1458 * ID, then we still want to issue the kill there..
1460 if(one
!= NULL
&& (client_p
== one
->from
) &&
1461 (!has_id(client_p
) || !has_id(target_p
)))
1464 _send_linebuf(client_p
, &rb_linebuf_id
);
1467 rb_linebuf_donebuf(&rb_linebuf_id
);