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
)
221 char buf
[IRCD_BUFSIZE
];
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
);
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(!MyClient(source_p
) && (IsIOError(target_p
->from
) || target_p
->from
== one
))
533 if(MyClient(source_p
) && !IsCapable(source_p
, CLICAP_ECHO_MESSAGE
) && target_p
== one
)
536 if(type
&& ((msptr
->flags
& type
) == 0))
542 if(!MyClient(target_p
))
544 /* if we've got a specific type, target must support
547 if(type
&& NotCapable(target_p
->from
, CAP_CHW
))
550 if(target_p
->from
->serial
!= current_serial
)
552 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_id
);
553 target_p
->from
->serial
= current_serial
;
558 if (target_p
->localClient
->caps
!= current_capmask
)
560 /* reset the linebuf */
561 rb_linebuf_donebuf(&rb_linebuf_local
);
562 rb_linebuf_newbuf(&rb_linebuf_local
);
564 /* render the new linebuf and attach it */
565 linebuf_put_msgbuf(&msgbuf
, &rb_linebuf_local
, target_p
->localClient
->caps
, "%s", buf
);
566 current_capmask
= target_p
->localClient
->caps
;
569 _send_linebuf(target_p
, &rb_linebuf_local
);
573 rb_linebuf_donebuf(&rb_linebuf_local
);
574 rb_linebuf_donebuf(&rb_linebuf_id
);
577 /* sendto_channel_flags()
579 * inputs - server not to send to, flags needed, source, channel, va_args
580 * outputs - message is sent to channel members
584 sendto_channel_opmod(struct Client
*one
, struct Client
*source_p
,
585 struct Channel
*chptr
, const char *command
,
588 buf_head_t rb_linebuf_local
;
589 buf_head_t rb_linebuf_old
;
590 buf_head_t rb_linebuf_new
;
591 struct Client
*target_p
;
592 struct membership
*msptr
;
594 rb_dlink_node
*next_ptr
;
596 rb_linebuf_newbuf(&rb_linebuf_local
);
597 rb_linebuf_newbuf(&rb_linebuf_old
);
598 rb_linebuf_newbuf(&rb_linebuf_new
);
602 if(IsServer(source_p
))
603 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
605 source_p
->name
, command
, chptr
->chname
, text
);
607 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
608 ":%s!%s@%s %s %s :%s",
609 source_p
->name
, source_p
->username
,
610 source_p
->host
, command
, chptr
->chname
, text
);
612 if (chptr
->mode
.mode
& MODE_MODERATED
)
613 rb_linebuf_putmsg(&rb_linebuf_old
, NULL
, NULL
,
615 use_id(source_p
), command
, chptr
->chname
, text
);
617 rb_linebuf_putmsg(&rb_linebuf_old
, NULL
, NULL
,
618 ":%s NOTICE @%s :<%s:%s> %s",
619 use_id(source_p
->servptr
), chptr
->chname
,
620 source_p
->name
, chptr
->chname
, text
);
621 rb_linebuf_putmsg(&rb_linebuf_new
, NULL
, NULL
,
623 use_id(source_p
), command
, chptr
->chname
, text
);
625 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->members
.head
)
628 target_p
= msptr
->client_p
;
630 if(!MyClient(source_p
) && (IsIOError(target_p
->from
) || target_p
->from
== one
))
633 if(MyClient(source_p
) && !IsCapable(source_p
, CLICAP_ECHO_MESSAGE
) && target_p
== one
)
636 if((msptr
->flags
& CHFL_CHANOP
) == 0)
642 if(!MyClient(target_p
))
644 /* if we've got a specific type, target must support
647 if(NotCapable(target_p
->from
, CAP_CHW
))
650 if(target_p
->from
->serial
!= current_serial
)
652 if (IsCapable(target_p
->from
, CAP_EOPMOD
))
653 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_new
);
655 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_old
);
656 target_p
->from
->serial
= current_serial
;
660 _send_linebuf(target_p
, &rb_linebuf_local
);
663 rb_linebuf_donebuf(&rb_linebuf_local
);
664 rb_linebuf_donebuf(&rb_linebuf_old
);
665 rb_linebuf_donebuf(&rb_linebuf_new
);
668 /* sendto_channel_local()
670 * inputs - flags to send to, channel to send to, va_args
671 * outputs - message to local channel members
675 sendto_channel_local(int type
, struct Channel
*chptr
, const char *pattern
, ...)
679 struct membership
*msptr
;
680 struct Client
*target_p
;
682 rb_dlink_node
*next_ptr
;
684 rb_linebuf_newbuf(&linebuf
);
686 va_start(args
, pattern
);
687 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
690 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
693 target_p
= msptr
->client_p
;
695 if(IsIOError(target_p
))
698 if(type
== ONLY_OPERS
)
700 if (!IsOper(target_p
))
703 else if(type
&& ((msptr
->flags
& type
) == 0))
706 _send_linebuf(target_p
, &linebuf
);
709 rb_linebuf_donebuf(&linebuf
);
713 * _sendto_channel_local_with_capability_butone()
715 * Shared implementation of sendto_channel_local_with_capability and sendto_channel_local_with_capability_butone
718 _sendto_channel_local_with_capability_butone(struct Client
*one
, int type
, int caps
, int negcaps
, struct Channel
*chptr
,
719 const char *pattern
, va_list * args
)
722 struct membership
*msptr
;
723 struct Client
*target_p
;
725 rb_dlink_node
*next_ptr
;
727 rb_linebuf_newbuf(&linebuf
);
728 rb_linebuf_putmsg(&linebuf
, pattern
, args
, NULL
);
730 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
733 target_p
= msptr
->client_p
;
738 if(IsIOError(target_p
) ||
739 !IsCapable(target_p
, caps
) ||
740 !NotCapable(target_p
, negcaps
))
743 if(type
&& ((msptr
->flags
& type
) == 0))
746 _send_linebuf(target_p
, &linebuf
);
749 rb_linebuf_donebuf(&linebuf
);
752 /* sendto_channel_local_with_capability()
754 * inputs - flags to send to, caps, negate caps, channel to send to, va_args
755 * outputs - message to local channel members
759 sendto_channel_local_with_capability(int type
, int caps
, int negcaps
, struct Channel
*chptr
, const char *pattern
, ...)
763 va_start(args
, pattern
);
764 _sendto_channel_local_with_capability_butone(NULL
, type
, caps
, negcaps
, chptr
, pattern
, &args
);
769 /* sendto_channel_local_with_capability()
771 * inputs - flags to send to, caps, negate caps, channel to send to, va_args
772 * outputs - message to local channel members
776 sendto_channel_local_with_capability_butone(struct Client
*one
, int type
, int caps
, int negcaps
, struct Channel
*chptr
,
777 const char *pattern
, ...)
781 va_start(args
, pattern
);
782 _sendto_channel_local_with_capability_butone(one
, type
, caps
, negcaps
, chptr
, pattern
, &args
);
787 /* sendto_channel_local_butone()
789 * inputs - flags to send to, channel to send to, va_args
790 * - user to ignore when sending
791 * outputs - message to local channel members
795 sendto_channel_local_butone(struct Client
*one
, int type
, struct Channel
*chptr
, const char *pattern
, ...)
799 struct membership
*msptr
;
800 struct Client
*target_p
;
801 struct MsgBuf msgbuf
;
803 rb_dlink_node
*next_ptr
;
805 rb_linebuf_newbuf(&linebuf
);
807 build_msgbuf_from(&msgbuf
, one
, NULL
);
809 va_start(args
, pattern
);
810 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
813 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
816 target_p
= msptr
->client_p
;
821 if(IsIOError(target_p
))
824 if(type
&& ((msptr
->flags
& type
) == 0))
827 /* attach the present linebuf to the target */
828 _send_linebuf(target_p
, &linebuf
);
831 rb_linebuf_donebuf(&linebuf
);
835 * sendto_common_channels_local()
837 * inputs - pointer to client
839 * - negated capability mask
842 * side effects - Sends a message to all people on local server who are
843 * in same channel with user.
844 * used by m_nick.c and exit_one_client.
847 sendto_common_channels_local(struct Client
*user
, int cap
, int negcap
, const char *pattern
, ...)
851 rb_dlink_node
*next_ptr
;
853 rb_dlink_node
*next_uptr
;
854 struct Channel
*chptr
;
855 struct Client
*target_p
;
856 struct membership
*msptr
;
857 struct membership
*mscptr
;
860 rb_linebuf_newbuf(&linebuf
);
861 va_start(args
, pattern
);
862 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
867 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
870 chptr
= mscptr
->chptr
;
872 RB_DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
875 target_p
= msptr
->client_p
;
877 if(IsIOError(target_p
) ||
878 target_p
->serial
== current_serial
||
879 !IsCapable(target_p
, cap
) ||
880 !NotCapable(target_p
, negcap
))
883 target_p
->serial
= current_serial
;
884 send_linebuf(target_p
, &linebuf
);
888 /* this can happen when the user isnt in any channels, but we still
889 * need to send them the data, ie a nick change
891 if(MyConnect(user
) && (user
->serial
!= current_serial
))
892 send_linebuf(user
, &linebuf
);
894 rb_linebuf_donebuf(&linebuf
);
898 * sendto_common_channels_local_butone()
900 * inputs - pointer to client
902 * - negated capability mask
905 * side effects - Sends a message to all people on local server who are
906 * in same channel with user, except for user itself.
909 sendto_common_channels_local_butone(struct Client
*user
, int cap
, int negcap
, const char *pattern
, ...)
913 rb_dlink_node
*next_ptr
;
915 rb_dlink_node
*next_uptr
;
916 struct Channel
*chptr
;
917 struct Client
*target_p
;
918 struct membership
*msptr
;
919 struct membership
*mscptr
;
922 rb_linebuf_newbuf(&linebuf
);
924 va_start(args
, pattern
);
925 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
929 /* Skip them -- jilles */
930 user
->serial
= current_serial
;
932 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
935 chptr
= mscptr
->chptr
;
937 RB_DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
940 target_p
= msptr
->client_p
;
942 if(IsIOError(target_p
) ||
943 target_p
->serial
== current_serial
||
944 !IsCapable(target_p
, cap
) ||
945 !NotCapable(target_p
, negcap
))
948 target_p
->serial
= current_serial
;
949 send_linebuf(target_p
, &linebuf
);
953 rb_linebuf_donebuf(&linebuf
);
956 /* sendto_match_butone()
958 * inputs - server not to send to, source, mask, type of mask, va_args
960 * side effects - message is sent to matching clients
963 sendto_match_butone(struct Client
*one
, struct Client
*source_p
,
964 const char *mask
, int what
, const char *pattern
, ...)
966 static char buf
[BUFSIZE
];
968 struct Client
*target_p
;
970 rb_dlink_node
*next_ptr
;
971 buf_head_t rb_linebuf_local
;
972 buf_head_t rb_linebuf_id
;
974 rb_linebuf_newbuf(&rb_linebuf_local
);
975 rb_linebuf_newbuf(&rb_linebuf_id
);
977 va_start(args
, pattern
);
978 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
981 if(IsServer(source_p
))
982 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
983 ":%s %s", source_p
->name
, buf
);
985 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
987 source_p
->name
, source_p
->username
,
988 source_p
->host
, buf
);
990 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
992 if(what
== MATCH_HOST
)
994 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
996 target_p
= ptr
->data
;
998 if(match(mask
, target_p
->host
))
999 _send_linebuf(target_p
, &rb_linebuf_local
);
1002 /* what = MATCH_SERVER, if it doesnt match us, just send remote */
1003 else if(match(mask
, me
.name
))
1005 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
1007 target_p
= ptr
->data
;
1008 _send_linebuf(target_p
, &rb_linebuf_local
);
1012 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
1014 target_p
= ptr
->data
;
1019 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_id
);
1022 rb_linebuf_donebuf(&rb_linebuf_local
);
1023 rb_linebuf_donebuf(&rb_linebuf_id
);
1026 /* sendto_match_servs()
1028 * inputs - source, mask to send to, caps needed, va_args
1030 * side effects - message is sent to matching servers with caps.
1033 sendto_match_servs(struct Client
*source_p
, const char *mask
, int cap
,
1034 int nocap
, const char *pattern
, ...)
1036 static char buf
[BUFSIZE
];
1039 struct Client
*target_p
;
1040 buf_head_t rb_linebuf_id
;
1042 if(EmptyString(mask
))
1045 rb_linebuf_newbuf(&rb_linebuf_id
);
1047 va_start(args
, pattern
);
1048 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1051 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
,
1052 ":%s %s", use_id(source_p
), buf
);
1056 RB_DLINK_FOREACH(ptr
, global_serv_list
.head
)
1058 target_p
= ptr
->data
;
1060 /* dont send to ourselves, or back to where it came from.. */
1061 if(IsMe(target_p
) || target_p
->from
== source_p
->from
)
1064 if(target_p
->from
->serial
== current_serial
)
1067 if(match(mask
, target_p
->name
))
1069 /* if we set the serial here, then we'll never do
1070 * a match() again if !IsCapable()
1072 target_p
->from
->serial
= current_serial
;
1074 if(cap
&& !IsCapable(target_p
->from
, cap
))
1077 if(nocap
&& !NotCapable(target_p
->from
, nocap
))
1080 _send_linebuf(target_p
->from
, &rb_linebuf_id
);
1084 rb_linebuf_donebuf(&rb_linebuf_id
);
1087 /* sendto_local_clients_with_capability()
1089 * inputs - caps needed, pattern, va_args
1091 * side effects - message is sent to matching local clients with caps.
1094 sendto_local_clients_with_capability(int cap
, const char *pattern
, ...)
1098 struct Client
*target_p
;
1101 rb_linebuf_newbuf(&linebuf
);
1103 va_start(args
, pattern
);
1104 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
1107 RB_DLINK_FOREACH(ptr
, lclient_list
.head
)
1109 target_p
= ptr
->data
;
1111 if(IsIOError(target_p
) || !IsCapable(target_p
, cap
))
1114 send_linebuf(target_p
, &linebuf
);
1117 rb_linebuf_donebuf(&linebuf
);
1122 * inputs - monitor nick to send to, format, va_args
1123 * outputs - message to local users monitoring the given nick
1127 sendto_monitor(struct monitor
*monptr
, const char *pattern
, ...)
1131 struct Client
*target_p
;
1133 rb_dlink_node
*next_ptr
;
1135 rb_linebuf_newbuf(&linebuf
);
1137 va_start(args
, pattern
);
1138 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
1141 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, monptr
->users
.head
)
1143 target_p
= ptr
->data
;
1145 if(IsIOError(target_p
))
1148 _send_linebuf(target_p
, &linebuf
);
1151 rb_linebuf_donebuf(&linebuf
);
1154 /* sendto_anywhere()
1156 * inputs - target, source, va_args
1158 * side effects - client is sent message with correct prefix.
1161 sendto_anywhere(struct Client
*target_p
, struct Client
*source_p
,
1162 const char *command
, const char *pattern
, ...)
1167 rb_linebuf_newbuf(&linebuf
);
1169 va_start(args
, pattern
);
1171 if(MyClient(target_p
))
1173 if(IsServer(source_p
))
1174 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
1175 source_p
->name
, command
,
1179 struct MsgBuf msgbuf
;
1181 build_msgbuf_from(&msgbuf
, source_p
, command
);
1182 msgbuf
.target
= target_p
->name
;
1184 linebuf_put_msgvbuf(&msgbuf
, &linebuf
, target_p
->localClient
->caps
, pattern
, &args
);
1188 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
1189 get_id(source_p
, target_p
), command
,
1190 get_id(target_p
, target_p
));
1193 if(MyClient(target_p
))
1194 _send_linebuf(target_p
, &linebuf
);
1196 send_linebuf_remote(target_p
, source_p
, &linebuf
);
1198 rb_linebuf_donebuf(&linebuf
);
1201 /* sendto_realops_snomask()
1203 * inputs - snomask needed, level (opers/admin), va_args
1205 * side effects - message is sent to opers with matching snomasks
1208 sendto_realops_snomask(int flags
, int level
, const char *pattern
, ...)
1210 static char buf
[BUFSIZE
];
1212 struct Client
*client_p
;
1214 rb_dlink_node
*next_ptr
;
1218 rb_linebuf_newbuf(&linebuf
);
1220 /* Be very sure not to do things like "Trying to send to myself"
1221 * L_NETWIDE, otherwise infinite recursion may result! -- jilles */
1222 if (level
& L_NETWIDE
&& ConfigFileEntry
.global_snotices
)
1224 /* rather a lot of copying around, oh well -- jilles */
1225 va_start(args
, pattern
);
1226 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1228 rb_linebuf_putmsg(&linebuf
, pattern
, NULL
,
1229 ":%s NOTICE * :*** Notice -- %s", me
.name
, buf
);
1230 snobuf
= construct_snobuf(flags
);
1231 if (snobuf
[1] != '\0')
1232 sendto_server(NULL
, NULL
, CAP_ENCAP
|CAP_TS6
, NOCAPS
,
1233 ":%s ENCAP * SNOTE %c :%s",
1234 me
.id
, snobuf
[1], buf
);
1236 else if (remote_rehash_oper_p
!= NULL
)
1238 /* rather a lot of copying around, oh well -- jilles */
1239 va_start(args
, pattern
);
1240 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1242 rb_linebuf_putmsg(&linebuf
, pattern
, NULL
,
1243 ":%s NOTICE * :*** Notice -- %s", me
.name
, buf
);
1244 sendto_one_notice(remote_rehash_oper_p
, ":*** Notice -- %s", buf
);
1248 va_start(args
, pattern
);
1249 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1250 ":%s NOTICE * :*** Notice -- ", me
.name
);
1253 level
&= ~L_NETWIDE
;
1255 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1257 client_p
= ptr
->data
;
1259 /* If we're sending it to opers and theyre an admin, skip.
1260 * If we're sending it to admins, and theyre not, skip.
1262 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1263 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1266 if(client_p
->snomask
& flags
)
1267 _send_linebuf(client_p
, &linebuf
);
1270 rb_linebuf_donebuf(&linebuf
);
1272 /* sendto_realops_snomask_from()
1274 * inputs - snomask needed, level (opers/admin), source server, va_args
1276 * side effects - message is sent to opers with matching snomask
1279 sendto_realops_snomask_from(int flags
, int level
, struct Client
*source_p
,
1280 const char *pattern
, ...)
1282 struct Client
*client_p
;
1284 rb_dlink_node
*next_ptr
;
1288 rb_linebuf_newbuf(&linebuf
);
1290 va_start(args
, pattern
);
1291 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1292 ":%s NOTICE * :*** Notice -- ", source_p
->name
);
1295 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1297 client_p
= ptr
->data
;
1299 /* If we're sending it to opers and theyre an admin, skip.
1300 * If we're sending it to admins, and theyre not, skip.
1302 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1303 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1306 if(client_p
->snomask
& flags
)
1307 _send_linebuf(client_p
, &linebuf
);
1310 rb_linebuf_donebuf(&linebuf
);
1314 * sendto_wallops_flags
1316 * inputs - flag types of messages to show to real opers
1317 * - client sending request
1318 * - var args input message
1320 * side effects - Send a wallops to local opers
1323 sendto_wallops_flags(int flags
, struct Client
*source_p
, const char *pattern
, ...)
1325 struct Client
*client_p
;
1327 rb_dlink_node
*next_ptr
;
1331 rb_linebuf_newbuf(&linebuf
);
1333 va_start(args
, pattern
);
1335 if(IsPerson(source_p
))
1336 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1337 ":%s!%s@%s WALLOPS :", source_p
->name
,
1338 source_p
->username
, source_p
->host
);
1340 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s WALLOPS :", source_p
->name
);
1344 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, IsPerson(source_p
) && flags
== UMODE_WALLOP
? lclient_list
.head
: local_oper_list
.head
)
1346 client_p
= ptr
->data
;
1348 if(client_p
->umodes
& flags
)
1349 _send_linebuf(client_p
, &linebuf
);
1352 rb_linebuf_donebuf(&linebuf
);
1357 * input - client to send kill to, client to kill, va_args
1359 * side effects - we issue a kill for the client
1362 kill_client(struct Client
*target_p
, struct Client
*diedie
, const char *pattern
, ...)
1367 rb_linebuf_newbuf(&linebuf
);
1369 va_start(args
, pattern
);
1370 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s KILL %s :",
1371 get_id(&me
, target_p
), get_id(diedie
, target_p
));
1374 send_linebuf(target_p
, &linebuf
);
1375 rb_linebuf_donebuf(&linebuf
);
1380 * kill_client_serv_butone
1382 * inputs - pointer to client to not send to
1383 * - pointer to client to kill
1385 * side effects - Send a KILL for the given client
1386 * message to all connected servers
1387 * except the client 'one'. Also deal with
1388 * client being unknown to leaf, as in lazylink...
1391 kill_client_serv_butone(struct Client
*one
, struct Client
*target_p
, const char *pattern
, ...)
1393 static char buf
[BUFSIZE
];
1395 struct Client
*client_p
;
1397 rb_dlink_node
*next_ptr
;
1398 buf_head_t rb_linebuf_id
;
1400 rb_linebuf_newbuf(&rb_linebuf_id
);
1402 va_start(args
, pattern
);
1403 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1406 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s KILL %s :%s",
1407 use_id(&me
), use_id(target_p
), buf
);
1409 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
1411 client_p
= ptr
->data
;
1413 /* ok, if the client we're supposed to not send to has an
1414 * ID, then we still want to issue the kill there..
1416 if(one
!= NULL
&& (client_p
== one
->from
) &&
1417 (!has_id(client_p
) || !has_id(target_p
)))
1420 _send_linebuf(client_p
, &rb_linebuf_id
);
1423 rb_linebuf_donebuf(&rb_linebuf_id
);