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
35 #include "s_newconf.h"
41 /* send the message to the link the target is attached to */
42 #define send_linebuf(a,b) _send_linebuf((a->from ? a->from : a) ,b)
44 static void send_queued_write(rb_fde_t
*F
, void *data
);
46 unsigned long current_serial
= 0L;
48 struct Client
*remote_rehash_oper_p
;
52 * inputs - client to send to, linebuf to attach
54 * side effects - linebuf is attached to client
57 _send_linebuf(struct Client
*to
, buf_head_t
*linebuf
)
61 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send message to myself!");
65 if(!MyConnect(to
) || IsIOError(to
))
68 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > get_sendq(to
))
72 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
73 "Max SendQ limit exceeded for %s: %u > %lu",
75 rb_linebuf_len(&to
->localClient
->buf_sendq
),
78 ilog(L_SERVER
, "Max SendQ limit exceeded for %s: %u > %lu",
79 log_client_name(to
, SHOW_IP
),
80 rb_linebuf_len(&to
->localClient
->buf_sendq
),
89 /* just attach the linebuf to the sendq instead of
90 * generating a new one
92 rb_linebuf_attach(&to
->localClient
->buf_sendq
, linebuf
);
96 ** Update statistics. The following is slightly incorrect
97 ** because it counts messages even if queued, but bytes
98 ** only really sent. Queued bytes get updated in SendQueued.
100 to
->localClient
->sendM
+= 1;
101 me
.localClient
->sendM
+= 1;
102 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > 0)
107 /* send_linebuf_remote()
109 * inputs - client to attach to, sender, linebuf
111 * side effects - client has linebuf attached
114 send_linebuf_remote(struct Client
*to
, struct Client
*from
, buf_head_t
*linebuf
)
119 /* we assume the caller has already tested for fake direction */
120 _send_linebuf(to
, linebuf
);
123 /* send_queued_write()
125 * inputs - fd to have queue sent, client we're sending to
126 * outputs - contents of queue
127 * side effects - write is rescheduled if queue isnt emptied
130 send_queued(struct Client
*to
)
134 rb_fde_t
*F
= to
->localClient
->F
;
138 /* cant write anything to a dead socket. */
142 /* try to flush later when the write event resets this */
146 if(rb_linebuf_len(&to
->localClient
->buf_sendq
))
149 rb_linebuf_flush(F
, &to
->localClient
->buf_sendq
)) > 0)
151 /* We have some data written .. update counters */
154 to
->localClient
->sendB
+= retlen
;
155 me
.localClient
->sendB
+= retlen
;
156 if(to
->localClient
->sendB
> 1023)
158 to
->localClient
->sendK
+= (to
->localClient
->sendB
>> 10);
159 to
->localClient
->sendB
&= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */
161 else if(me
.localClient
->sendB
> 1023)
163 me
.localClient
->sendK
+= (me
.localClient
->sendB
>> 10);
164 me
.localClient
->sendB
&= 0x03ff;
168 if(retlen
== 0 || (retlen
< 0 && !rb_ignore_errno(errno
)))
175 if(rb_linebuf_len(&to
->localClient
->buf_sendq
))
178 rb_setselect(to
->localClient
->F
, RB_SELECT_WRITE
,
179 send_queued_write
, to
);
186 send_pop_queue(struct Client
*to
)
190 if(!MyConnect(to
) || IsIOError(to
))
192 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > 0)
196 /* send_queued_write()
198 * inputs - fd to have queue sent, client we're sending to
199 * outputs - contents of queue
200 * side effects - write is scheduled if queue isnt emptied
203 send_queued_write(rb_fde_t
*F
, void *data
)
205 struct Client
*to
= data
;
211 * linebuf_put_msgvbuf
213 * inputs - msgbuf header, linebuf object, capability mask, pattern, arguments
215 * side effects - the linebuf object is cleared, then populated using rb_linebuf_putmsg().
218 linebuf_put_msgvbuf(struct MsgBuf
*msgbuf
, buf_head_t
*linebuf
, unsigned int capmask
, const char *pattern
, va_list *va
)
222 rb_linebuf_newbuf(linebuf
);
223 msgbuf_unparse_prefix(buf
, sizeof buf
, msgbuf
, capmask
);
224 rb_linebuf_putprefix(linebuf
, pattern
, va
, buf
);
227 /* linebuf_put_msgbuf
229 * inputs - msgbuf header, linebuf object, capability mask, pattern, arguments
231 * side effects - the linebuf object is cleared, then populated using rb_linebuf_putmsg().
234 linebuf_put_msgbuf(struct MsgBuf
*msgbuf
, buf_head_t
*linebuf
, unsigned int capmask
, const char *pattern
, ...)
238 va_start(va
, pattern
);
239 linebuf_put_msgvbuf(msgbuf
, linebuf
, capmask
, pattern
, &va
);
245 * inputs - msgbuf object, client the message is from
247 * side effects - a msgbuf object is populated with an origin and relevant tags
248 * notes - to make this reentrant, find a solution for `buf` below
251 build_msgbuf_from(struct MsgBuf
*msgbuf
, struct Client
*from
, const char *cmd
)
253 static char buf
[BUFSIZE
];
258 msgbuf
->origin
= buf
;
261 if (from
!= NULL
&& IsPerson(from
))
262 snprintf(buf
, sizeof buf
, "%s!%s@%s", from
->name
, from
->username
, from
->host
);
263 else if (from
!= NULL
)
264 rb_strlcpy(buf
, from
->name
, sizeof buf
);
266 rb_strlcpy(buf
, me
.name
, sizeof buf
);
271 call_hook(h_outbound_msgbuf
, &hdata
);
276 * inputs - client to send to, va_args
277 * outputs - client has message put into its queue
281 sendto_one(struct Client
*target_p
, const char *pattern
, ...)
286 /* send remote if to->from non NULL */
287 if(target_p
->from
!= NULL
)
288 target_p
= target_p
->from
;
290 if(IsIOError(target_p
))
293 rb_linebuf_newbuf(&linebuf
);
295 va_start(args
, pattern
);
296 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
299 _send_linebuf(target_p
, &linebuf
);
301 rb_linebuf_donebuf(&linebuf
);
304 /* sendto_one_prefix()
306 * inputs - client to send to, va_args
307 * outputs - client has message put into its queue
308 * side effects - source(us)/target is chosen based on TS6 capability
311 sendto_one_prefix(struct Client
*target_p
, struct Client
*source_p
,
312 const char *command
, const char *pattern
, ...)
314 struct Client
*dest_p
;
318 /* send remote if to->from non NULL */
319 if(target_p
->from
!= NULL
)
320 dest_p
= target_p
->from
;
324 if(IsIOError(dest_p
))
329 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
333 rb_linebuf_newbuf(&linebuf
);
334 va_start(args
, pattern
);
335 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
337 get_id(source_p
, target_p
),
338 command
, get_id(target_p
, target_p
));
341 _send_linebuf(dest_p
, &linebuf
);
342 rb_linebuf_donebuf(&linebuf
);
345 /* sendto_one_notice()
347 * inputs - client to send to, va_args
348 * outputs - client has a NOTICE put into its queue
349 * side effects - source(us)/target is chosen based on TS6 capability
352 sendto_one_notice(struct Client
*target_p
, const char *pattern
, ...)
354 struct Client
*dest_p
;
359 /* send remote if to->from non NULL */
360 if(target_p
->from
!= NULL
)
361 dest_p
= target_p
->from
;
365 if(IsIOError(dest_p
))
370 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
374 rb_linebuf_newbuf(&linebuf
);
375 va_start(args
, pattern
);
376 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
378 get_id(&me
, target_p
), *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
381 _send_linebuf(dest_p
, &linebuf
);
382 rb_linebuf_donebuf(&linebuf
);
386 /* sendto_one_numeric()
388 * inputs - client to send to, va_args
389 * outputs - client has message put into its queue
390 * side effects - source/target is chosen based on TS6 capability
393 sendto_one_numeric(struct Client
*target_p
, int numeric
, const char *pattern
, ...)
395 struct Client
*dest_p
;
400 /* send remote if to->from non NULL */
401 if(target_p
->from
!= NULL
)
402 dest_p
= target_p
->from
;
406 if(IsIOError(dest_p
))
411 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
415 rb_linebuf_newbuf(&linebuf
);
416 va_start(args
, pattern
);
417 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
419 get_id(&me
, target_p
),
420 numeric
, *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
423 _send_linebuf(dest_p
, &linebuf
);
424 rb_linebuf_donebuf(&linebuf
);
430 * inputs - pointer to client to NOT send to
431 * - caps or'd together which must ALL be present
432 * - caps or'd together which must ALL NOT be present
433 * - printf style format string
434 * - args to format string
436 * side effects - Send a message to all connected servers, except the
437 * client 'one' (if non-NULL), as long as the servers
438 * support ALL capabs in 'caps', and NO capabs in 'nocaps'.
440 * This function was written in an attempt to merge together the other
441 * billion sendto_*serv*() functions, which sprung up with capabs, uids etc
445 sendto_server(struct Client
*one
, struct Channel
*chptr
, unsigned long caps
,
446 unsigned long nocaps
, const char *format
, ...)
449 struct Client
*target_p
;
451 rb_dlink_node
*next_ptr
;
454 /* noone to send to.. */
455 if(rb_dlink_list_length(&serv_list
) == 0)
458 if(chptr
!= NULL
&& *chptr
->chname
!= '#')
461 rb_linebuf_newbuf(&linebuf
);
462 va_start(args
, format
);
463 rb_linebuf_putmsg(&linebuf
, format
, &args
, NULL
);
466 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
468 target_p
= ptr
->data
;
470 /* check against 'one' */
471 if(one
!= NULL
&& (target_p
== one
->from
))
474 /* check we have required capabs */
475 if(!IsCapable(target_p
, caps
))
478 /* check we don't have any forbidden capabs */
479 if(!NotCapable(target_p
, nocaps
))
482 _send_linebuf(target_p
, &linebuf
);
485 rb_linebuf_donebuf(&linebuf
);
489 /* sendto_channel_flags()
491 * inputs - server not to send to, flags needed, source, channel, va_args
492 * outputs - message is sent to channel members
496 sendto_channel_flags(struct Client
*one
, int type
, struct Client
*source_p
,
497 struct Channel
*chptr
, const char *pattern
, ...)
501 buf_head_t rb_linebuf_local
;
502 buf_head_t rb_linebuf_id
;
503 struct Client
*target_p
;
504 struct membership
*msptr
;
506 rb_dlink_node
*next_ptr
;
507 int current_capmask
= 0;
508 struct MsgBuf msgbuf
;
510 rb_linebuf_newbuf(&rb_linebuf_local
);
511 rb_linebuf_newbuf(&rb_linebuf_id
);
515 build_msgbuf_from(&msgbuf
, source_p
, NULL
);
517 va_start(args
, pattern
);
518 vsnprintf(buf
, sizeof buf
, pattern
, args
);
521 linebuf_put_msgbuf(&msgbuf
, &rb_linebuf_local
, NOCAPS
, "%s", buf
);
522 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
524 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->members
.head
)
527 target_p
= msptr
->client_p
;
529 if(!MyClient(source_p
) && (IsIOError(target_p
->from
) || target_p
->from
== one
))
532 if(MyClient(source_p
) && !IsCapable(source_p
, CLICAP_ECHO_MESSAGE
) && target_p
== one
)
535 if(type
&& ((msptr
->flags
& type
) == 0))
541 if(!MyClient(target_p
))
543 /* if we've got a specific type, target must support
546 if(type
&& NotCapable(target_p
->from
, CAP_CHW
))
549 if(target_p
->from
->serial
!= current_serial
)
551 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_id
);
552 target_p
->from
->serial
= current_serial
;
557 if (target_p
->localClient
->caps
!= current_capmask
)
559 /* reset the linebuf */
560 rb_linebuf_donebuf(&rb_linebuf_local
);
561 rb_linebuf_newbuf(&rb_linebuf_local
);
563 /* render the new linebuf and attach it */
564 linebuf_put_msgbuf(&msgbuf
, &rb_linebuf_local
, target_p
->localClient
->caps
, "%s", buf
);
565 current_capmask
= target_p
->localClient
->caps
;
568 _send_linebuf(target_p
, &rb_linebuf_local
);
572 rb_linebuf_donebuf(&rb_linebuf_local
);
573 rb_linebuf_donebuf(&rb_linebuf_id
);
576 /* sendto_channel_flags()
578 * inputs - server not to send to, flags needed, source, channel, va_args
579 * outputs - message is sent to channel members
583 sendto_channel_opmod(struct Client
*one
, struct Client
*source_p
,
584 struct Channel
*chptr
, const char *command
,
587 buf_head_t rb_linebuf_local
;
588 buf_head_t rb_linebuf_old
;
589 buf_head_t rb_linebuf_new
;
590 struct Client
*target_p
;
591 struct membership
*msptr
;
593 rb_dlink_node
*next_ptr
;
595 rb_linebuf_newbuf(&rb_linebuf_local
);
596 rb_linebuf_newbuf(&rb_linebuf_old
);
597 rb_linebuf_newbuf(&rb_linebuf_new
);
601 if(IsServer(source_p
))
602 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
604 source_p
->name
, command
, chptr
->chname
, text
);
606 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
607 ":%s!%s@%s %s %s :%s",
608 source_p
->name
, source_p
->username
,
609 source_p
->host
, command
, chptr
->chname
, text
);
611 if (chptr
->mode
.mode
& MODE_MODERATED
)
612 rb_linebuf_putmsg(&rb_linebuf_old
, NULL
, NULL
,
614 use_id(source_p
), command
, chptr
->chname
, text
);
616 rb_linebuf_putmsg(&rb_linebuf_old
, NULL
, NULL
,
617 ":%s NOTICE @%s :<%s:%s> %s",
618 use_id(source_p
->servptr
), chptr
->chname
,
619 source_p
->name
, chptr
->chname
, text
);
620 rb_linebuf_putmsg(&rb_linebuf_new
, NULL
, NULL
,
622 use_id(source_p
), command
, chptr
->chname
, text
);
624 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->members
.head
)
627 target_p
= msptr
->client_p
;
629 if(!MyClient(source_p
) && (IsIOError(target_p
->from
) || target_p
->from
== one
))
632 if(MyClient(source_p
) && !IsCapable(source_p
, CLICAP_ECHO_MESSAGE
) && target_p
== one
)
635 if((msptr
->flags
& CHFL_CHANOP
) == 0)
641 if(!MyClient(target_p
))
643 /* if we've got a specific type, target must support
646 if(NotCapable(target_p
->from
, CAP_CHW
))
649 if(target_p
->from
->serial
!= current_serial
)
651 if (IsCapable(target_p
->from
, CAP_EOPMOD
))
652 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_new
);
654 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_old
);
655 target_p
->from
->serial
= current_serial
;
659 _send_linebuf(target_p
, &rb_linebuf_local
);
662 rb_linebuf_donebuf(&rb_linebuf_local
);
663 rb_linebuf_donebuf(&rb_linebuf_old
);
664 rb_linebuf_donebuf(&rb_linebuf_new
);
667 /* sendto_channel_local()
669 * inputs - flags to send to, channel to send to, va_args
670 * outputs - message to local channel members
674 sendto_channel_local(int type
, struct Channel
*chptr
, const char *pattern
, ...)
678 struct membership
*msptr
;
679 struct Client
*target_p
;
681 rb_dlink_node
*next_ptr
;
683 rb_linebuf_newbuf(&linebuf
);
685 va_start(args
, pattern
);
686 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
689 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
692 target_p
= msptr
->client_p
;
694 if(IsIOError(target_p
))
697 if(type
== ONLY_OPERS
)
699 if (!IsOper(target_p
))
702 else if(type
&& ((msptr
->flags
& type
) == 0))
705 _send_linebuf(target_p
, &linebuf
);
708 rb_linebuf_donebuf(&linebuf
);
712 * _sendto_channel_local_with_capability_butone()
714 * Shared implementation of sendto_channel_local_with_capability and sendto_channel_local_with_capability_butone
717 _sendto_channel_local_with_capability_butone(struct Client
*one
, int type
, int caps
, int negcaps
, struct Channel
*chptr
,
718 const char *pattern
, va_list * args
)
721 struct membership
*msptr
;
722 struct Client
*target_p
;
724 rb_dlink_node
*next_ptr
;
726 rb_linebuf_newbuf(&linebuf
);
727 rb_linebuf_putmsg(&linebuf
, pattern
, args
, NULL
);
729 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
732 target_p
= msptr
->client_p
;
737 if(IsIOError(target_p
) ||
738 !IsCapable(target_p
, caps
) ||
739 !NotCapable(target_p
, negcaps
))
742 if(type
&& ((msptr
->flags
& type
) == 0))
745 _send_linebuf(target_p
, &linebuf
);
748 rb_linebuf_donebuf(&linebuf
);
751 /* sendto_channel_local_with_capability()
753 * inputs - flags to send to, caps, negate caps, channel to send to, va_args
754 * outputs - message to local channel members
758 sendto_channel_local_with_capability(int type
, int caps
, int negcaps
, struct Channel
*chptr
, const char *pattern
, ...)
762 va_start(args
, pattern
);
763 _sendto_channel_local_with_capability_butone(NULL
, type
, caps
, negcaps
, chptr
, pattern
, &args
);
768 /* sendto_channel_local_with_capability()
770 * inputs - flags to send to, caps, negate caps, channel to send to, va_args
771 * outputs - message to local channel members
775 sendto_channel_local_with_capability_butone(struct Client
*one
, int type
, int caps
, int negcaps
, struct Channel
*chptr
,
776 const char *pattern
, ...)
780 va_start(args
, pattern
);
781 _sendto_channel_local_with_capability_butone(one
, type
, caps
, negcaps
, chptr
, pattern
, &args
);
786 /* sendto_channel_local_butone()
788 * inputs - flags to send to, channel to send to, va_args
789 * - user to ignore when sending
790 * outputs - message to local channel members
794 sendto_channel_local_butone(struct Client
*one
, int type
, struct Channel
*chptr
, const char *pattern
, ...)
798 struct membership
*msptr
;
799 struct Client
*target_p
;
800 struct MsgBuf msgbuf
;
802 rb_dlink_node
*next_ptr
;
804 rb_linebuf_newbuf(&linebuf
);
806 build_msgbuf_from(&msgbuf
, one
, NULL
);
808 va_start(args
, pattern
);
809 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
812 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
815 target_p
= msptr
->client_p
;
820 if(IsIOError(target_p
))
823 if(type
&& ((msptr
->flags
& type
) == 0))
826 /* attach the present linebuf to the target */
827 _send_linebuf(target_p
, &linebuf
);
830 rb_linebuf_donebuf(&linebuf
);
834 * sendto_common_channels_local()
836 * inputs - pointer to client
838 * - negated capability mask
841 * side effects - Sends a message to all people on local server who are
842 * in same channel with user.
843 * used by m_nick.c and exit_one_client.
846 sendto_common_channels_local(struct Client
*user
, int cap
, int negcap
, const char *pattern
, ...)
850 rb_dlink_node
*next_ptr
;
852 rb_dlink_node
*next_uptr
;
853 struct Channel
*chptr
;
854 struct Client
*target_p
;
855 struct membership
*msptr
;
856 struct membership
*mscptr
;
859 rb_linebuf_newbuf(&linebuf
);
860 va_start(args
, pattern
);
861 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
866 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
869 chptr
= mscptr
->chptr
;
871 RB_DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
874 target_p
= msptr
->client_p
;
876 if(IsIOError(target_p
) ||
877 target_p
->serial
== current_serial
||
878 !IsCapable(target_p
, cap
) ||
879 !NotCapable(target_p
, negcap
))
882 target_p
->serial
= current_serial
;
883 send_linebuf(target_p
, &linebuf
);
887 /* this can happen when the user isnt in any channels, but we still
888 * need to send them the data, ie a nick change
890 if(MyConnect(user
) && (user
->serial
!= current_serial
))
891 send_linebuf(user
, &linebuf
);
893 rb_linebuf_donebuf(&linebuf
);
897 * sendto_common_channels_local_butone()
899 * inputs - pointer to client
901 * - negated capability mask
904 * side effects - Sends a message to all people on local server who are
905 * in same channel with user, except for user itself.
908 sendto_common_channels_local_butone(struct Client
*user
, int cap
, int negcap
, const char *pattern
, ...)
912 rb_dlink_node
*next_ptr
;
914 rb_dlink_node
*next_uptr
;
915 struct Channel
*chptr
;
916 struct Client
*target_p
;
917 struct membership
*msptr
;
918 struct membership
*mscptr
;
921 rb_linebuf_newbuf(&linebuf
);
923 va_start(args
, pattern
);
924 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
928 /* Skip them -- jilles */
929 user
->serial
= current_serial
;
931 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
934 chptr
= mscptr
->chptr
;
936 RB_DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
939 target_p
= msptr
->client_p
;
941 if(IsIOError(target_p
) ||
942 target_p
->serial
== current_serial
||
943 !IsCapable(target_p
, cap
) ||
944 !NotCapable(target_p
, negcap
))
947 target_p
->serial
= current_serial
;
948 send_linebuf(target_p
, &linebuf
);
952 rb_linebuf_donebuf(&linebuf
);
955 /* sendto_match_butone()
957 * inputs - server not to send to, source, mask, type of mask, va_args
959 * side effects - message is sent to matching clients
962 sendto_match_butone(struct Client
*one
, struct Client
*source_p
,
963 const char *mask
, int what
, const char *pattern
, ...)
965 static char buf
[BUFSIZE
];
967 struct Client
*target_p
;
969 rb_dlink_node
*next_ptr
;
970 buf_head_t rb_linebuf_local
;
971 buf_head_t rb_linebuf_id
;
973 rb_linebuf_newbuf(&rb_linebuf_local
);
974 rb_linebuf_newbuf(&rb_linebuf_id
);
976 va_start(args
, pattern
);
977 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
980 if(IsServer(source_p
))
981 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
982 ":%s %s", source_p
->name
, buf
);
984 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
986 source_p
->name
, source_p
->username
,
987 source_p
->host
, buf
);
989 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
991 if(what
== MATCH_HOST
)
993 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
995 target_p
= ptr
->data
;
997 if(match(mask
, target_p
->host
))
998 _send_linebuf(target_p
, &rb_linebuf_local
);
1001 /* what = MATCH_SERVER, if it doesnt match us, just send remote */
1002 else if(match(mask
, me
.name
))
1004 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
1006 target_p
= ptr
->data
;
1007 _send_linebuf(target_p
, &rb_linebuf_local
);
1011 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
1013 target_p
= ptr
->data
;
1018 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_id
);
1021 rb_linebuf_donebuf(&rb_linebuf_local
);
1022 rb_linebuf_donebuf(&rb_linebuf_id
);
1025 /* sendto_match_servs()
1027 * inputs - source, mask to send to, caps needed, va_args
1029 * side effects - message is sent to matching servers with caps.
1032 sendto_match_servs(struct Client
*source_p
, const char *mask
, int cap
,
1033 int nocap
, const char *pattern
, ...)
1035 static char buf
[BUFSIZE
];
1038 struct Client
*target_p
;
1039 buf_head_t rb_linebuf_id
;
1041 if(EmptyString(mask
))
1044 rb_linebuf_newbuf(&rb_linebuf_id
);
1046 va_start(args
, pattern
);
1047 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1050 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
,
1051 ":%s %s", use_id(source_p
), buf
);
1055 RB_DLINK_FOREACH(ptr
, global_serv_list
.head
)
1057 target_p
= ptr
->data
;
1059 /* dont send to ourselves, or back to where it came from.. */
1060 if(IsMe(target_p
) || target_p
->from
== source_p
->from
)
1063 if(target_p
->from
->serial
== current_serial
)
1066 if(match(mask
, target_p
->name
))
1068 /* if we set the serial here, then we'll never do
1069 * a match() again if !IsCapable()
1071 target_p
->from
->serial
= current_serial
;
1073 if(cap
&& !IsCapable(target_p
->from
, cap
))
1076 if(nocap
&& !NotCapable(target_p
->from
, nocap
))
1079 _send_linebuf(target_p
->from
, &rb_linebuf_id
);
1083 rb_linebuf_donebuf(&rb_linebuf_id
);
1086 /* sendto_local_clients_with_capability()
1088 * inputs - caps needed, pattern, va_args
1090 * side effects - message is sent to matching local clients with caps.
1093 sendto_local_clients_with_capability(int cap
, const char *pattern
, ...)
1097 struct Client
*target_p
;
1100 rb_linebuf_newbuf(&linebuf
);
1102 va_start(args
, pattern
);
1103 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
1106 RB_DLINK_FOREACH(ptr
, lclient_list
.head
)
1108 target_p
= ptr
->data
;
1110 if(IsIOError(target_p
) || !IsCapable(target_p
, cap
))
1113 send_linebuf(target_p
, &linebuf
);
1116 rb_linebuf_donebuf(&linebuf
);
1121 * inputs - monitor nick to send to, format, va_args
1122 * outputs - message to local users monitoring the given nick
1126 sendto_monitor(struct monitor
*monptr
, const char *pattern
, ...)
1130 struct Client
*target_p
;
1132 rb_dlink_node
*next_ptr
;
1134 rb_linebuf_newbuf(&linebuf
);
1136 va_start(args
, pattern
);
1137 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
1140 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, monptr
->users
.head
)
1142 target_p
= ptr
->data
;
1144 if(IsIOError(target_p
))
1147 _send_linebuf(target_p
, &linebuf
);
1150 rb_linebuf_donebuf(&linebuf
);
1153 /* sendto_anywhere()
1155 * inputs - target, source, va_args
1157 * side effects - client is sent message with correct prefix.
1160 sendto_anywhere(struct Client
*target_p
, struct Client
*source_p
,
1161 const char *command
, const char *pattern
, ...)
1166 rb_linebuf_newbuf(&linebuf
);
1168 va_start(args
, pattern
);
1170 if(MyClient(target_p
))
1172 if(IsServer(source_p
))
1173 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
1174 source_p
->name
, command
,
1178 struct MsgBuf msgbuf
;
1180 build_msgbuf_from(&msgbuf
, source_p
, command
);
1181 msgbuf
.target
= target_p
->name
;
1183 linebuf_put_msgvbuf(&msgbuf
, &linebuf
, target_p
->localClient
->caps
, pattern
, &args
);
1187 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
1188 get_id(source_p
, target_p
), command
,
1189 get_id(target_p
, target_p
));
1192 if(MyClient(target_p
))
1193 _send_linebuf(target_p
, &linebuf
);
1195 send_linebuf_remote(target_p
, source_p
, &linebuf
);
1197 rb_linebuf_donebuf(&linebuf
);
1200 /* sendto_realops_snomask()
1202 * inputs - snomask needed, level (opers/admin), va_args
1204 * side effects - message is sent to opers with matching snomasks
1207 sendto_realops_snomask(int flags
, int level
, const char *pattern
, ...)
1209 static char buf
[BUFSIZE
];
1211 struct Client
*client_p
;
1213 rb_dlink_node
*next_ptr
;
1217 rb_linebuf_newbuf(&linebuf
);
1219 /* Be very sure not to do things like "Trying to send to myself"
1220 * L_NETWIDE, otherwise infinite recursion may result! -- jilles */
1221 if (level
& L_NETWIDE
&& ConfigFileEntry
.global_snotices
)
1223 /* rather a lot of copying around, oh well -- jilles */
1224 va_start(args
, pattern
);
1225 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1227 rb_linebuf_putmsg(&linebuf
, pattern
, NULL
,
1228 ":%s NOTICE * :*** Notice -- %s", me
.name
, buf
);
1229 snobuf
= construct_snobuf(flags
);
1230 if (snobuf
[1] != '\0')
1231 sendto_server(NULL
, NULL
, CAP_ENCAP
|CAP_TS6
, NOCAPS
,
1232 ":%s ENCAP * SNOTE %c :%s",
1233 me
.id
, snobuf
[1], buf
);
1235 else if (remote_rehash_oper_p
!= NULL
)
1237 /* rather a lot of copying around, oh well -- jilles */
1238 va_start(args
, pattern
);
1239 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1241 rb_linebuf_putmsg(&linebuf
, pattern
, NULL
,
1242 ":%s NOTICE * :*** Notice -- %s", me
.name
, buf
);
1243 sendto_one_notice(remote_rehash_oper_p
, ":*** Notice -- %s", buf
);
1247 va_start(args
, pattern
);
1248 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1249 ":%s NOTICE * :*** Notice -- ", me
.name
);
1252 level
&= ~L_NETWIDE
;
1254 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1256 client_p
= ptr
->data
;
1258 /* If we're sending it to opers and theyre an admin, skip.
1259 * If we're sending it to admins, and theyre not, skip.
1261 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1262 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1265 if(client_p
->snomask
& flags
)
1266 _send_linebuf(client_p
, &linebuf
);
1269 rb_linebuf_donebuf(&linebuf
);
1271 /* sendto_realops_snomask_from()
1273 * inputs - snomask needed, level (opers/admin), source server, va_args
1275 * side effects - message is sent to opers with matching snomask
1278 sendto_realops_snomask_from(int flags
, int level
, struct Client
*source_p
,
1279 const char *pattern
, ...)
1281 struct Client
*client_p
;
1283 rb_dlink_node
*next_ptr
;
1287 rb_linebuf_newbuf(&linebuf
);
1289 va_start(args
, pattern
);
1290 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1291 ":%s NOTICE * :*** Notice -- ", source_p
->name
);
1294 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1296 client_p
= ptr
->data
;
1298 /* If we're sending it to opers and theyre an admin, skip.
1299 * If we're sending it to admins, and theyre not, skip.
1301 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1302 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1305 if(client_p
->snomask
& flags
)
1306 _send_linebuf(client_p
, &linebuf
);
1309 rb_linebuf_donebuf(&linebuf
);
1313 * sendto_wallops_flags
1315 * inputs - flag types of messages to show to real opers
1316 * - client sending request
1317 * - var args input message
1319 * side effects - Send a wallops to local opers
1322 sendto_wallops_flags(int flags
, struct Client
*source_p
, const char *pattern
, ...)
1324 struct Client
*client_p
;
1326 rb_dlink_node
*next_ptr
;
1330 rb_linebuf_newbuf(&linebuf
);
1332 va_start(args
, pattern
);
1334 if(IsPerson(source_p
))
1335 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1336 ":%s!%s@%s WALLOPS :", source_p
->name
,
1337 source_p
->username
, source_p
->host
);
1339 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s WALLOPS :", source_p
->name
);
1343 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, IsPerson(source_p
) && flags
== UMODE_WALLOP
? lclient_list
.head
: local_oper_list
.head
)
1345 client_p
= ptr
->data
;
1347 if(client_p
->umodes
& flags
)
1348 _send_linebuf(client_p
, &linebuf
);
1351 rb_linebuf_donebuf(&linebuf
);
1356 * input - client to send kill to, client to kill, va_args
1358 * side effects - we issue a kill for the client
1361 kill_client(struct Client
*target_p
, struct Client
*diedie
, const char *pattern
, ...)
1366 rb_linebuf_newbuf(&linebuf
);
1368 va_start(args
, pattern
);
1369 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s KILL %s :",
1370 get_id(&me
, target_p
), get_id(diedie
, target_p
));
1373 send_linebuf(target_p
, &linebuf
);
1374 rb_linebuf_donebuf(&linebuf
);
1379 * kill_client_serv_butone
1381 * inputs - pointer to client to not send to
1382 * - pointer to client to kill
1384 * side effects - Send a KILL for the given client
1385 * message to all connected servers
1386 * except the client 'one'. Also deal with
1387 * client being unknown to leaf, as in lazylink...
1390 kill_client_serv_butone(struct Client
*one
, struct Client
*target_p
, const char *pattern
, ...)
1392 static char buf
[BUFSIZE
];
1394 struct Client
*client_p
;
1396 rb_dlink_node
*next_ptr
;
1397 buf_head_t rb_linebuf_id
;
1399 rb_linebuf_newbuf(&rb_linebuf_id
);
1401 va_start(args
, pattern
);
1402 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1405 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s KILL %s :%s",
1406 use_id(&me
), use_id(target_p
), buf
);
1408 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
1410 client_p
= ptr
->data
;
1412 /* ok, if the client we're supposed to not send to has an
1413 * ID, then we still want to issue the kill there..
1415 if(one
!= NULL
&& (client_p
== one
->from
) &&
1416 (!has_id(client_p
) || !has_id(target_p
)))
1419 _send_linebuf(client_p
, &rb_linebuf_id
);
1422 rb_linebuf_donebuf(&rb_linebuf_id
);