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_msgvbuf
214 * inputs - msgbuf header, linebuf object, capability mask, pattern, arguments
216 * side effects - the linebuf object is cleared, then populated using rb_linebuf_putmsg().
219 linebuf_put_msgvbuf(struct MsgBuf
*msgbuf
, buf_head_t
*linebuf
, unsigned int capmask
, const char *pattern
, va_list *va
)
223 rb_linebuf_newbuf(linebuf
);
224 msgbuf_unparse_prefix(buf
, sizeof buf
, msgbuf
, capmask
);
225 rb_linebuf_putprefix(linebuf
, pattern
, va
, buf
);
228 /* linebuf_put_msgbuf
230 * inputs - msgbuf header, linebuf object, capability mask, pattern, arguments
232 * side effects - the linebuf object is cleared, then populated using rb_linebuf_putmsg().
235 linebuf_put_msgbuf(struct MsgBuf
*msgbuf
, buf_head_t
*linebuf
, unsigned int capmask
, const char *pattern
, ...)
239 va_start(va
, pattern
);
240 linebuf_put_msgvbuf(msgbuf
, linebuf
, capmask
, pattern
, &va
);
246 * inputs - msgbuf object, client the message is from
248 * side effects - a msgbuf object is populated with an origin and relevant tags
249 * notes - to make this reentrant, find a solution for `buf` below
252 build_msgbuf_from(struct MsgBuf
*msgbuf
, struct Client
*from
, const char *cmd
)
254 static char buf
[BUFSIZE
];
259 msgbuf
->origin
= buf
;
262 if (from
!= NULL
&& IsPerson(from
))
263 snprintf(buf
, sizeof buf
, "%s!%s@%s", from
->name
, from
->username
, from
->host
);
264 else if (from
!= NULL
)
265 rb_strlcpy(buf
, from
->name
, sizeof buf
);
267 rb_strlcpy(buf
, me
.name
, sizeof buf
);
272 call_hook(h_outbound_msgbuf
, &hdata
);
277 * inputs - client to send to, va_args
278 * outputs - client has message put into its queue
282 sendto_one(struct Client
*target_p
, const char *pattern
, ...)
287 /* send remote if to->from non NULL */
288 if(target_p
->from
!= NULL
)
289 target_p
= target_p
->from
;
291 if(IsIOError(target_p
))
294 rb_linebuf_newbuf(&linebuf
);
296 va_start(args
, pattern
);
297 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
300 _send_linebuf(target_p
, &linebuf
);
302 rb_linebuf_donebuf(&linebuf
);
305 /* sendto_one_prefix()
307 * inputs - client to send to, va_args
308 * outputs - client has message put into its queue
309 * side effects - source(us)/target is chosen based on TS6 capability
312 sendto_one_prefix(struct Client
*target_p
, struct Client
*source_p
,
313 const char *command
, const char *pattern
, ...)
315 struct Client
*dest_p
;
319 /* send remote if to->from non NULL */
320 if(target_p
->from
!= NULL
)
321 dest_p
= target_p
->from
;
325 if(IsIOError(dest_p
))
330 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
334 rb_linebuf_newbuf(&linebuf
);
335 va_start(args
, pattern
);
336 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
338 get_id(source_p
, target_p
),
339 command
, get_id(target_p
, target_p
));
342 _send_linebuf(dest_p
, &linebuf
);
343 rb_linebuf_donebuf(&linebuf
);
346 /* sendto_one_notice()
348 * inputs - client to send to, va_args
349 * outputs - client has a NOTICE put into its queue
350 * side effects - source(us)/target is chosen based on TS6 capability
353 sendto_one_notice(struct Client
*target_p
, const char *pattern
, ...)
355 struct Client
*dest_p
;
360 /* send remote if to->from non NULL */
361 if(target_p
->from
!= NULL
)
362 dest_p
= target_p
->from
;
366 if(IsIOError(dest_p
))
371 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
375 rb_linebuf_newbuf(&linebuf
);
376 va_start(args
, pattern
);
377 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
379 get_id(&me
, target_p
), *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
382 _send_linebuf(dest_p
, &linebuf
);
383 rb_linebuf_donebuf(&linebuf
);
387 /* sendto_one_numeric()
389 * inputs - client to send to, va_args
390 * outputs - client has message put into its queue
391 * side effects - source/target is chosen based on TS6 capability
394 sendto_one_numeric(struct Client
*target_p
, int numeric
, const char *pattern
, ...)
396 struct Client
*dest_p
;
401 /* send remote if to->from non NULL */
402 if(target_p
->from
!= NULL
)
403 dest_p
= target_p
->from
;
407 if(IsIOError(dest_p
))
412 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
416 rb_linebuf_newbuf(&linebuf
);
417 va_start(args
, pattern
);
418 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
420 get_id(&me
, target_p
),
421 numeric
, *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
424 _send_linebuf(dest_p
, &linebuf
);
425 rb_linebuf_donebuf(&linebuf
);
431 * inputs - pointer to client to NOT send to
432 * - caps or'd together which must ALL be present
433 * - caps or'd together which must ALL NOT be present
434 * - printf style format string
435 * - args to format string
437 * side effects - Send a message to all connected servers, except the
438 * client 'one' (if non-NULL), as long as the servers
439 * support ALL capabs in 'caps', and NO capabs in 'nocaps'.
441 * This function was written in an attempt to merge together the other
442 * billion sendto_*serv*() functions, which sprung up with capabs, uids etc
446 sendto_server(struct Client
*one
, struct Channel
*chptr
, unsigned long caps
,
447 unsigned long nocaps
, const char *format
, ...)
450 struct Client
*target_p
;
452 rb_dlink_node
*next_ptr
;
455 /* noone to send to.. */
456 if(rb_dlink_list_length(&serv_list
) == 0)
459 if(chptr
!= NULL
&& *chptr
->chname
!= '#')
462 rb_linebuf_newbuf(&linebuf
);
463 va_start(args
, format
);
464 rb_linebuf_putmsg(&linebuf
, format
, &args
, NULL
);
467 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
469 target_p
= ptr
->data
;
471 /* check against 'one' */
472 if(one
!= NULL
&& (target_p
== one
->from
))
475 /* check we have required capabs */
476 if(!IsCapable(target_p
, caps
))
479 /* check we don't have any forbidden capabs */
480 if(!NotCapable(target_p
, nocaps
))
483 _send_linebuf(target_p
, &linebuf
);
486 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
) && 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 /* source client may not be on the channel, send echo separately */
573 if(MyClient(source_p
) && IsCapable(source_p
, CLICAP_ECHO_MESSAGE
))
577 if (target_p
->localClient
->caps
!= current_capmask
)
579 /* reset the linebuf */
580 rb_linebuf_donebuf(&rb_linebuf_local
);
581 rb_linebuf_newbuf(&rb_linebuf_local
);
583 /* render the new linebuf and attach it */
584 linebuf_put_msgbuf(&msgbuf
, &rb_linebuf_local
, target_p
->localClient
->caps
, "%s", buf
);
585 current_capmask
= target_p
->localClient
->caps
;
588 _send_linebuf(target_p
, &rb_linebuf_local
);
591 rb_linebuf_donebuf(&rb_linebuf_local
);
592 rb_linebuf_donebuf(&rb_linebuf_id
);
595 /* sendto_channel_flags()
597 * inputs - server not to send to, flags needed, source, channel, va_args
598 * outputs - message is sent to channel members
602 sendto_channel_opmod(struct Client
*one
, struct Client
*source_p
,
603 struct Channel
*chptr
, const char *command
,
606 buf_head_t rb_linebuf_local
;
607 buf_head_t rb_linebuf_old
;
608 buf_head_t rb_linebuf_new
;
609 struct Client
*target_p
;
610 struct membership
*msptr
;
612 rb_dlink_node
*next_ptr
;
614 rb_linebuf_newbuf(&rb_linebuf_local
);
615 rb_linebuf_newbuf(&rb_linebuf_old
);
616 rb_linebuf_newbuf(&rb_linebuf_new
);
620 if(IsServer(source_p
))
621 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
623 source_p
->name
, command
, chptr
->chname
, text
);
625 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
626 ":%s!%s@%s %s %s :%s",
627 source_p
->name
, source_p
->username
,
628 source_p
->host
, command
, chptr
->chname
, text
);
630 if (chptr
->mode
.mode
& MODE_MODERATED
)
631 rb_linebuf_putmsg(&rb_linebuf_old
, NULL
, NULL
,
633 use_id(source_p
), command
, chptr
->chname
, text
);
635 rb_linebuf_putmsg(&rb_linebuf_old
, NULL
, NULL
,
636 ":%s NOTICE @%s :<%s:%s> %s",
637 use_id(source_p
->servptr
), chptr
->chname
,
638 source_p
->name
, chptr
->chname
, text
);
639 rb_linebuf_putmsg(&rb_linebuf_new
, NULL
, NULL
,
641 use_id(source_p
), command
, chptr
->chname
, text
);
643 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->members
.head
)
646 target_p
= msptr
->client_p
;
648 if(!MyClient(source_p
) && (IsIOError(target_p
->from
) || target_p
->from
== one
))
651 if(MyClient(source_p
) && target_p
== one
)
654 if((msptr
->flags
& CHFL_CHANOP
) == 0)
660 if(!MyClient(target_p
))
662 /* if we've got a specific type, target must support
665 if(NotCapable(target_p
->from
, CAP_CHW
))
668 if(target_p
->from
->serial
!= current_serial
)
670 if (IsCapable(target_p
->from
, CAP_EOPMOD
))
671 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_new
);
673 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_old
);
674 target_p
->from
->serial
= current_serial
;
678 _send_linebuf(target_p
, &rb_linebuf_local
);
681 /* source client may not be on the channel, send echo separately */
682 if(MyClient(source_p
) && IsCapable(source_p
, CLICAP_ECHO_MESSAGE
))
686 _send_linebuf(target_p
, &rb_linebuf_local
);
689 rb_linebuf_donebuf(&rb_linebuf_local
);
690 rb_linebuf_donebuf(&rb_linebuf_old
);
691 rb_linebuf_donebuf(&rb_linebuf_new
);
694 /* sendto_channel_local()
696 * inputs - flags to send to, channel to send to, va_args
697 * outputs - message to local channel members
701 sendto_channel_local(int type
, struct Channel
*chptr
, const char *pattern
, ...)
705 struct membership
*msptr
;
706 struct Client
*target_p
;
708 rb_dlink_node
*next_ptr
;
710 rb_linebuf_newbuf(&linebuf
);
712 va_start(args
, pattern
);
713 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
716 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
719 target_p
= msptr
->client_p
;
721 if(IsIOError(target_p
))
724 if(type
== ONLY_OPERS
)
726 if (!IsOper(target_p
))
729 else if(type
&& ((msptr
->flags
& type
) == 0))
732 _send_linebuf(target_p
, &linebuf
);
735 rb_linebuf_donebuf(&linebuf
);
739 * _sendto_channel_local_with_capability_butone()
741 * Shared implementation of sendto_channel_local_with_capability and sendto_channel_local_with_capability_butone
744 _sendto_channel_local_with_capability_butone(struct Client
*one
, int type
, int caps
, int negcaps
, struct Channel
*chptr
,
745 const char *pattern
, va_list * args
)
748 struct membership
*msptr
;
749 struct Client
*target_p
;
751 rb_dlink_node
*next_ptr
;
753 rb_linebuf_newbuf(&linebuf
);
754 rb_linebuf_putmsg(&linebuf
, pattern
, args
, NULL
);
756 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
759 target_p
= msptr
->client_p
;
764 if(IsIOError(target_p
) ||
765 !IsCapable(target_p
, caps
) ||
766 !NotCapable(target_p
, negcaps
))
769 if(type
&& ((msptr
->flags
& type
) == 0))
772 _send_linebuf(target_p
, &linebuf
);
775 rb_linebuf_donebuf(&linebuf
);
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(int type
, int caps
, int negcaps
, struct Channel
*chptr
, const char *pattern
, ...)
789 va_start(args
, pattern
);
790 _sendto_channel_local_with_capability_butone(NULL
, type
, caps
, negcaps
, chptr
, pattern
, &args
);
795 /* sendto_channel_local_with_capability()
797 * inputs - flags to send to, caps, negate caps, channel to send to, va_args
798 * outputs - message to local channel members
802 sendto_channel_local_with_capability_butone(struct Client
*one
, int type
, int caps
, int negcaps
, struct Channel
*chptr
,
803 const char *pattern
, ...)
807 va_start(args
, pattern
);
808 _sendto_channel_local_with_capability_butone(one
, type
, caps
, negcaps
, chptr
, pattern
, &args
);
813 /* sendto_channel_local_butone()
815 * inputs - flags to send to, channel to send to, va_args
816 * - user to ignore when sending
817 * outputs - message to local channel members
821 sendto_channel_local_butone(struct Client
*one
, int type
, struct Channel
*chptr
, const char *pattern
, ...)
825 struct membership
*msptr
;
826 struct Client
*target_p
;
827 struct MsgBuf msgbuf
;
829 rb_dlink_node
*next_ptr
;
831 rb_linebuf_newbuf(&linebuf
);
833 build_msgbuf_from(&msgbuf
, one
, NULL
);
835 va_start(args
, pattern
);
836 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
839 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
842 target_p
= msptr
->client_p
;
847 if(IsIOError(target_p
))
850 if(type
&& ((msptr
->flags
& type
) == 0))
853 /* attach the present linebuf to the target */
854 _send_linebuf(target_p
, &linebuf
);
857 rb_linebuf_donebuf(&linebuf
);
861 * sendto_common_channels_local()
863 * inputs - pointer to client
865 * - negated capability mask
868 * side effects - Sends a message to all people on local server who are
869 * in same channel with user.
870 * used by m_nick.c and exit_one_client.
873 sendto_common_channels_local(struct Client
*user
, int cap
, int negcap
, const char *pattern
, ...)
877 rb_dlink_node
*next_ptr
;
879 rb_dlink_node
*next_uptr
;
880 struct Channel
*chptr
;
881 struct Client
*target_p
;
882 struct membership
*msptr
;
883 struct membership
*mscptr
;
886 rb_linebuf_newbuf(&linebuf
);
887 va_start(args
, pattern
);
888 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
893 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
896 chptr
= mscptr
->chptr
;
898 RB_DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
901 target_p
= msptr
->client_p
;
903 if(IsIOError(target_p
) ||
904 target_p
->serial
== current_serial
||
905 !IsCapable(target_p
, cap
) ||
906 !NotCapable(target_p
, negcap
))
909 target_p
->serial
= current_serial
;
910 send_linebuf(target_p
, &linebuf
);
914 /* this can happen when the user isnt in any channels, but we still
915 * need to send them the data, ie a nick change
917 if(MyConnect(user
) && (user
->serial
!= current_serial
))
918 send_linebuf(user
, &linebuf
);
920 rb_linebuf_donebuf(&linebuf
);
924 * sendto_common_channels_local_butone()
926 * inputs - pointer to client
928 * - negated capability mask
931 * side effects - Sends a message to all people on local server who are
932 * in same channel with user, except for user itself.
935 sendto_common_channels_local_butone(struct Client
*user
, int cap
, int negcap
, const char *pattern
, ...)
939 rb_dlink_node
*next_ptr
;
941 rb_dlink_node
*next_uptr
;
942 struct Channel
*chptr
;
943 struct Client
*target_p
;
944 struct membership
*msptr
;
945 struct membership
*mscptr
;
948 rb_linebuf_newbuf(&linebuf
);
950 va_start(args
, pattern
);
951 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
955 /* Skip them -- jilles */
956 user
->serial
= current_serial
;
958 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
961 chptr
= mscptr
->chptr
;
963 RB_DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
966 target_p
= msptr
->client_p
;
968 if(IsIOError(target_p
) ||
969 target_p
->serial
== current_serial
||
970 !IsCapable(target_p
, cap
) ||
971 !NotCapable(target_p
, negcap
))
974 target_p
->serial
= current_serial
;
975 send_linebuf(target_p
, &linebuf
);
979 rb_linebuf_donebuf(&linebuf
);
982 /* sendto_match_butone()
984 * inputs - server not to send to, source, mask, type of mask, va_args
986 * side effects - message is sent to matching clients
989 sendto_match_butone(struct Client
*one
, struct Client
*source_p
,
990 const char *mask
, int what
, const char *pattern
, ...)
992 static char buf
[BUFSIZE
];
994 struct Client
*target_p
;
996 rb_dlink_node
*next_ptr
;
997 buf_head_t rb_linebuf_local
;
998 buf_head_t rb_linebuf_id
;
1000 rb_linebuf_newbuf(&rb_linebuf_local
);
1001 rb_linebuf_newbuf(&rb_linebuf_id
);
1003 va_start(args
, pattern
);
1004 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1007 if(IsServer(source_p
))
1008 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
1009 ":%s %s", source_p
->name
, buf
);
1011 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
1013 source_p
->name
, source_p
->username
,
1014 source_p
->host
, buf
);
1016 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
1018 if(what
== MATCH_HOST
)
1020 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
1022 target_p
= ptr
->data
;
1024 if(match(mask
, target_p
->host
))
1025 _send_linebuf(target_p
, &rb_linebuf_local
);
1028 /* what = MATCH_SERVER, if it doesnt match us, just send remote */
1029 else if(match(mask
, me
.name
))
1031 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
1033 target_p
= ptr
->data
;
1034 _send_linebuf(target_p
, &rb_linebuf_local
);
1038 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
1040 target_p
= ptr
->data
;
1045 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_id
);
1048 rb_linebuf_donebuf(&rb_linebuf_local
);
1049 rb_linebuf_donebuf(&rb_linebuf_id
);
1052 /* sendto_match_servs()
1054 * inputs - source, mask to send to, caps needed, va_args
1056 * side effects - message is sent to matching servers with caps.
1059 sendto_match_servs(struct Client
*source_p
, const char *mask
, int cap
,
1060 int nocap
, const char *pattern
, ...)
1062 static char buf
[BUFSIZE
];
1065 struct Client
*target_p
;
1066 buf_head_t rb_linebuf_id
;
1068 if(EmptyString(mask
))
1071 rb_linebuf_newbuf(&rb_linebuf_id
);
1073 va_start(args
, pattern
);
1074 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1077 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
,
1078 ":%s %s", use_id(source_p
), buf
);
1082 RB_DLINK_FOREACH(ptr
, global_serv_list
.head
)
1084 target_p
= ptr
->data
;
1086 /* dont send to ourselves, or back to where it came from.. */
1087 if(IsMe(target_p
) || target_p
->from
== source_p
->from
)
1090 if(target_p
->from
->serial
== current_serial
)
1093 if(match(mask
, target_p
->name
))
1095 /* if we set the serial here, then we'll never do
1096 * a match() again if !IsCapable()
1098 target_p
->from
->serial
= current_serial
;
1100 if(cap
&& !IsCapable(target_p
->from
, cap
))
1103 if(nocap
&& !NotCapable(target_p
->from
, nocap
))
1106 _send_linebuf(target_p
->from
, &rb_linebuf_id
);
1110 rb_linebuf_donebuf(&rb_linebuf_id
);
1113 /* sendto_local_clients_with_capability()
1115 * inputs - caps needed, pattern, va_args
1117 * side effects - message is sent to matching local clients with caps.
1120 sendto_local_clients_with_capability(int cap
, const char *pattern
, ...)
1124 struct Client
*target_p
;
1127 rb_linebuf_newbuf(&linebuf
);
1129 va_start(args
, pattern
);
1130 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
1133 RB_DLINK_FOREACH(ptr
, lclient_list
.head
)
1135 target_p
= ptr
->data
;
1137 if(IsIOError(target_p
) || !IsCapable(target_p
, cap
))
1140 send_linebuf(target_p
, &linebuf
);
1143 rb_linebuf_donebuf(&linebuf
);
1148 * inputs - monitor nick to send to, format, va_args
1149 * outputs - message to local users monitoring the given nick
1153 sendto_monitor(struct monitor
*monptr
, const char *pattern
, ...)
1157 struct Client
*target_p
;
1159 rb_dlink_node
*next_ptr
;
1161 rb_linebuf_newbuf(&linebuf
);
1163 va_start(args
, pattern
);
1164 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
1167 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, monptr
->users
.head
)
1169 target_p
= ptr
->data
;
1171 if(IsIOError(target_p
))
1174 _send_linebuf(target_p
, &linebuf
);
1177 rb_linebuf_donebuf(&linebuf
);
1180 /* _sendto_anywhere()
1182 * inputs - real_target, target, source, va_args
1184 * side effects - client is sent message/own message with correct prefix.
1187 _sendto_anywhere(struct Client
*dest_p
, struct Client
*target_p
,
1188 struct Client
*source_p
, const char *command
,
1189 const char *pattern
, va_list *args
)
1193 rb_linebuf_newbuf(&linebuf
);
1195 if(MyClient(dest_p
))
1197 if(IsServer(source_p
))
1198 rb_linebuf_putmsg(&linebuf
, pattern
, args
, ":%s %s %s ",
1199 source_p
->name
, command
,
1203 struct MsgBuf msgbuf
;
1205 build_msgbuf_from(&msgbuf
, source_p
, command
);
1206 msgbuf
.target
= target_p
->name
;
1208 linebuf_put_msgvbuf(&msgbuf
, &linebuf
, dest_p
->localClient
->caps
, pattern
, args
);
1212 rb_linebuf_putmsg(&linebuf
, pattern
, args
, ":%s %s %s ",
1213 get_id(source_p
, target_p
), command
,
1214 get_id(target_p
, target_p
));
1216 if(MyClient(dest_p
))
1217 _send_linebuf(dest_p
, &linebuf
);
1219 send_linebuf_remote(dest_p
, source_p
, &linebuf
);
1221 rb_linebuf_donebuf(&linebuf
);
1224 /* sendto_anywhere()
1226 * inputs - target, source, va_args
1228 * side effects - client is sent message with correct prefix.
1231 sendto_anywhere(struct Client
*target_p
, struct Client
*source_p
,
1232 const char *command
, const char *pattern
, ...)
1236 va_start(args
, pattern
);
1237 _sendto_anywhere(target_p
, target_p
, source_p
, command
, pattern
, &args
);
1241 /* sendto_anywhere_echo()
1243 * inputs - target, source, va_args
1245 * side effects - client is sent own message with correct prefix.
1248 sendto_anywhere_echo(struct Client
*target_p
, struct Client
*source_p
,
1249 const char *command
, const char *pattern
, ...)
1253 s_assert(MyClient(source_p
));
1254 s_assert(!IsServer(source_p
));
1256 va_start(args
, pattern
);
1257 _sendto_anywhere(source_p
, target_p
, source_p
, command
, pattern
, &args
);
1261 /* sendto_realops_snomask()
1263 * inputs - snomask needed, level (opers/admin), va_args
1265 * side effects - message is sent to opers with matching snomasks
1268 sendto_realops_snomask(int flags
, int level
, const char *pattern
, ...)
1270 static char buf
[BUFSIZE
];
1272 struct Client
*client_p
;
1274 rb_dlink_node
*next_ptr
;
1278 rb_linebuf_newbuf(&linebuf
);
1280 /* Be very sure not to do things like "Trying to send to myself"
1281 * L_NETWIDE, otherwise infinite recursion may result! -- jilles */
1282 if (level
& L_NETWIDE
&& ConfigFileEntry
.global_snotices
)
1284 /* rather a lot of copying around, oh well -- jilles */
1285 va_start(args
, pattern
);
1286 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1288 rb_linebuf_putmsg(&linebuf
, pattern
, NULL
,
1289 ":%s NOTICE * :*** Notice -- %s", me
.name
, buf
);
1290 snobuf
= construct_snobuf(flags
);
1291 if (snobuf
[1] != '\0')
1292 sendto_server(NULL
, NULL
, CAP_ENCAP
|CAP_TS6
, NOCAPS
,
1293 ":%s ENCAP * SNOTE %c :%s",
1294 me
.id
, snobuf
[1], buf
);
1296 else if (remote_rehash_oper_p
!= NULL
)
1298 /* rather a lot of copying around, oh well -- jilles */
1299 va_start(args
, pattern
);
1300 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1302 rb_linebuf_putmsg(&linebuf
, pattern
, NULL
,
1303 ":%s NOTICE * :*** Notice -- %s", me
.name
, buf
);
1304 sendto_one_notice(remote_rehash_oper_p
, ":*** Notice -- %s", buf
);
1308 va_start(args
, pattern
);
1309 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1310 ":%s NOTICE * :*** Notice -- ", me
.name
);
1313 level
&= ~L_NETWIDE
;
1315 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1317 client_p
= ptr
->data
;
1319 /* If we're sending it to opers and theyre an admin, skip.
1320 * If we're sending it to admins, and theyre not, skip.
1322 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1323 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1326 if(client_p
->snomask
& flags
)
1327 _send_linebuf(client_p
, &linebuf
);
1330 rb_linebuf_donebuf(&linebuf
);
1332 /* sendto_realops_snomask_from()
1334 * inputs - snomask needed, level (opers/admin), source server, va_args
1336 * side effects - message is sent to opers with matching snomask
1339 sendto_realops_snomask_from(int flags
, int level
, struct Client
*source_p
,
1340 const char *pattern
, ...)
1342 struct Client
*client_p
;
1344 rb_dlink_node
*next_ptr
;
1348 rb_linebuf_newbuf(&linebuf
);
1350 va_start(args
, pattern
);
1351 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1352 ":%s NOTICE * :*** Notice -- ", source_p
->name
);
1355 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1357 client_p
= ptr
->data
;
1359 /* If we're sending it to opers and theyre an admin, skip.
1360 * If we're sending it to admins, and theyre not, skip.
1362 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1363 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1366 if(client_p
->snomask
& flags
)
1367 _send_linebuf(client_p
, &linebuf
);
1370 rb_linebuf_donebuf(&linebuf
);
1374 * sendto_wallops_flags
1376 * inputs - flag types of messages to show to real opers
1377 * - client sending request
1378 * - var args input message
1380 * side effects - Send a wallops to local opers
1383 sendto_wallops_flags(int flags
, struct Client
*source_p
, const char *pattern
, ...)
1385 struct Client
*client_p
;
1387 rb_dlink_node
*next_ptr
;
1391 rb_linebuf_newbuf(&linebuf
);
1393 va_start(args
, pattern
);
1395 if(IsPerson(source_p
))
1396 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1397 ":%s!%s@%s WALLOPS :", source_p
->name
,
1398 source_p
->username
, source_p
->host
);
1400 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s WALLOPS :", source_p
->name
);
1404 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, IsPerson(source_p
) && flags
== UMODE_WALLOP
? lclient_list
.head
: local_oper_list
.head
)
1406 client_p
= ptr
->data
;
1408 if(client_p
->umodes
& flags
)
1409 _send_linebuf(client_p
, &linebuf
);
1412 rb_linebuf_donebuf(&linebuf
);
1417 * input - client to send kill to, client to kill, va_args
1419 * side effects - we issue a kill for the client
1422 kill_client(struct Client
*target_p
, struct Client
*diedie
, const char *pattern
, ...)
1427 rb_linebuf_newbuf(&linebuf
);
1429 va_start(args
, pattern
);
1430 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s KILL %s :",
1431 get_id(&me
, target_p
), get_id(diedie
, target_p
));
1434 send_linebuf(target_p
, &linebuf
);
1435 rb_linebuf_donebuf(&linebuf
);
1440 * kill_client_serv_butone
1442 * inputs - pointer to client to not send to
1443 * - pointer to client to kill
1445 * side effects - Send a KILL for the given client
1446 * message to all connected servers
1447 * except the client 'one'. Also deal with
1448 * client being unknown to leaf, as in lazylink...
1451 kill_client_serv_butone(struct Client
*one
, struct Client
*target_p
, const char *pattern
, ...)
1453 static char buf
[BUFSIZE
];
1455 struct Client
*client_p
;
1457 rb_dlink_node
*next_ptr
;
1458 buf_head_t rb_linebuf_id
;
1460 rb_linebuf_newbuf(&rb_linebuf_id
);
1462 va_start(args
, pattern
);
1463 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1466 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s KILL %s :%s",
1467 use_id(&me
), use_id(target_p
), buf
);
1469 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
1471 client_p
= ptr
->data
;
1473 /* ok, if the client we're supposed to not send to has an
1474 * ID, then we still want to issue the kill there..
1476 if(one
!= NULL
&& (client_p
== one
->from
) &&
1477 (!has_id(client_p
) || !has_id(target_p
)))
1480 _send_linebuf(client_p
, &rb_linebuf_id
);
1483 rb_linebuf_donebuf(&rb_linebuf_id
);