2 * ircd-ratbox: A slightly useful ircd.
3 * send.c: Functions for sending messages.
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 * $Id: send.c 3520 2007-06-30 22:15:35Z jilles $
38 #include "s_newconf.h"
44 /* send the message to the link the target is attached to */
45 #define send_linebuf(a,b) _send_linebuf((a->from ? a->from : a) ,b)
47 static void send_queued_write(rb_fde_t
*F
, void *data
);
49 unsigned long current_serial
= 0L;
51 struct Client
*remote_rehash_oper_p
;
55 * inputs - client to send to, linebuf to attach
57 * side effects - linebuf is attached to client
60 _send_linebuf(struct Client
*to
, buf_head_t
*linebuf
)
64 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send message to myself!");
68 if(!MyConnect(to
) || IsIOError(to
))
71 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > get_sendq(to
))
75 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
76 "Max SendQ limit exceeded for %s: %u > %lu",
78 rb_linebuf_len(&to
->localClient
->buf_sendq
),
81 ilog(L_SERVER
, "Max SendQ limit exceeded for %s: %u > %lu",
82 log_client_name(to
, SHOW_IP
),
83 rb_linebuf_len(&to
->localClient
->buf_sendq
),
92 /* just attach the linebuf to the sendq instead of
93 * generating a new one
95 rb_linebuf_attach(&to
->localClient
->buf_sendq
, linebuf
);
99 ** Update statistics. The following is slightly incorrect
100 ** because it counts messages even if queued, but bytes
101 ** only really sent. Queued bytes get updated in SendQueued.
103 to
->localClient
->sendM
+= 1;
104 me
.localClient
->sendM
+= 1;
105 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > 0)
110 /* send_linebuf_remote()
112 * inputs - client to attach to, sender, linebuf
114 * side effects - client has linebuf attached
117 send_linebuf_remote(struct Client
*to
, struct Client
*from
, buf_head_t
*linebuf
)
122 /* we assume the caller has already tested for fake direction */
123 _send_linebuf(to
, linebuf
);
126 /* send_queued_write()
128 * inputs - fd to have queue sent, client we're sending to
129 * outputs - contents of queue
130 * side effects - write is rescheduled if queue isnt emptied
133 send_queued(struct Client
*to
)
137 rb_fde_t
*F
= to
->localClient
->F
;
141 /* cant write anything to a dead socket. */
145 /* try to flush later when the write event resets this */
149 if(rb_linebuf_len(&to
->localClient
->buf_sendq
))
152 rb_linebuf_flush(F
, &to
->localClient
->buf_sendq
)) > 0)
154 /* We have some data written .. update counters */
157 to
->localClient
->sendB
+= retlen
;
158 me
.localClient
->sendB
+= retlen
;
159 if(to
->localClient
->sendB
> 1023)
161 to
->localClient
->sendK
+= (to
->localClient
->sendB
>> 10);
162 to
->localClient
->sendB
&= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */
164 else if(me
.localClient
->sendB
> 1023)
166 me
.localClient
->sendK
+= (me
.localClient
->sendB
>> 10);
167 me
.localClient
->sendB
&= 0x03ff;
171 if(retlen
== 0 || (retlen
< 0 && !rb_ignore_errno(errno
)))
178 if(rb_linebuf_len(&to
->localClient
->buf_sendq
))
181 rb_setselect(to
->localClient
->F
, RB_SELECT_WRITE
,
182 send_queued_write
, to
);
189 send_pop_queue(struct Client
*to
)
193 if(!MyConnect(to
) || IsIOError(to
))
195 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > 0)
199 /* send_queued_write()
201 * inputs - fd to have queue sent, client we're sending to
202 * outputs - contents of queue
203 * side effects - write is scheduled if queue isnt emptied
206 send_queued_write(rb_fde_t
*F
, void *data
)
208 struct Client
*to
= data
;
214 * linebuf_put_msgvbuf
216 * inputs - msgbuf header, linebuf object, capability mask, pattern, arguments
218 * side effects - the linebuf object is cleared, then populated using rb_linebuf_putmsg().
221 linebuf_put_msgvbuf(struct MsgBuf
*msgbuf
, buf_head_t
*linebuf
, unsigned int capmask
, const char *pattern
, va_list *va
)
223 char buf
[IRCD_BUFSIZE
];
225 rb_linebuf_newbuf(linebuf
);
226 msgbuf_unparse_prefix(buf
, sizeof buf
, msgbuf
, capmask
);
227 rb_linebuf_putprefix(linebuf
, pattern
, va
, buf
);
230 /* linebuf_put_msgbuf
232 * inputs - msgbuf header, linebuf object, capability mask, pattern, arguments
234 * side effects - the linebuf object is cleared, then populated using rb_linebuf_putmsg().
237 linebuf_put_msgbuf(struct MsgBuf
*msgbuf
, buf_head_t
*linebuf
, unsigned int capmask
, const char *pattern
, ...)
241 va_start(va
, pattern
);
242 linebuf_put_msgvbuf(msgbuf
, linebuf
, capmask
, pattern
, &va
);
248 * inputs - msgbuf object, client the message is from
250 * side effects - a msgbuf object is populated with an origin and relevant tags
251 * notes - to make this reentrant, find a solution for `buf` below
254 build_msgbuf_from(struct MsgBuf
*msgbuf
, struct Client
*from
, const char *cmd
)
256 static char buf
[BUFSIZE
];
261 msgbuf
->origin
= buf
;
265 snprintf(buf
, sizeof buf
, "%s!%s@%s", from
->name
, from
->username
, from
->host
);
267 rb_strlcpy(buf
, from
->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
);
490 /* sendto_channel_flags()
492 * inputs - server not to send to, flags needed, source, channel, va_args
493 * outputs - message is sent to channel members
497 sendto_channel_flags(struct Client
*one
, int type
, struct Client
*source_p
,
498 struct Channel
*chptr
, const char *pattern
, ...)
500 char buf
[IRCD_BUFSIZE
];
502 buf_head_t rb_linebuf_local
;
503 buf_head_t rb_linebuf_id
;
504 struct Client
*target_p
;
505 struct membership
*msptr
;
507 rb_dlink_node
*next_ptr
;
508 unsigned int current_capmask
= 0;
509 struct MsgBuf msgbuf
;
511 rb_linebuf_newbuf(&rb_linebuf_local
);
512 rb_linebuf_newbuf(&rb_linebuf_id
);
516 build_msgbuf_from(&msgbuf
, source_p
, NULL
);
518 va_start(args
, pattern
);
519 vsnprintf(buf
, sizeof buf
, pattern
, args
);
522 linebuf_put_msgbuf(&msgbuf
, &rb_linebuf_local
, NOCAPS
, "%s", buf
);
523 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
525 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->members
.head
)
528 target_p
= msptr
->client_p
;
530 if(IsIOError(target_p
->from
) || target_p
->from
== one
)
533 if(type
&& ((msptr
->flags
& type
) == 0))
539 if(!MyClient(target_p
))
541 /* if we've got a specific type, target must support
544 if(type
&& NotCapable(target_p
->from
, CAP_CHW
))
547 if(target_p
->from
->serial
!= current_serial
)
549 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_id
);
550 target_p
->from
->serial
= current_serial
;
555 if (target_p
->localClient
->caps
!= current_capmask
)
557 /* reset the linebuf */
558 rb_linebuf_donebuf(&rb_linebuf_local
);
559 rb_linebuf_newbuf(&rb_linebuf_local
);
561 /* render the new linebuf and attach it */
562 linebuf_put_msgbuf(&msgbuf
, &rb_linebuf_local
, target_p
->localClient
->caps
, "%s", buf
);
563 current_capmask
= target_p
->localClient
->caps
;
566 _send_linebuf(target_p
, &rb_linebuf_local
);
570 rb_linebuf_donebuf(&rb_linebuf_local
);
571 rb_linebuf_donebuf(&rb_linebuf_id
);
574 /* sendto_channel_flags()
576 * inputs - server not to send to, flags needed, source, channel, va_args
577 * outputs - message is sent to channel members
581 sendto_channel_opmod(struct Client
*one
, struct Client
*source_p
,
582 struct Channel
*chptr
, const char *command
,
585 buf_head_t rb_linebuf_local
;
586 buf_head_t rb_linebuf_old
;
587 buf_head_t rb_linebuf_new
;
588 struct Client
*target_p
;
589 struct membership
*msptr
;
591 rb_dlink_node
*next_ptr
;
593 rb_linebuf_newbuf(&rb_linebuf_local
);
594 rb_linebuf_newbuf(&rb_linebuf_old
);
595 rb_linebuf_newbuf(&rb_linebuf_new
);
599 if(IsServer(source_p
))
600 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
602 source_p
->name
, command
, chptr
->chname
, text
);
604 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
605 ":%s!%s@%s %s %s :%s",
606 source_p
->name
, source_p
->username
,
607 source_p
->host
, command
, chptr
->chname
, text
);
609 if (chptr
->mode
.mode
& MODE_MODERATED
)
610 rb_linebuf_putmsg(&rb_linebuf_old
, NULL
, NULL
,
612 use_id(source_p
), command
, chptr
->chname
, text
);
614 rb_linebuf_putmsg(&rb_linebuf_old
, NULL
, NULL
,
615 ":%s NOTICE @%s :<%s:%s> %s",
616 use_id(source_p
->servptr
), chptr
->chname
,
617 source_p
->name
, chptr
->chname
, text
);
618 rb_linebuf_putmsg(&rb_linebuf_new
, NULL
, NULL
,
620 use_id(source_p
), command
, chptr
->chname
, text
);
622 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->members
.head
)
625 target_p
= msptr
->client_p
;
627 if(IsIOError(target_p
->from
) || target_p
->from
== one
)
630 if((msptr
->flags
& CHFL_CHANOP
) == 0)
636 if(!MyClient(target_p
))
638 /* if we've got a specific type, target must support
641 if(NotCapable(target_p
->from
, CAP_CHW
))
644 if(target_p
->from
->serial
!= current_serial
)
646 if (IsCapable(target_p
->from
, CAP_EOPMOD
))
647 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_new
);
649 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_old
);
650 target_p
->from
->serial
= current_serial
;
654 _send_linebuf(target_p
, &rb_linebuf_local
);
657 rb_linebuf_donebuf(&rb_linebuf_local
);
658 rb_linebuf_donebuf(&rb_linebuf_old
);
659 rb_linebuf_donebuf(&rb_linebuf_new
);
662 /* sendto_channel_local()
664 * inputs - flags to send to, channel to send to, va_args
665 * outputs - message to local channel members
669 sendto_channel_local(int type
, struct Channel
*chptr
, const char *pattern
, ...)
673 struct membership
*msptr
;
674 struct Client
*target_p
;
676 rb_dlink_node
*next_ptr
;
678 rb_linebuf_newbuf(&linebuf
);
680 va_start(args
, pattern
);
681 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
684 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
687 target_p
= msptr
->client_p
;
689 if(IsIOError(target_p
))
692 if(type
== ONLY_OPERS
)
694 if (!IsOper(target_p
))
697 else if(type
&& ((msptr
->flags
& type
) == 0))
700 _send_linebuf(target_p
, &linebuf
);
703 rb_linebuf_donebuf(&linebuf
);
707 * _sendto_channel_local_with_capability_butone()
709 * Shared implementation of sendto_channel_local_with_capability and sendto_channel_local_with_capability_butone
712 _sendto_channel_local_with_capability_butone(struct Client
*one
, int type
, int caps
, int negcaps
, struct Channel
*chptr
,
713 const char *pattern
, va_list * args
)
716 struct membership
*msptr
;
717 struct Client
*target_p
;
719 rb_dlink_node
*next_ptr
;
721 rb_linebuf_newbuf(&linebuf
);
722 rb_linebuf_putmsg(&linebuf
, pattern
, args
, NULL
);
724 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
727 target_p
= msptr
->client_p
;
732 if(IsIOError(target_p
) ||
733 !IsCapable(target_p
, caps
) ||
734 !NotCapable(target_p
, negcaps
))
737 if(type
&& ((msptr
->flags
& type
) == 0))
740 _send_linebuf(target_p
, &linebuf
);
743 rb_linebuf_donebuf(&linebuf
);
746 /* sendto_channel_local_with_capability()
748 * inputs - flags to send to, caps, negate caps, channel to send to, va_args
749 * outputs - message to local channel members
753 sendto_channel_local_with_capability(int type
, int caps
, int negcaps
, struct Channel
*chptr
, const char *pattern
, ...)
757 va_start(args
, pattern
);
758 _sendto_channel_local_with_capability_butone(NULL
, type
, caps
, negcaps
, chptr
, pattern
, &args
);
763 /* sendto_channel_local_with_capability()
765 * inputs - flags to send to, caps, negate caps, channel to send to, va_args
766 * outputs - message to local channel members
770 sendto_channel_local_with_capability_butone(struct Client
*one
, int type
, int caps
, int negcaps
, struct Channel
*chptr
,
771 const char *pattern
, ...)
775 va_start(args
, pattern
);
776 _sendto_channel_local_with_capability_butone(one
, type
, caps
, negcaps
, chptr
, pattern
, &args
);
781 /* sendto_channel_local_butone()
783 * inputs - flags to send to, channel to send to, va_args
784 * - user to ignore when sending
785 * outputs - message to local channel members
789 sendto_channel_local_butone(struct Client
*one
, int type
, struct Channel
*chptr
, const char *pattern
, ...)
793 struct membership
*msptr
;
794 struct Client
*target_p
;
795 struct MsgBuf msgbuf
;
797 rb_dlink_node
*next_ptr
;
799 rb_linebuf_newbuf(&linebuf
);
801 build_msgbuf_from(&msgbuf
, one
, NULL
);
803 va_start(args
, pattern
);
804 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
807 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
810 target_p
= msptr
->client_p
;
815 if(IsIOError(target_p
))
818 if(type
&& ((msptr
->flags
& type
) == 0))
821 /* attach the present linebuf to the target */
822 _send_linebuf(target_p
, &linebuf
);
825 rb_linebuf_donebuf(&linebuf
);
829 * sendto_common_channels_local()
831 * inputs - pointer to client
833 * - negated capability mask
836 * side effects - Sends a message to all people on local server who are
837 * in same channel with user.
838 * used by m_nick.c and exit_one_client.
841 sendto_common_channels_local(struct Client
*user
, int cap
, int negcap
, const char *pattern
, ...)
845 rb_dlink_node
*next_ptr
;
847 rb_dlink_node
*next_uptr
;
848 struct Channel
*chptr
;
849 struct Client
*target_p
;
850 struct membership
*msptr
;
851 struct membership
*mscptr
;
854 rb_linebuf_newbuf(&linebuf
);
855 va_start(args
, pattern
);
856 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
861 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
864 chptr
= mscptr
->chptr
;
866 RB_DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
869 target_p
= msptr
->client_p
;
871 if(IsIOError(target_p
) ||
872 target_p
->serial
== current_serial
||
873 !IsCapable(target_p
, cap
) ||
874 !NotCapable(target_p
, negcap
))
877 target_p
->serial
= current_serial
;
878 send_linebuf(target_p
, &linebuf
);
882 /* this can happen when the user isnt in any channels, but we still
883 * need to send them the data, ie a nick change
885 if(MyConnect(user
) && (user
->serial
!= current_serial
))
886 send_linebuf(user
, &linebuf
);
888 rb_linebuf_donebuf(&linebuf
);
892 * sendto_common_channels_local_butone()
894 * inputs - pointer to client
896 * - negated capability mask
899 * side effects - Sends a message to all people on local server who are
900 * in same channel with user, except for user itself.
903 sendto_common_channels_local_butone(struct Client
*user
, int cap
, int negcap
, const char *pattern
, ...)
907 rb_dlink_node
*next_ptr
;
909 rb_dlink_node
*next_uptr
;
910 struct Channel
*chptr
;
911 struct Client
*target_p
;
912 struct membership
*msptr
;
913 struct membership
*mscptr
;
916 rb_linebuf_newbuf(&linebuf
);
918 va_start(args
, pattern
);
919 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
923 /* Skip them -- jilles */
924 user
->serial
= current_serial
;
926 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
929 chptr
= mscptr
->chptr
;
931 RB_DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
934 target_p
= msptr
->client_p
;
936 if(IsIOError(target_p
) ||
937 target_p
->serial
== current_serial
||
938 !IsCapable(target_p
, cap
) ||
939 !NotCapable(target_p
, negcap
))
942 target_p
->serial
= current_serial
;
943 send_linebuf(target_p
, &linebuf
);
947 rb_linebuf_donebuf(&linebuf
);
950 /* sendto_match_butone()
952 * inputs - server not to send to, source, mask, type of mask, va_args
954 * side effects - message is sent to matching clients
957 sendto_match_butone(struct Client
*one
, struct Client
*source_p
,
958 const char *mask
, int what
, const char *pattern
, ...)
960 static char buf
[BUFSIZE
];
962 struct Client
*target_p
;
964 rb_dlink_node
*next_ptr
;
965 buf_head_t rb_linebuf_local
;
966 buf_head_t rb_linebuf_id
;
968 rb_linebuf_newbuf(&rb_linebuf_local
);
969 rb_linebuf_newbuf(&rb_linebuf_id
);
971 va_start(args
, pattern
);
972 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
975 if(IsServer(source_p
))
976 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
977 ":%s %s", source_p
->name
, buf
);
979 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
981 source_p
->name
, source_p
->username
,
982 source_p
->host
, buf
);
984 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
986 if(what
== MATCH_HOST
)
988 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
990 target_p
= ptr
->data
;
992 if(match(mask
, target_p
->host
))
993 _send_linebuf(target_p
, &rb_linebuf_local
);
996 /* what = MATCH_SERVER, if it doesnt match us, just send remote */
997 else if(match(mask
, me
.name
))
999 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
1001 target_p
= ptr
->data
;
1002 _send_linebuf(target_p
, &rb_linebuf_local
);
1006 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
1008 target_p
= ptr
->data
;
1013 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_id
);
1016 rb_linebuf_donebuf(&rb_linebuf_local
);
1017 rb_linebuf_donebuf(&rb_linebuf_id
);
1020 /* sendto_match_servs()
1022 * inputs - source, mask to send to, caps needed, va_args
1024 * side effects - message is sent to matching servers with caps.
1027 sendto_match_servs(struct Client
*source_p
, const char *mask
, int cap
,
1028 int nocap
, const char *pattern
, ...)
1030 static char buf
[BUFSIZE
];
1033 struct Client
*target_p
;
1034 buf_head_t rb_linebuf_id
;
1036 if(EmptyString(mask
))
1039 rb_linebuf_newbuf(&rb_linebuf_id
);
1041 va_start(args
, pattern
);
1042 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1045 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
,
1046 ":%s %s", use_id(source_p
), buf
);
1050 RB_DLINK_FOREACH(ptr
, global_serv_list
.head
)
1052 target_p
= ptr
->data
;
1054 /* dont send to ourselves, or back to where it came from.. */
1055 if(IsMe(target_p
) || target_p
->from
== source_p
->from
)
1058 if(target_p
->from
->serial
== current_serial
)
1061 if(match(mask
, target_p
->name
))
1063 /* if we set the serial here, then we'll never do
1064 * a match() again if !IsCapable()
1066 target_p
->from
->serial
= current_serial
;
1068 if(cap
&& !IsCapable(target_p
->from
, cap
))
1071 if(nocap
&& !NotCapable(target_p
->from
, nocap
))
1074 _send_linebuf(target_p
->from
, &rb_linebuf_id
);
1078 rb_linebuf_donebuf(&rb_linebuf_id
);
1081 /* sendto_local_clients_with_capability()
1083 * inputs - caps needed, pattern, va_args
1085 * side effects - message is sent to matching local clients with caps.
1088 sendto_local_clients_with_capability(int cap
, const char *pattern
, ...)
1092 struct Client
*target_p
;
1095 rb_linebuf_newbuf(&linebuf
);
1097 va_start(args
, pattern
);
1098 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
1101 RB_DLINK_FOREACH(ptr
, lclient_list
.head
)
1103 target_p
= ptr
->data
;
1105 if(IsIOError(target_p
) || !IsCapable(target_p
, cap
))
1108 send_linebuf(target_p
, &linebuf
);
1111 rb_linebuf_donebuf(&linebuf
);
1116 * inputs - monitor nick to send to, format, va_args
1117 * outputs - message to local users monitoring the given nick
1121 sendto_monitor(struct monitor
*monptr
, const char *pattern
, ...)
1125 struct Client
*target_p
;
1127 rb_dlink_node
*next_ptr
;
1129 rb_linebuf_newbuf(&linebuf
);
1131 va_start(args
, pattern
);
1132 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
1135 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, monptr
->users
.head
)
1137 target_p
= ptr
->data
;
1139 if(IsIOError(target_p
))
1142 _send_linebuf(target_p
, &linebuf
);
1145 rb_linebuf_donebuf(&linebuf
);
1148 /* sendto_anywhere()
1150 * inputs - target, source, va_args
1152 * side effects - client is sent message with correct prefix.
1155 sendto_anywhere(struct Client
*target_p
, struct Client
*source_p
,
1156 const char *command
, const char *pattern
, ...)
1161 rb_linebuf_newbuf(&linebuf
);
1163 va_start(args
, pattern
);
1165 if(MyClient(target_p
))
1167 if(IsServer(source_p
))
1168 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
1169 source_p
->name
, command
,
1173 struct MsgBuf msgbuf
;
1175 build_msgbuf_from(&msgbuf
, source_p
, command
);
1176 msgbuf
.target
= target_p
->name
;
1178 linebuf_put_msgvbuf(&msgbuf
, &linebuf
, target_p
->localClient
->caps
, pattern
, &args
);
1182 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
1183 get_id(source_p
, target_p
), command
,
1184 get_id(target_p
, target_p
));
1187 if(MyClient(target_p
))
1188 _send_linebuf(target_p
, &linebuf
);
1190 send_linebuf_remote(target_p
, source_p
, &linebuf
);
1192 rb_linebuf_donebuf(&linebuf
);
1195 /* sendto_realops_snomask()
1197 * inputs - snomask needed, level (opers/admin), va_args
1199 * side effects - message is sent to opers with matching snomasks
1202 sendto_realops_snomask(int flags
, int level
, const char *pattern
, ...)
1204 static char buf
[BUFSIZE
];
1206 struct Client
*client_p
;
1208 rb_dlink_node
*next_ptr
;
1212 rb_linebuf_newbuf(&linebuf
);
1214 /* Be very sure not to do things like "Trying to send to myself"
1215 * L_NETWIDE, otherwise infinite recursion may result! -- jilles */
1216 if (level
& L_NETWIDE
&& ConfigFileEntry
.global_snotices
)
1218 /* rather a lot of copying around, oh well -- jilles */
1219 va_start(args
, pattern
);
1220 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1222 rb_linebuf_putmsg(&linebuf
, pattern
, NULL
,
1223 ":%s NOTICE * :*** Notice -- %s", me
.name
, buf
);
1224 snobuf
= construct_snobuf(flags
);
1225 if (snobuf
[1] != '\0')
1226 sendto_server(NULL
, NULL
, CAP_ENCAP
|CAP_TS6
, NOCAPS
,
1227 ":%s ENCAP * SNOTE %c :%s",
1228 me
.id
, snobuf
[1], buf
);
1230 else if (remote_rehash_oper_p
!= NULL
)
1232 /* rather a lot of copying around, oh well -- jilles */
1233 va_start(args
, pattern
);
1234 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1236 rb_linebuf_putmsg(&linebuf
, pattern
, NULL
,
1237 ":%s NOTICE * :*** Notice -- %s", me
.name
, buf
);
1238 sendto_one_notice(remote_rehash_oper_p
, ":*** Notice -- %s", buf
);
1242 va_start(args
, pattern
);
1243 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1244 ":%s NOTICE * :*** Notice -- ", me
.name
);
1247 level
&= ~L_NETWIDE
;
1249 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1251 client_p
= ptr
->data
;
1253 /* If we're sending it to opers and theyre an admin, skip.
1254 * If we're sending it to admins, and theyre not, skip.
1256 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1257 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1260 if(client_p
->snomask
& flags
)
1261 _send_linebuf(client_p
, &linebuf
);
1264 rb_linebuf_donebuf(&linebuf
);
1266 /* sendto_realops_snomask_from()
1268 * inputs - snomask needed, level (opers/admin), source server, va_args
1270 * side effects - message is sent to opers with matching snomask
1273 sendto_realops_snomask_from(int flags
, int level
, struct Client
*source_p
,
1274 const char *pattern
, ...)
1276 struct Client
*client_p
;
1278 rb_dlink_node
*next_ptr
;
1282 rb_linebuf_newbuf(&linebuf
);
1284 va_start(args
, pattern
);
1285 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1286 ":%s NOTICE * :*** Notice -- ", source_p
->name
);
1289 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1291 client_p
= ptr
->data
;
1293 /* If we're sending it to opers and theyre an admin, skip.
1294 * If we're sending it to admins, and theyre not, skip.
1296 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1297 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1300 if(client_p
->snomask
& flags
)
1301 _send_linebuf(client_p
, &linebuf
);
1304 rb_linebuf_donebuf(&linebuf
);
1308 * sendto_wallops_flags
1310 * inputs - flag types of messages to show to real opers
1311 * - client sending request
1312 * - var args input message
1314 * side effects - Send a wallops to local opers
1317 sendto_wallops_flags(int flags
, struct Client
*source_p
, const char *pattern
, ...)
1319 struct Client
*client_p
;
1321 rb_dlink_node
*next_ptr
;
1325 rb_linebuf_newbuf(&linebuf
);
1327 va_start(args
, pattern
);
1329 if(IsPerson(source_p
))
1330 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1331 ":%s!%s@%s WALLOPS :", source_p
->name
,
1332 source_p
->username
, source_p
->host
);
1334 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s WALLOPS :", source_p
->name
);
1338 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, IsPerson(source_p
) && flags
== UMODE_WALLOP
? lclient_list
.head
: local_oper_list
.head
)
1340 client_p
= ptr
->data
;
1342 if(client_p
->umodes
& flags
)
1343 _send_linebuf(client_p
, &linebuf
);
1346 rb_linebuf_donebuf(&linebuf
);
1351 * input - client to send kill to, client to kill, va_args
1353 * side effects - we issue a kill for the client
1356 kill_client(struct Client
*target_p
, struct Client
*diedie
, const char *pattern
, ...)
1361 rb_linebuf_newbuf(&linebuf
);
1363 va_start(args
, pattern
);
1364 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s KILL %s :",
1365 get_id(&me
, target_p
), get_id(diedie
, target_p
));
1368 send_linebuf(target_p
, &linebuf
);
1369 rb_linebuf_donebuf(&linebuf
);
1374 * kill_client_serv_butone
1376 * inputs - pointer to client to not send to
1377 * - pointer to client to kill
1379 * side effects - Send a KILL for the given client
1380 * message to all connected servers
1381 * except the client 'one'. Also deal with
1382 * client being unknown to leaf, as in lazylink...
1385 kill_client_serv_butone(struct Client
*one
, struct Client
*target_p
, const char *pattern
, ...)
1387 static char buf
[BUFSIZE
];
1389 struct Client
*client_p
;
1391 rb_dlink_node
*next_ptr
;
1392 buf_head_t rb_linebuf_id
;
1394 rb_linebuf_newbuf(&rb_linebuf_id
);
1396 va_start(args
, pattern
);
1397 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1400 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s KILL %s :%s",
1401 use_id(&me
), use_id(target_p
), buf
);
1403 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
1405 client_p
= ptr
->data
;
1407 /* ok, if the client we're supposed to not send to has an
1408 * ID, then we still want to issue the kill there..
1410 if(one
!= NULL
&& (client_p
== one
->from
) &&
1411 (!has_id(client_p
) || !has_id(target_p
)))
1414 _send_linebuf(client_p
, &rb_linebuf_id
);
1417 rb_linebuf_donebuf(&rb_linebuf_id
);