2 * ircd-ratbox: A slightly useful ircd.
3 * send.c: Functions for sending messages.
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
35 #include "s_newconf.h"
41 /* send the message to the link the target is attached to */
42 #define send_linebuf(a,b) _send_linebuf((a->from ? a->from : a) ,b)
44 static void send_queued_write(rb_fde_t
*F
, void *data
);
46 unsigned long current_serial
= 0L;
48 struct Client
*remote_rehash_oper_p
;
52 * inputs - client to send to, linebuf to attach
54 * side effects - linebuf is attached to client
57 _send_linebuf(struct Client
*to
, buf_head_t
*linebuf
)
61 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send message to myself!");
65 if(!MyConnect(to
) || IsIOError(to
))
68 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > get_sendq(to
))
72 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
73 "Max SendQ limit exceeded for %s: %u > %lu",
75 rb_linebuf_len(&to
->localClient
->buf_sendq
),
78 ilog(L_SERVER
, "Max SendQ limit exceeded for %s: %u > %lu",
79 log_client_name(to
, SHOW_IP
),
80 rb_linebuf_len(&to
->localClient
->buf_sendq
),
89 /* just attach the linebuf to the sendq instead of
90 * generating a new one
92 rb_linebuf_attach(&to
->localClient
->buf_sendq
, linebuf
);
96 ** Update statistics. The following is slightly incorrect
97 ** because it counts messages even if queued, but bytes
98 ** only really sent. Queued bytes get updated in SendQueued.
100 to
->localClient
->sendM
+= 1;
101 me
.localClient
->sendM
+= 1;
102 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > 0)
107 /* send_linebuf_remote()
109 * inputs - client to attach to, sender, linebuf
111 * side effects - client has linebuf attached
114 send_linebuf_remote(struct Client
*to
, struct Client
*from
, buf_head_t
*linebuf
)
119 /* we assume the caller has already tested for fake direction */
120 _send_linebuf(to
, linebuf
);
123 /* send_queued_write()
125 * inputs - fd to have queue sent, client we're sending to
126 * outputs - contents of queue
127 * side effects - write is rescheduled if queue isnt emptied
130 send_queued(struct Client
*to
)
134 rb_fde_t
*F
= to
->localClient
->F
;
138 /* cant write anything to a dead socket. */
142 /* try to flush later when the write event resets this */
146 if(rb_linebuf_len(&to
->localClient
->buf_sendq
))
149 rb_linebuf_flush(F
, &to
->localClient
->buf_sendq
)) > 0)
151 /* We have some data written .. update counters */
154 to
->localClient
->sendB
+= retlen
;
155 me
.localClient
->sendB
+= retlen
;
156 if(to
->localClient
->sendB
> 1023)
158 to
->localClient
->sendK
+= (to
->localClient
->sendB
>> 10);
159 to
->localClient
->sendB
&= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */
161 else if(me
.localClient
->sendB
> 1023)
163 me
.localClient
->sendK
+= (me
.localClient
->sendB
>> 10);
164 me
.localClient
->sendB
&= 0x03ff;
168 if(retlen
== 0 || (retlen
< 0 && !rb_ignore_errno(errno
)))
175 if(rb_linebuf_len(&to
->localClient
->buf_sendq
))
178 rb_setselect(to
->localClient
->F
, RB_SELECT_WRITE
,
179 send_queued_write
, to
);
186 send_pop_queue(struct Client
*to
)
190 if(!MyConnect(to
) || IsIOError(to
))
192 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > 0)
196 /* send_queued_write()
198 * inputs - fd to have queue sent, client we're sending to
199 * outputs - contents of queue
200 * side effects - write is scheduled if queue isnt emptied
203 send_queued_write(rb_fde_t
*F
, void *data
)
205 struct Client
*to
= data
;
211 * linebuf_put_msgvbuf
213 * inputs - msgbuf header, linebuf object, capability mask, pattern, arguments
215 * side effects - the linebuf object is cleared, then populated using rb_linebuf_putmsg().
218 linebuf_put_msgvbuf(struct MsgBuf
*msgbuf
, buf_head_t
*linebuf
, unsigned int capmask
, const char *pattern
, va_list *va
)
222 rb_linebuf_newbuf(linebuf
);
223 msgbuf_unparse_prefix(buf
, sizeof buf
, msgbuf
, capmask
);
224 rb_linebuf_putprefix(linebuf
, pattern
, va
, buf
);
227 /* linebuf_put_msgbuf
229 * inputs - msgbuf header, linebuf object, capability mask, pattern, arguments
231 * side effects - the linebuf object is cleared, then populated using rb_linebuf_putmsg().
234 linebuf_put_msgbuf(struct MsgBuf
*msgbuf
, buf_head_t
*linebuf
, unsigned int capmask
, const char *pattern
, ...)
238 va_start(va
, pattern
);
239 linebuf_put_msgvbuf(msgbuf
, linebuf
, capmask
, pattern
, &va
);
245 * inputs - msgbuf object, client the message is from
247 * side effects - a msgbuf object is populated with an origin and relevant tags
248 * notes - to make this reentrant, find a solution for `buf` below
251 build_msgbuf_from(struct MsgBuf
*msgbuf
, struct Client
*from
, const char *cmd
)
253 static char buf
[BUFSIZE
];
258 msgbuf
->origin
= buf
;
261 if (from
!= NULL
&& IsPerson(from
))
262 snprintf(buf
, sizeof buf
, "%s!%s@%s", from
->name
, from
->username
, from
->host
);
263 else if (from
!= NULL
)
264 rb_strlcpy(buf
, from
->name
, sizeof buf
);
266 rb_strlcpy(buf
, me
.name
, sizeof buf
);
271 call_hook(h_outbound_msgbuf
, &hdata
);
276 * inputs - client to send to, va_args
277 * outputs - client has message put into its queue
281 sendto_one(struct Client
*target_p
, const char *pattern
, ...)
286 /* send remote if to->from non NULL */
287 if(target_p
->from
!= NULL
)
288 target_p
= target_p
->from
;
290 if(IsIOError(target_p
))
293 rb_linebuf_newbuf(&linebuf
);
295 va_start(args
, pattern
);
296 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
299 _send_linebuf(target_p
, &linebuf
);
301 rb_linebuf_donebuf(&linebuf
);
304 /* sendto_one_prefix()
306 * inputs - client to send to, va_args
307 * outputs - client has message put into its queue
308 * side effects - source(us)/target is chosen based on TS6 capability
311 sendto_one_prefix(struct Client
*target_p
, struct Client
*source_p
,
312 const char *command
, const char *pattern
, ...)
314 struct Client
*dest_p
;
318 /* send remote if to->from non NULL */
319 if(target_p
->from
!= NULL
)
320 dest_p
= target_p
->from
;
324 if(IsIOError(dest_p
))
329 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
333 rb_linebuf_newbuf(&linebuf
);
334 va_start(args
, pattern
);
335 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
337 get_id(source_p
, target_p
),
338 command
, get_id(target_p
, target_p
));
341 _send_linebuf(dest_p
, &linebuf
);
342 rb_linebuf_donebuf(&linebuf
);
345 /* sendto_one_notice()
347 * inputs - client to send to, va_args
348 * outputs - client has a NOTICE put into its queue
349 * side effects - source(us)/target is chosen based on TS6 capability
352 sendto_one_notice(struct Client
*target_p
, const char *pattern
, ...)
354 struct Client
*dest_p
;
359 /* send remote if to->from non NULL */
360 if(target_p
->from
!= NULL
)
361 dest_p
= target_p
->from
;
365 if(IsIOError(dest_p
))
370 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
374 rb_linebuf_newbuf(&linebuf
);
375 va_start(args
, pattern
);
376 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
378 get_id(&me
, target_p
), *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
381 _send_linebuf(dest_p
, &linebuf
);
382 rb_linebuf_donebuf(&linebuf
);
386 /* sendto_one_numeric()
388 * inputs - client to send to, va_args
389 * outputs - client has message put into its queue
390 * side effects - source/target is chosen based on TS6 capability
393 sendto_one_numeric(struct Client
*target_p
, int numeric
, const char *pattern
, ...)
395 struct Client
*dest_p
;
400 /* send remote if to->from non NULL */
401 if(target_p
->from
!= NULL
)
402 dest_p
= target_p
->from
;
406 if(IsIOError(dest_p
))
411 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
415 rb_linebuf_newbuf(&linebuf
);
416 va_start(args
, pattern
);
417 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
419 get_id(&me
, target_p
),
420 numeric
, *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
423 _send_linebuf(dest_p
, &linebuf
);
424 rb_linebuf_donebuf(&linebuf
);
430 * inputs - pointer to client to NOT send to
431 * - caps or'd together which must ALL be present
432 * - caps or'd together which must ALL NOT be present
433 * - printf style format string
434 * - args to format string
436 * side effects - Send a message to all connected servers, except the
437 * client 'one' (if non-NULL), as long as the servers
438 * support ALL capabs in 'caps', and NO capabs in 'nocaps'.
440 * This function was written in an attempt to merge together the other
441 * billion sendto_*serv*() functions, which sprung up with capabs, uids etc
445 sendto_server(struct Client
*one
, struct Channel
*chptr
, unsigned long caps
,
446 unsigned long nocaps
, const char *format
, ...)
449 struct Client
*target_p
;
451 rb_dlink_node
*next_ptr
;
454 /* noone to send to.. */
455 if(rb_dlink_list_length(&serv_list
) == 0)
458 if(chptr
!= NULL
&& *chptr
->chname
!= '#')
461 rb_linebuf_newbuf(&linebuf
);
462 va_start(args
, format
);
463 rb_linebuf_putmsg(&linebuf
, format
, &args
, NULL
);
466 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
468 target_p
= ptr
->data
;
470 /* check against 'one' */
471 if(one
!= NULL
&& (target_p
== one
->from
))
474 /* check we have required capabs */
475 if(!IsCapable(target_p
, caps
))
478 /* check we don't have any forbidden capabs */
479 if(!NotCapable(target_p
, nocaps
))
482 _send_linebuf(target_p
, &linebuf
);
485 rb_linebuf_donebuf(&linebuf
);
488 /* sendto_channel_flags()
490 * inputs - server not to send to, flags needed, source, channel, va_args
491 * outputs - message is sent to channel members
495 sendto_channel_flags(struct Client
*one
, int type
, struct Client
*source_p
,
496 struct Channel
*chptr
, const char *pattern
, ...)
500 buf_head_t rb_linebuf_local
;
501 buf_head_t rb_linebuf_id
;
502 struct Client
*target_p
;
503 struct membership
*msptr
;
505 rb_dlink_node
*next_ptr
;
506 int current_capmask
= 0;
507 struct MsgBuf msgbuf
;
509 rb_linebuf_newbuf(&rb_linebuf_local
);
510 rb_linebuf_newbuf(&rb_linebuf_id
);
514 build_msgbuf_from(&msgbuf
, source_p
, NULL
);
516 va_start(args
, pattern
);
517 vsnprintf(buf
, sizeof buf
, pattern
, args
);
520 linebuf_put_msgbuf(&msgbuf
, &rb_linebuf_local
, NOCAPS
, "%s", buf
);
521 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
523 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->members
.head
)
526 target_p
= msptr
->client_p
;
528 if(!MyClient(source_p
) && (IsIOError(target_p
->from
) || target_p
->from
== one
))
531 if(MyClient(source_p
) && !IsCapable(source_p
, CLICAP_ECHO_MESSAGE
) && target_p
== one
)
534 if(type
&& ((msptr
->flags
& type
) == 0))
540 if(!MyClient(target_p
))
542 /* if we've got a specific type, target must support
545 if(type
&& NotCapable(target_p
->from
, CAP_CHW
))
548 if(target_p
->from
->serial
!= current_serial
)
550 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_id
);
551 target_p
->from
->serial
= current_serial
;
556 if (target_p
->localClient
->caps
!= current_capmask
)
558 /* reset the linebuf */
559 rb_linebuf_donebuf(&rb_linebuf_local
);
560 rb_linebuf_newbuf(&rb_linebuf_local
);
562 /* render the new linebuf and attach it */
563 linebuf_put_msgbuf(&msgbuf
, &rb_linebuf_local
, target_p
->localClient
->caps
, "%s", buf
);
564 current_capmask
= target_p
->localClient
->caps
;
567 _send_linebuf(target_p
, &rb_linebuf_local
);
571 rb_linebuf_donebuf(&rb_linebuf_local
);
572 rb_linebuf_donebuf(&rb_linebuf_id
);
575 /* sendto_channel_flags()
577 * inputs - server not to send to, flags needed, source, channel, va_args
578 * outputs - message is sent to channel members
582 sendto_channel_opmod(struct Client
*one
, struct Client
*source_p
,
583 struct Channel
*chptr
, const char *command
,
586 buf_head_t rb_linebuf_local
;
587 buf_head_t rb_linebuf_old
;
588 buf_head_t rb_linebuf_new
;
589 struct Client
*target_p
;
590 struct membership
*msptr
;
592 rb_dlink_node
*next_ptr
;
594 rb_linebuf_newbuf(&rb_linebuf_local
);
595 rb_linebuf_newbuf(&rb_linebuf_old
);
596 rb_linebuf_newbuf(&rb_linebuf_new
);
600 if(IsServer(source_p
))
601 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
603 source_p
->name
, command
, chptr
->chname
, text
);
605 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
606 ":%s!%s@%s %s %s :%s",
607 source_p
->name
, source_p
->username
,
608 source_p
->host
, command
, chptr
->chname
, text
);
610 if (chptr
->mode
.mode
& MODE_MODERATED
)
611 rb_linebuf_putmsg(&rb_linebuf_old
, NULL
, NULL
,
613 use_id(source_p
), command
, chptr
->chname
, text
);
615 rb_linebuf_putmsg(&rb_linebuf_old
, NULL
, NULL
,
616 ":%s NOTICE @%s :<%s:%s> %s",
617 use_id(source_p
->servptr
), chptr
->chname
,
618 source_p
->name
, chptr
->chname
, text
);
619 rb_linebuf_putmsg(&rb_linebuf_new
, NULL
, NULL
,
621 use_id(source_p
), command
, chptr
->chname
, text
);
623 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->members
.head
)
626 target_p
= msptr
->client_p
;
628 if(!MyClient(source_p
) && (IsIOError(target_p
->from
) || target_p
->from
== one
))
631 if(MyClient(source_p
) && !IsCapable(source_p
, CLICAP_ECHO_MESSAGE
) && target_p
== one
)
634 if((msptr
->flags
& CHFL_CHANOP
) == 0)
640 if(!MyClient(target_p
))
642 /* if we've got a specific type, target must support
645 if(NotCapable(target_p
->from
, CAP_CHW
))
648 if(target_p
->from
->serial
!= current_serial
)
650 if (IsCapable(target_p
->from
, CAP_EOPMOD
))
651 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_new
);
653 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_old
);
654 target_p
->from
->serial
= current_serial
;
658 _send_linebuf(target_p
, &rb_linebuf_local
);
661 rb_linebuf_donebuf(&rb_linebuf_local
);
662 rb_linebuf_donebuf(&rb_linebuf_old
);
663 rb_linebuf_donebuf(&rb_linebuf_new
);
666 /* sendto_channel_local()
668 * inputs - flags to send to, channel to send to, va_args
669 * outputs - message to local channel members
673 sendto_channel_local(int type
, struct Channel
*chptr
, const char *pattern
, ...)
677 struct membership
*msptr
;
678 struct Client
*target_p
;
680 rb_dlink_node
*next_ptr
;
682 rb_linebuf_newbuf(&linebuf
);
684 va_start(args
, pattern
);
685 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
688 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
691 target_p
= msptr
->client_p
;
693 if(IsIOError(target_p
))
696 if(type
== ONLY_OPERS
)
698 if (!IsOper(target_p
))
701 else if(type
&& ((msptr
->flags
& type
) == 0))
704 _send_linebuf(target_p
, &linebuf
);
707 rb_linebuf_donebuf(&linebuf
);
711 * _sendto_channel_local_with_capability_butone()
713 * Shared implementation of sendto_channel_local_with_capability and sendto_channel_local_with_capability_butone
716 _sendto_channel_local_with_capability_butone(struct Client
*one
, int type
, int caps
, int negcaps
, struct Channel
*chptr
,
717 const char *pattern
, va_list * args
)
720 struct membership
*msptr
;
721 struct Client
*target_p
;
723 rb_dlink_node
*next_ptr
;
725 rb_linebuf_newbuf(&linebuf
);
726 rb_linebuf_putmsg(&linebuf
, pattern
, args
, NULL
);
728 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
731 target_p
= msptr
->client_p
;
736 if(IsIOError(target_p
) ||
737 !IsCapable(target_p
, caps
) ||
738 !NotCapable(target_p
, negcaps
))
741 if(type
&& ((msptr
->flags
& type
) == 0))
744 _send_linebuf(target_p
, &linebuf
);
747 rb_linebuf_donebuf(&linebuf
);
750 /* sendto_channel_local_with_capability()
752 * inputs - flags to send to, caps, negate caps, channel to send to, va_args
753 * outputs - message to local channel members
757 sendto_channel_local_with_capability(int type
, int caps
, int negcaps
, struct Channel
*chptr
, const char *pattern
, ...)
761 va_start(args
, pattern
);
762 _sendto_channel_local_with_capability_butone(NULL
, type
, caps
, negcaps
, chptr
, pattern
, &args
);
767 /* sendto_channel_local_with_capability()
769 * inputs - flags to send to, caps, negate caps, channel to send to, va_args
770 * outputs - message to local channel members
774 sendto_channel_local_with_capability_butone(struct Client
*one
, int type
, int caps
, int negcaps
, struct Channel
*chptr
,
775 const char *pattern
, ...)
779 va_start(args
, pattern
);
780 _sendto_channel_local_with_capability_butone(one
, type
, caps
, negcaps
, chptr
, pattern
, &args
);
785 /* sendto_channel_local_butone()
787 * inputs - flags to send to, channel to send to, va_args
788 * - user to ignore when sending
789 * outputs - message to local channel members
793 sendto_channel_local_butone(struct Client
*one
, int type
, struct Channel
*chptr
, const char *pattern
, ...)
797 struct membership
*msptr
;
798 struct Client
*target_p
;
799 struct MsgBuf msgbuf
;
801 rb_dlink_node
*next_ptr
;
803 rb_linebuf_newbuf(&linebuf
);
805 build_msgbuf_from(&msgbuf
, one
, NULL
);
807 va_start(args
, pattern
);
808 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
811 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
814 target_p
= msptr
->client_p
;
819 if(IsIOError(target_p
))
822 if(type
&& ((msptr
->flags
& type
) == 0))
825 /* attach the present linebuf to the target */
826 _send_linebuf(target_p
, &linebuf
);
829 rb_linebuf_donebuf(&linebuf
);
833 * sendto_common_channels_local()
835 * inputs - pointer to client
837 * - negated capability mask
840 * side effects - Sends a message to all people on local server who are
841 * in same channel with user.
842 * used by m_nick.c and exit_one_client.
845 sendto_common_channels_local(struct Client
*user
, int cap
, int negcap
, const char *pattern
, ...)
849 rb_dlink_node
*next_ptr
;
851 rb_dlink_node
*next_uptr
;
852 struct Channel
*chptr
;
853 struct Client
*target_p
;
854 struct membership
*msptr
;
855 struct membership
*mscptr
;
858 rb_linebuf_newbuf(&linebuf
);
859 va_start(args
, pattern
);
860 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
865 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
868 chptr
= mscptr
->chptr
;
870 RB_DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
873 target_p
= msptr
->client_p
;
875 if(IsIOError(target_p
) ||
876 target_p
->serial
== current_serial
||
877 !IsCapable(target_p
, cap
) ||
878 !NotCapable(target_p
, negcap
))
881 target_p
->serial
= current_serial
;
882 send_linebuf(target_p
, &linebuf
);
886 /* this can happen when the user isnt in any channels, but we still
887 * need to send them the data, ie a nick change
889 if(MyConnect(user
) && (user
->serial
!= current_serial
))
890 send_linebuf(user
, &linebuf
);
892 rb_linebuf_donebuf(&linebuf
);
896 * sendto_common_channels_local_butone()
898 * inputs - pointer to client
900 * - negated capability mask
903 * side effects - Sends a message to all people on local server who are
904 * in same channel with user, except for user itself.
907 sendto_common_channels_local_butone(struct Client
*user
, int cap
, int negcap
, const char *pattern
, ...)
911 rb_dlink_node
*next_ptr
;
913 rb_dlink_node
*next_uptr
;
914 struct Channel
*chptr
;
915 struct Client
*target_p
;
916 struct membership
*msptr
;
917 struct membership
*mscptr
;
920 rb_linebuf_newbuf(&linebuf
);
922 va_start(args
, pattern
);
923 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
927 /* Skip them -- jilles */
928 user
->serial
= current_serial
;
930 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
933 chptr
= mscptr
->chptr
;
935 RB_DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
938 target_p
= msptr
->client_p
;
940 if(IsIOError(target_p
) ||
941 target_p
->serial
== current_serial
||
942 !IsCapable(target_p
, cap
) ||
943 !NotCapable(target_p
, negcap
))
946 target_p
->serial
= current_serial
;
947 send_linebuf(target_p
, &linebuf
);
951 rb_linebuf_donebuf(&linebuf
);
954 /* sendto_match_butone()
956 * inputs - server not to send to, source, mask, type of mask, va_args
958 * side effects - message is sent to matching clients
961 sendto_match_butone(struct Client
*one
, struct Client
*source_p
,
962 const char *mask
, int what
, const char *pattern
, ...)
964 static char buf
[BUFSIZE
];
966 struct Client
*target_p
;
968 rb_dlink_node
*next_ptr
;
969 buf_head_t rb_linebuf_local
;
970 buf_head_t rb_linebuf_id
;
972 rb_linebuf_newbuf(&rb_linebuf_local
);
973 rb_linebuf_newbuf(&rb_linebuf_id
);
975 va_start(args
, pattern
);
976 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
979 if(IsServer(source_p
))
980 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
981 ":%s %s", source_p
->name
, buf
);
983 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
985 source_p
->name
, source_p
->username
,
986 source_p
->host
, buf
);
988 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
990 if(what
== MATCH_HOST
)
992 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
994 target_p
= ptr
->data
;
996 if(match(mask
, target_p
->host
))
997 _send_linebuf(target_p
, &rb_linebuf_local
);
1000 /* what = MATCH_SERVER, if it doesnt match us, just send remote */
1001 else if(match(mask
, me
.name
))
1003 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
1005 target_p
= ptr
->data
;
1006 _send_linebuf(target_p
, &rb_linebuf_local
);
1010 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
1012 target_p
= ptr
->data
;
1017 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_id
);
1020 rb_linebuf_donebuf(&rb_linebuf_local
);
1021 rb_linebuf_donebuf(&rb_linebuf_id
);
1024 /* sendto_match_servs()
1026 * inputs - source, mask to send to, caps needed, va_args
1028 * side effects - message is sent to matching servers with caps.
1031 sendto_match_servs(struct Client
*source_p
, const char *mask
, int cap
,
1032 int nocap
, const char *pattern
, ...)
1034 static char buf
[BUFSIZE
];
1037 struct Client
*target_p
;
1038 buf_head_t rb_linebuf_id
;
1040 if(EmptyString(mask
))
1043 rb_linebuf_newbuf(&rb_linebuf_id
);
1045 va_start(args
, pattern
);
1046 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1049 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
,
1050 ":%s %s", use_id(source_p
), buf
);
1054 RB_DLINK_FOREACH(ptr
, global_serv_list
.head
)
1056 target_p
= ptr
->data
;
1058 /* dont send to ourselves, or back to where it came from.. */
1059 if(IsMe(target_p
) || target_p
->from
== source_p
->from
)
1062 if(target_p
->from
->serial
== current_serial
)
1065 if(match(mask
, target_p
->name
))
1067 /* if we set the serial here, then we'll never do
1068 * a match() again if !IsCapable()
1070 target_p
->from
->serial
= current_serial
;
1072 if(cap
&& !IsCapable(target_p
->from
, cap
))
1075 if(nocap
&& !NotCapable(target_p
->from
, nocap
))
1078 _send_linebuf(target_p
->from
, &rb_linebuf_id
);
1082 rb_linebuf_donebuf(&rb_linebuf_id
);
1085 /* sendto_local_clients_with_capability()
1087 * inputs - caps needed, pattern, va_args
1089 * side effects - message is sent to matching local clients with caps.
1092 sendto_local_clients_with_capability(int cap
, const char *pattern
, ...)
1096 struct Client
*target_p
;
1099 rb_linebuf_newbuf(&linebuf
);
1101 va_start(args
, pattern
);
1102 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
1105 RB_DLINK_FOREACH(ptr
, lclient_list
.head
)
1107 target_p
= ptr
->data
;
1109 if(IsIOError(target_p
) || !IsCapable(target_p
, cap
))
1112 send_linebuf(target_p
, &linebuf
);
1115 rb_linebuf_donebuf(&linebuf
);
1120 * inputs - monitor nick to send to, format, va_args
1121 * outputs - message to local users monitoring the given nick
1125 sendto_monitor(struct monitor
*monptr
, const char *pattern
, ...)
1129 struct Client
*target_p
;
1131 rb_dlink_node
*next_ptr
;
1133 rb_linebuf_newbuf(&linebuf
);
1135 va_start(args
, pattern
);
1136 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
1139 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, monptr
->users
.head
)
1141 target_p
= ptr
->data
;
1143 if(IsIOError(target_p
))
1146 _send_linebuf(target_p
, &linebuf
);
1149 rb_linebuf_donebuf(&linebuf
);
1152 /* sendto_anywhere()
1154 * inputs - target, source, va_args
1156 * side effects - client is sent message with correct prefix.
1159 sendto_anywhere(struct Client
*target_p
, struct Client
*source_p
,
1160 const char *command
, const char *pattern
, ...)
1165 rb_linebuf_newbuf(&linebuf
);
1167 va_start(args
, pattern
);
1169 if(MyClient(target_p
))
1171 if(IsServer(source_p
))
1172 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
1173 source_p
->name
, command
,
1177 struct MsgBuf msgbuf
;
1179 build_msgbuf_from(&msgbuf
, source_p
, command
);
1180 msgbuf
.target
= target_p
->name
;
1182 linebuf_put_msgvbuf(&msgbuf
, &linebuf
, target_p
->localClient
->caps
, pattern
, &args
);
1186 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
1187 get_id(source_p
, target_p
), command
,
1188 get_id(target_p
, target_p
));
1191 if(MyClient(target_p
))
1192 _send_linebuf(target_p
, &linebuf
);
1194 send_linebuf_remote(target_p
, source_p
, &linebuf
);
1196 rb_linebuf_donebuf(&linebuf
);
1199 /* sendto_realops_snomask()
1201 * inputs - snomask needed, level (opers/admin), va_args
1203 * side effects - message is sent to opers with matching snomasks
1206 sendto_realops_snomask(int flags
, int level
, const char *pattern
, ...)
1208 static char buf
[BUFSIZE
];
1210 struct Client
*client_p
;
1212 rb_dlink_node
*next_ptr
;
1216 rb_linebuf_newbuf(&linebuf
);
1218 /* Be very sure not to do things like "Trying to send to myself"
1219 * L_NETWIDE, otherwise infinite recursion may result! -- jilles */
1220 if (level
& L_NETWIDE
&& ConfigFileEntry
.global_snotices
)
1222 /* rather a lot of copying around, oh well -- jilles */
1223 va_start(args
, pattern
);
1224 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1226 rb_linebuf_putmsg(&linebuf
, pattern
, NULL
,
1227 ":%s NOTICE * :*** Notice -- %s", me
.name
, buf
);
1228 snobuf
= construct_snobuf(flags
);
1229 if (snobuf
[1] != '\0')
1230 sendto_server(NULL
, NULL
, CAP_ENCAP
|CAP_TS6
, NOCAPS
,
1231 ":%s ENCAP * SNOTE %c :%s",
1232 me
.id
, snobuf
[1], buf
);
1234 else if (remote_rehash_oper_p
!= NULL
)
1236 /* rather a lot of copying around, oh well -- jilles */
1237 va_start(args
, pattern
);
1238 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1240 rb_linebuf_putmsg(&linebuf
, pattern
, NULL
,
1241 ":%s NOTICE * :*** Notice -- %s", me
.name
, buf
);
1242 sendto_one_notice(remote_rehash_oper_p
, ":*** Notice -- %s", buf
);
1246 va_start(args
, pattern
);
1247 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1248 ":%s NOTICE * :*** Notice -- ", me
.name
);
1251 level
&= ~L_NETWIDE
;
1253 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1255 client_p
= ptr
->data
;
1257 /* If we're sending it to opers and theyre an admin, skip.
1258 * If we're sending it to admins, and theyre not, skip.
1260 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1261 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1264 if(client_p
->snomask
& flags
)
1265 _send_linebuf(client_p
, &linebuf
);
1268 rb_linebuf_donebuf(&linebuf
);
1270 /* sendto_realops_snomask_from()
1272 * inputs - snomask needed, level (opers/admin), source server, va_args
1274 * side effects - message is sent to opers with matching snomask
1277 sendto_realops_snomask_from(int flags
, int level
, struct Client
*source_p
,
1278 const char *pattern
, ...)
1280 struct Client
*client_p
;
1282 rb_dlink_node
*next_ptr
;
1286 rb_linebuf_newbuf(&linebuf
);
1288 va_start(args
, pattern
);
1289 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1290 ":%s NOTICE * :*** Notice -- ", source_p
->name
);
1293 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1295 client_p
= ptr
->data
;
1297 /* If we're sending it to opers and theyre an admin, skip.
1298 * If we're sending it to admins, and theyre not, skip.
1300 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1301 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1304 if(client_p
->snomask
& flags
)
1305 _send_linebuf(client_p
, &linebuf
);
1308 rb_linebuf_donebuf(&linebuf
);
1312 * sendto_wallops_flags
1314 * inputs - flag types of messages to show to real opers
1315 * - client sending request
1316 * - var args input message
1318 * side effects - Send a wallops to local opers
1321 sendto_wallops_flags(int flags
, struct Client
*source_p
, const char *pattern
, ...)
1323 struct Client
*client_p
;
1325 rb_dlink_node
*next_ptr
;
1329 rb_linebuf_newbuf(&linebuf
);
1331 va_start(args
, pattern
);
1333 if(IsPerson(source_p
))
1334 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1335 ":%s!%s@%s WALLOPS :", source_p
->name
,
1336 source_p
->username
, source_p
->host
);
1338 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s WALLOPS :", source_p
->name
);
1342 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, IsPerson(source_p
) && flags
== UMODE_WALLOP
? lclient_list
.head
: local_oper_list
.head
)
1344 client_p
= ptr
->data
;
1346 if(client_p
->umodes
& flags
)
1347 _send_linebuf(client_p
, &linebuf
);
1350 rb_linebuf_donebuf(&linebuf
);
1355 * input - client to send kill to, client to kill, va_args
1357 * side effects - we issue a kill for the client
1360 kill_client(struct Client
*target_p
, struct Client
*diedie
, const char *pattern
, ...)
1365 rb_linebuf_newbuf(&linebuf
);
1367 va_start(args
, pattern
);
1368 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s KILL %s :",
1369 get_id(&me
, target_p
), get_id(diedie
, target_p
));
1372 send_linebuf(target_p
, &linebuf
);
1373 rb_linebuf_donebuf(&linebuf
);
1378 * kill_client_serv_butone
1380 * inputs - pointer to client to not send to
1381 * - pointer to client to kill
1383 * side effects - Send a KILL for the given client
1384 * message to all connected servers
1385 * except the client 'one'. Also deal with
1386 * client being unknown to leaf, as in lazylink...
1389 kill_client_serv_butone(struct Client
*one
, struct Client
*target_p
, const char *pattern
, ...)
1391 static char buf
[BUFSIZE
];
1393 struct Client
*client_p
;
1395 rb_dlink_node
*next_ptr
;
1396 buf_head_t rb_linebuf_id
;
1398 rb_linebuf_newbuf(&rb_linebuf_id
);
1400 va_start(args
, pattern
);
1401 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1404 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s KILL %s :%s",
1405 use_id(&me
), use_id(target_p
), buf
);
1407 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
1409 client_p
= ptr
->data
;
1411 /* ok, if the client we're supposed to not send to has an
1412 * ID, then we still want to issue the kill there..
1414 if(one
!= NULL
&& (client_p
== one
->from
) &&
1415 (!has_id(client_p
) || !has_id(target_p
)))
1418 _send_linebuf(client_p
, &rb_linebuf_id
);
1421 rb_linebuf_donebuf(&rb_linebuf_id
);