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"
43 #define LOG_BUFSIZE 2048
45 /* send the message to the link the target is attached to */
46 #define send_linebuf(a,b) _send_linebuf((a->from ? a->from : a) ,b)
48 static void send_queued_write(rb_fde_t
*F
, void *data
);
50 unsigned long current_serial
= 0L;
52 struct Client
*remote_rehash_oper_p
;
56 * inputs - client to send to, linebuf to attach
58 * side effects - linebuf is attached to client
61 _send_linebuf(struct Client
*to
, buf_head_t
*linebuf
)
65 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send message to myself!");
69 if(!MyConnect(to
) || IsIOError(to
))
72 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > get_sendq(to
))
76 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
77 "Max SendQ limit exceeded for %s: %u > %lu",
79 rb_linebuf_len(&to
->localClient
->buf_sendq
),
82 ilog(L_SERVER
, "Max SendQ limit exceeded for %s: %u > %lu",
83 log_client_name(to
, SHOW_IP
),
84 rb_linebuf_len(&to
->localClient
->buf_sendq
),
89 to
->flags
|= FLAGS_SENDQEX
;
96 /* just attach the linebuf to the sendq instead of
97 * generating a new one
99 rb_linebuf_attach(&to
->localClient
->buf_sendq
, linebuf
);
103 ** Update statistics. The following is slightly incorrect
104 ** because it counts messages even if queued, but bytes
105 ** only really sent. Queued bytes get updated in SendQueued.
107 to
->localClient
->sendM
+= 1;
108 me
.localClient
->sendM
+= 1;
109 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > 0)
114 /* send_linebuf_remote()
116 * inputs - client to attach to, sender, linebuf
118 * side effects - client has linebuf attached
121 send_linebuf_remote(struct Client
*to
, struct Client
*from
, buf_head_t
*linebuf
)
126 /* we assume the caller has already tested for fake direction */
128 _send_linebuf(to
, linebuf
);
132 /* send_queued_write()
134 * inputs - fd to have queue sent, client we're sending to
135 * outputs - contents of queue
136 * side effects - write is rescheduled if queue isnt emptied
139 send_queued(struct Client
*to
)
142 #ifdef USE_IODEBUG_HOOKS
145 rb_fde_t
*F
= to
->localClient
->F
;
149 /* cant write anything to a dead socket. */
153 /* Something wants us to not send anything currently */
157 /* try to flush later when the write event resets this */
161 #ifdef USE_IODEBUG_HOOKS
163 if(to
->localClient
->buf_sendq
.list
.head
)
164 hd
.arg1
= ((buf_line_t
*) to
->localClient
->buf_sendq
.list
.head
->data
)->buf
+
165 to
->localClient
->buf_sendq
.writeofs
;
168 if(rb_linebuf_len(&to
->localClient
->buf_sendq
))
171 rb_linebuf_flush(F
, &to
->localClient
->buf_sendq
)) > 0)
173 /* We have some data written .. update counters */
174 #ifdef USE_IODEBUG_HOOKS
176 call_hook(h_iosend_id
, &hd
);
178 if(to
->localClient
->buf_sendq
.list
.head
)
180 ((buf_line_t
*) to
->localClient
->buf_sendq
.list
.head
->
181 data
)->buf
+ to
->localClient
->buf_sendq
.writeofs
;
187 to
->localClient
->sendB
+= retlen
;
188 me
.localClient
->sendB
+= retlen
;
189 if(to
->localClient
->sendB
> 1023)
191 to
->localClient
->sendK
+= (to
->localClient
->sendB
>> 10);
192 to
->localClient
->sendB
&= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */
194 else if(me
.localClient
->sendB
> 1023)
196 me
.localClient
->sendK
+= (me
.localClient
->sendB
>> 10);
197 me
.localClient
->sendB
&= 0x03ff;
201 if(retlen
== 0 || (retlen
< 0 && !rb_ignore_errno(errno
)))
208 if(rb_linebuf_len(&to
->localClient
->buf_sendq
))
211 rb_setselect(to
->localClient
->F
, RB_SELECT_WRITE
,
212 send_queued_write
, to
);
219 send_pop_queue(struct Client
*to
)
223 if(!MyConnect(to
) || IsIOError(to
))
225 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > 0)
229 /* send_queued_write()
231 * inputs - fd to have queue sent, client we're sending to
232 * outputs - contents of queue
233 * side effects - write is scheduled if queue isnt emptied
236 send_queued_write(rb_fde_t
*F
, void *data
)
238 struct Client
*to
= data
;
245 * inputs - client to send to, va_args
246 * outputs - client has message put into its queue
250 sendto_one(struct Client
*target_p
, const char *pattern
, ...)
255 /* send remote if to->from non NULL */
256 if(target_p
->from
!= NULL
)
257 target_p
= target_p
->from
;
259 if(IsIOError(target_p
))
262 rb_linebuf_newbuf(&linebuf
);
264 va_start(args
, pattern
);
265 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
268 _send_linebuf(target_p
, &linebuf
);
270 rb_linebuf_donebuf(&linebuf
);
274 /* sendto_one_prefix()
276 * inputs - client to send to, va_args
277 * outputs - client has message put into its queue
278 * side effects - source(us)/target is chosen based on TS6 capability
281 sendto_one_prefix(struct Client
*target_p
, struct Client
*source_p
,
282 const char *command
, const char *pattern
, ...)
284 struct Client
*dest_p
;
288 /* send remote if to->from non NULL */
289 if(target_p
->from
!= NULL
)
290 dest_p
= target_p
->from
;
294 if(IsIOError(dest_p
))
299 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
303 rb_linebuf_newbuf(&linebuf
);
304 va_start(args
, pattern
);
305 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
307 get_id(source_p
, target_p
),
308 command
, get_id(target_p
, target_p
));
311 _send_linebuf(dest_p
, &linebuf
);
312 rb_linebuf_donebuf(&linebuf
);
315 /* sendto_one_notice()
317 * inputs - client to send to, va_args
318 * outputs - client has a NOTICE put into its queue
319 * side effects - source(us)/target is chosen based on TS6 capability
322 sendto_one_notice(struct Client
*target_p
, const char *pattern
, ...)
324 struct Client
*dest_p
;
329 /* send remote if to->from non NULL */
330 if(target_p
->from
!= NULL
)
331 dest_p
= target_p
->from
;
335 if(IsIOError(dest_p
))
340 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
344 rb_linebuf_newbuf(&linebuf
);
345 va_start(args
, pattern
);
346 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
348 get_id(&me
, target_p
), *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
351 _send_linebuf(dest_p
, &linebuf
);
352 rb_linebuf_donebuf(&linebuf
);
356 /* sendto_one_numeric()
358 * inputs - client to send to, va_args
359 * outputs - client has message put into its queue
360 * side effects - source/target is chosen based on TS6 capability
363 sendto_one_numeric(struct Client
*target_p
, int numeric
, const char *pattern
, ...)
365 struct Client
*dest_p
;
370 /* send remote if to->from non NULL */
371 if(target_p
->from
!= NULL
)
372 dest_p
= target_p
->from
;
376 if(IsIOError(dest_p
))
381 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
385 rb_linebuf_newbuf(&linebuf
);
386 va_start(args
, pattern
);
387 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
389 get_id(&me
, target_p
),
390 numeric
, *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
393 _send_linebuf(dest_p
, &linebuf
);
394 rb_linebuf_donebuf(&linebuf
);
400 * inputs - pointer to client to NOT send to
401 * - caps or'd together which must ALL be present
402 * - caps or'd together which must ALL NOT be present
403 * - printf style format string
404 * - args to format string
406 * side effects - Send a message to all connected servers, except the
407 * client 'one' (if non-NULL), as long as the servers
408 * support ALL capabs in 'caps', and NO capabs in 'nocaps'.
410 * This function was written in an attempt to merge together the other
411 * billion sendto_*serv*() functions, which sprung up with capabs, uids etc
415 sendto_server(struct Client
*one
, struct Channel
*chptr
, unsigned long caps
,
416 unsigned long nocaps
, const char *format
, ...)
419 struct Client
*target_p
;
421 rb_dlink_node
*next_ptr
;
424 /* noone to send to.. */
425 if(rb_dlink_list_length(&serv_list
) == 0)
428 if(chptr
!= NULL
&& *chptr
->chname
!= '#')
431 rb_linebuf_newbuf(&linebuf
);
432 va_start(args
, format
);
433 rb_linebuf_putmsg(&linebuf
, format
, &args
, NULL
);
436 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
438 target_p
= ptr
->data
;
440 /* check against 'one' */
441 if(one
!= NULL
&& (target_p
== one
->from
))
444 /* check we have required capabs */
445 if(!IsCapable(target_p
, caps
))
448 /* check we don't have any forbidden capabs */
449 if(!NotCapable(target_p
, nocaps
))
452 _send_linebuf(target_p
, &linebuf
);
455 rb_linebuf_donebuf(&linebuf
);
459 /* sendto_channel_flags()
461 * inputs - server not to send to, flags needed, source, channel, va_args
462 * outputs - message is sent to channel members
466 sendto_channel_flags(struct Client
*one
, int type
, struct Client
*source_p
,
467 struct Channel
*chptr
, const char *pattern
, ...)
469 static char buf
[BUFSIZE
];
471 buf_head_t rb_linebuf_local
;
472 buf_head_t rb_linebuf_id
;
473 struct Client
*target_p
;
474 struct membership
*msptr
;
476 rb_dlink_node
*next_ptr
;
478 rb_linebuf_newbuf(&rb_linebuf_local
);
479 rb_linebuf_newbuf(&rb_linebuf_id
);
483 va_start(args
, pattern
);
484 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
487 if(IsServer(source_p
))
488 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
489 ":%s %s", source_p
->name
, buf
);
491 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
493 source_p
->name
, source_p
->username
,
494 source_p
->host
, buf
);
496 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
498 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->members
.head
)
501 target_p
= msptr
->client_p
;
503 if(IsIOError(target_p
->from
) || target_p
->from
== one
)
506 if(type
&& ((msptr
->flags
& type
) == 0))
512 if(!MyClient(target_p
))
514 /* if we've got a specific type, target must support
517 if(type
&& NotCapable(target_p
->from
, CAP_CHW
))
520 if(target_p
->from
->serial
!= current_serial
)
522 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_id
);
523 target_p
->from
->serial
= current_serial
;
527 _send_linebuf(target_p
, &rb_linebuf_local
);
530 rb_linebuf_donebuf(&rb_linebuf_local
);
531 rb_linebuf_donebuf(&rb_linebuf_id
);
534 /* sendto_channel_flags()
536 * inputs - server not to send to, flags needed, source, channel, va_args
537 * outputs - message is sent to channel members
541 sendto_channel_opmod(struct Client
*one
, struct Client
*source_p
,
542 struct Channel
*chptr
, const char *command
,
545 buf_head_t rb_linebuf_local
;
546 buf_head_t rb_linebuf_old
;
547 buf_head_t rb_linebuf_new
;
548 struct Client
*target_p
;
549 struct membership
*msptr
;
551 rb_dlink_node
*next_ptr
;
553 rb_linebuf_newbuf(&rb_linebuf_local
);
554 rb_linebuf_newbuf(&rb_linebuf_old
);
555 rb_linebuf_newbuf(&rb_linebuf_new
);
559 if(IsServer(source_p
))
560 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
562 source_p
->name
, command
, chptr
->chname
, text
);
564 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
565 ":%s!%s@%s %s %s :%s",
566 source_p
->name
, source_p
->username
,
567 source_p
->host
, command
, chptr
->chname
, text
);
569 if (chptr
->mode
.mode
& MODE_MODERATED
)
570 rb_linebuf_putmsg(&rb_linebuf_old
, NULL
, NULL
,
572 use_id(source_p
), command
, chptr
->chname
, text
);
574 rb_linebuf_putmsg(&rb_linebuf_old
, NULL
, NULL
,
575 ":%s NOTICE @%s :<%s:%s> %s",
576 use_id(source_p
->servptr
), chptr
->chname
,
577 source_p
->name
, chptr
->chname
, text
);
578 rb_linebuf_putmsg(&rb_linebuf_new
, NULL
, NULL
,
580 use_id(source_p
), command
, chptr
->chname
, text
);
582 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->members
.head
)
585 target_p
= msptr
->client_p
;
587 if(IsIOError(target_p
->from
) || target_p
->from
== one
)
590 if((msptr
->flags
& CHFL_CHANOP
) == 0)
596 if(!MyClient(target_p
))
598 /* if we've got a specific type, target must support
601 if(NotCapable(target_p
->from
, CAP_CHW
))
604 if(target_p
->from
->serial
!= current_serial
)
606 if (IsCapable(target_p
->from
, CAP_EOPMOD
))
607 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_new
);
609 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_old
);
610 target_p
->from
->serial
= current_serial
;
614 _send_linebuf(target_p
, &rb_linebuf_local
);
617 rb_linebuf_donebuf(&rb_linebuf_local
);
618 rb_linebuf_donebuf(&rb_linebuf_old
);
619 rb_linebuf_donebuf(&rb_linebuf_new
);
622 /* sendto_channel_local()
624 * inputs - flags to send to, channel to send to, va_args
625 * outputs - message to local channel members
629 sendto_channel_local(int type
, struct Channel
*chptr
, const char *pattern
, ...)
633 struct membership
*msptr
;
634 struct Client
*target_p
;
636 rb_dlink_node
*next_ptr
;
638 rb_linebuf_newbuf(&linebuf
);
640 va_start(args
, pattern
);
641 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
644 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
647 target_p
= msptr
->client_p
;
649 if(IsIOError(target_p
))
652 if(type
&& ((msptr
->flags
& type
) == 0))
655 _send_linebuf(target_p
, &linebuf
);
658 rb_linebuf_donebuf(&linebuf
);
661 /* sendto_channel_local_butone()
663 * inputs - flags to send to, channel to send to, va_args
664 * - user to ignore when sending
665 * outputs - message to local channel members
669 sendto_channel_local_butone(struct Client
*one
, 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
;
692 if(IsIOError(target_p
))
695 if(type
&& ((msptr
->flags
& type
) == 0))
698 _send_linebuf(target_p
, &linebuf
);
701 rb_linebuf_donebuf(&linebuf
);
705 * sendto_common_channels_local()
707 * inputs - pointer to client
710 * side effects - Sends a message to all people on local server who are
711 * in same channel with user.
712 * used by m_nick.c and exit_one_client.
715 sendto_common_channels_local(struct Client
*user
, const char *pattern
, ...)
719 rb_dlink_node
*next_ptr
;
721 rb_dlink_node
*next_uptr
;
722 struct Channel
*chptr
;
723 struct Client
*target_p
;
724 struct membership
*msptr
;
725 struct membership
*mscptr
;
728 rb_linebuf_newbuf(&linebuf
);
729 va_start(args
, pattern
);
730 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
735 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
738 chptr
= mscptr
->chptr
;
740 RB_DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
743 target_p
= msptr
->client_p
;
745 if(IsIOError(target_p
) ||
746 target_p
->serial
== current_serial
)
749 target_p
->serial
= current_serial
;
750 send_linebuf(target_p
, &linebuf
);
754 /* this can happen when the user isnt in any channels, but we still
755 * need to send them the data, ie a nick change
757 if(MyConnect(user
) && (user
->serial
!= current_serial
))
758 send_linebuf(user
, &linebuf
);
760 rb_linebuf_donebuf(&linebuf
);
764 * sendto_common_channels_local_with_capability()
766 * inputs - pointer to client
770 * side effects - Sends a message to all people on local server who are
771 * in same channel with user.
772 * used by m_nick.c and exit_one_client.
775 sendto_common_channels_local_with_capability(struct Client
*user
, int capability
, const char *pattern
, ...)
779 rb_dlink_node
*next_ptr
;
781 rb_dlink_node
*next_uptr
;
782 struct Channel
*chptr
;
783 struct Client
*target_p
;
784 struct membership
*msptr
;
785 struct membership
*mscptr
;
788 rb_linebuf_newbuf(&linebuf
);
789 va_start(args
, pattern
);
790 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
795 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
798 chptr
= mscptr
->chptr
;
800 RB_DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
803 target_p
= msptr
->client_p
;
805 if(!IsCapable(target_p
, capability
))
808 if(IsIOError(target_p
) ||
809 target_p
->serial
== current_serial
)
812 target_p
->serial
= current_serial
;
813 send_linebuf(target_p
, &linebuf
);
817 /* this can happen when the user isnt in any channels, but we still
818 * need to send them the data, ie a nick change
820 if(MyConnect(user
) && (user
->serial
!= current_serial
) && IsCapable(user
, capability
))
821 send_linebuf(user
, &linebuf
);
823 rb_linebuf_donebuf(&linebuf
);
827 * sendto_common_channels_local_butone()
829 * inputs - pointer to client
832 * side effects - Sends a message to all people on local server who are
833 * in same channel with user, except for user itself.
836 sendto_common_channels_local_butone(struct Client
*user
, const char *pattern
, ...)
840 rb_dlink_node
*next_ptr
;
842 rb_dlink_node
*next_uptr
;
843 struct Channel
*chptr
;
844 struct Client
*target_p
;
845 struct membership
*msptr
;
846 struct membership
*mscptr
;
849 rb_linebuf_newbuf(&linebuf
);
850 va_start(args
, pattern
);
851 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
855 /* Skip them -- jilles */
856 user
->serial
= current_serial
;
858 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
861 chptr
= mscptr
->chptr
;
863 RB_DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
866 target_p
= msptr
->client_p
;
868 if(IsIOError(target_p
) ||
869 target_p
->serial
== current_serial
)
872 target_p
->serial
= current_serial
;
873 send_linebuf(target_p
, &linebuf
);
877 rb_linebuf_donebuf(&linebuf
);
881 * sendto_common_channels_local_with_capability_butone()
883 * inputs - pointer to client
887 * side effects - Sends a message to all people on local server who are
888 * in same channel with user, except the user themselves.
889 * used by m_nick.c and exit_one_client.
892 sendto_common_channels_local_with_capability_butone(struct Client
*user
, int capability
, const char *pattern
, ...)
896 rb_dlink_node
*next_ptr
;
898 rb_dlink_node
*next_uptr
;
899 struct Channel
*chptr
;
900 struct Client
*target_p
;
901 struct membership
*msptr
;
902 struct membership
*mscptr
;
905 rb_linebuf_newbuf(&linebuf
);
906 va_start(args
, pattern
);
907 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
911 /* Skip them -- jilles */
912 user
->serial
= current_serial
;
914 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
917 chptr
= mscptr
->chptr
;
919 RB_DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
922 target_p
= msptr
->client_p
;
924 if(!IsCapable(target_p
, capability
))
927 if(IsIOError(target_p
) ||
928 target_p
->serial
== current_serial
)
931 target_p
->serial
= current_serial
;
932 send_linebuf(target_p
, &linebuf
);
936 /* this can happen when the user isnt in any channels, but we still
937 * need to send them the data, ie a nick change
939 if(MyConnect(user
) && (user
->serial
!= current_serial
) && IsCapable(user
, capability
))
940 send_linebuf(user
, &linebuf
);
942 rb_linebuf_donebuf(&linebuf
);
946 /* sendto_match_butone()
948 * inputs - server not to send to, source, mask, type of mask, va_args
950 * side effects - message is sent to matching clients
953 sendto_match_butone(struct Client
*one
, struct Client
*source_p
,
954 const char *mask
, int what
, const char *pattern
, ...)
956 static char buf
[BUFSIZE
];
958 struct Client
*target_p
;
960 rb_dlink_node
*next_ptr
;
961 buf_head_t rb_linebuf_local
;
962 buf_head_t rb_linebuf_id
;
964 rb_linebuf_newbuf(&rb_linebuf_local
);
965 rb_linebuf_newbuf(&rb_linebuf_id
);
967 va_start(args
, pattern
);
968 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
971 if(IsServer(source_p
))
972 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
973 ":%s %s", source_p
->name
, buf
);
975 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
977 source_p
->name
, source_p
->username
,
978 source_p
->host
, buf
);
980 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
982 if(what
== MATCH_HOST
)
984 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
986 target_p
= ptr
->data
;
988 if(match(mask
, target_p
->host
))
989 _send_linebuf(target_p
, &rb_linebuf_local
);
992 /* what = MATCH_SERVER, if it doesnt match us, just send remote */
993 else if(match(mask
, me
.name
))
995 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
997 target_p
= ptr
->data
;
998 _send_linebuf(target_p
, &rb_linebuf_local
);
1002 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
1004 target_p
= ptr
->data
;
1009 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_id
);
1012 rb_linebuf_donebuf(&rb_linebuf_local
);
1013 rb_linebuf_donebuf(&rb_linebuf_id
);
1016 /* sendto_match_servs()
1018 * inputs - source, mask to send to, caps needed, va_args
1020 * side effects - message is sent to matching servers with caps.
1023 sendto_match_servs(struct Client
*source_p
, const char *mask
, int cap
,
1024 int nocap
, const char *pattern
, ...)
1026 static char buf
[BUFSIZE
];
1029 struct Client
*target_p
;
1030 buf_head_t rb_linebuf_id
;
1032 if(EmptyString(mask
))
1035 rb_linebuf_newbuf(&rb_linebuf_id
);
1037 va_start(args
, pattern
);
1038 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1041 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
,
1042 ":%s %s", use_id(source_p
), buf
);
1046 RB_DLINK_FOREACH(ptr
, global_serv_list
.head
)
1048 target_p
= ptr
->data
;
1050 /* dont send to ourselves, or back to where it came from.. */
1051 if(IsMe(target_p
) || target_p
->from
== source_p
->from
)
1054 if(target_p
->from
->serial
== current_serial
)
1057 if(match(mask
, target_p
->name
))
1059 /* if we set the serial here, then we'll never do
1060 * a match() again if !IsCapable()
1062 target_p
->from
->serial
= current_serial
;
1064 if(cap
&& !IsCapable(target_p
->from
, cap
))
1067 if(nocap
&& !NotCapable(target_p
->from
, nocap
))
1070 _send_linebuf(target_p
->from
, &rb_linebuf_id
);
1074 rb_linebuf_donebuf(&rb_linebuf_id
);
1079 * inputs - monitor nick to send to, format, va_args
1080 * outputs - message to local users monitoring the given nick
1084 sendto_monitor(struct monitor
*monptr
, const char *pattern
, ...)
1088 struct Client
*target_p
;
1090 rb_dlink_node
*next_ptr
;
1092 rb_linebuf_newbuf(&linebuf
);
1094 va_start(args
, pattern
);
1095 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
1098 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, monptr
->users
.head
)
1100 target_p
= ptr
->data
;
1102 if(IsIOError(target_p
))
1105 _send_linebuf(target_p
, &linebuf
);
1108 rb_linebuf_donebuf(&linebuf
);
1111 /* sendto_anywhere()
1113 * inputs - target, source, va_args
1115 * side effects - client is sent message with correct prefix.
1118 sendto_anywhere(struct Client
*target_p
, struct Client
*source_p
,
1119 const char *command
, const char *pattern
, ...)
1124 rb_linebuf_newbuf(&linebuf
);
1126 va_start(args
, pattern
);
1128 if(MyClient(target_p
))
1130 if(IsServer(source_p
))
1131 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
1132 source_p
->name
, command
,
1135 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1137 source_p
->name
, source_p
->username
,
1138 source_p
->host
, command
,
1142 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
1143 get_id(source_p
, target_p
), command
,
1144 get_id(target_p
, target_p
));
1147 if(MyClient(target_p
))
1148 _send_linebuf(target_p
, &linebuf
);
1150 send_linebuf_remote(target_p
, source_p
, &linebuf
);
1152 rb_linebuf_donebuf(&linebuf
);
1155 /* sendto_realops_snomask()
1157 * inputs - snomask needed, level (opers/admin), va_args
1159 * side effects - message is sent to opers with matching snomasks
1162 sendto_realops_snomask(int flags
, int level
, const char *pattern
, ...)
1164 static char buf
[BUFSIZE
];
1166 struct Client
*client_p
;
1168 rb_dlink_node
*next_ptr
;
1172 rb_linebuf_newbuf(&linebuf
);
1174 /* Be very sure not to do things like "Trying to send to myself"
1175 * L_NETWIDE, otherwise infinite recursion may result! -- jilles */
1176 if (level
& L_NETWIDE
&& ConfigFileEntry
.global_snotices
)
1178 /* rather a lot of copying around, oh well -- jilles */
1179 va_start(args
, pattern
);
1180 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1182 rb_linebuf_putmsg(&linebuf
, pattern
, NULL
,
1183 ":%s NOTICE * :*** Notice -- %s", me
.name
, buf
);
1184 snobuf
= construct_snobuf(flags
);
1185 if (snobuf
[1] != '\0')
1186 sendto_server(NULL
, NULL
, CAP_ENCAP
|CAP_TS6
, NOCAPS
,
1187 ":%s ENCAP * SNOTE %c :%s",
1188 me
.id
, snobuf
[1], buf
);
1190 else if (remote_rehash_oper_p
!= NULL
)
1192 /* rather a lot of copying around, oh well -- jilles */
1193 va_start(args
, pattern
);
1194 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1196 rb_linebuf_putmsg(&linebuf
, pattern
, NULL
,
1197 ":%s NOTICE * :*** Notice -- %s", me
.name
, buf
);
1198 sendto_one_notice(remote_rehash_oper_p
, ":*** Notice -- %s", buf
);
1202 va_start(args
, pattern
);
1203 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1204 ":%s NOTICE * :*** Notice -- ", me
.name
);
1207 level
&= ~L_NETWIDE
;
1209 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1211 client_p
= ptr
->data
;
1213 /* If we're sending it to opers and theyre an admin, skip.
1214 * If we're sending it to admins, and theyre not, skip.
1216 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1217 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1220 if(client_p
->snomask
& flags
)
1221 _send_linebuf(client_p
, &linebuf
);
1224 rb_linebuf_donebuf(&linebuf
);
1226 /* sendto_realops_snomask_from()
1228 * inputs - snomask needed, level (opers/admin), source server, va_args
1230 * side effects - message is sent to opers with matching snomask
1233 sendto_realops_snomask_from(int flags
, int level
, struct Client
*source_p
,
1234 const char *pattern
, ...)
1236 struct Client
*client_p
;
1238 rb_dlink_node
*next_ptr
;
1242 rb_linebuf_newbuf(&linebuf
);
1244 va_start(args
, pattern
);
1245 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1246 ":%s NOTICE * :*** Notice -- ", source_p
->name
);
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
);
1268 * sendto_wallops_flags
1270 * inputs - flag types of messages to show to real opers
1271 * - client sending request
1272 * - var args input message
1274 * side effects - Send a wallops to local opers
1277 sendto_wallops_flags(int flags
, struct Client
*source_p
, const char *pattern
, ...)
1279 struct Client
*client_p
;
1281 rb_dlink_node
*next_ptr
;
1285 rb_linebuf_newbuf(&linebuf
);
1287 va_start(args
, pattern
);
1289 if(IsPerson(source_p
))
1290 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1291 ":%s!%s@%s WALLOPS :", source_p
->name
,
1292 source_p
->username
, source_p
->host
);
1294 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s WALLOPS :", source_p
->name
);
1298 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, IsPerson(source_p
) && flags
== UMODE_WALLOP
? lclient_list
.head
: local_oper_list
.head
)
1300 client_p
= ptr
->data
;
1302 if(client_p
->umodes
& flags
)
1303 _send_linebuf(client_p
, &linebuf
);
1306 rb_linebuf_donebuf(&linebuf
);
1311 * input - client to send kill to, client to kill, va_args
1313 * side effects - we issue a kill for the client
1316 kill_client(struct Client
*target_p
, struct Client
*diedie
, const char *pattern
, ...)
1321 rb_linebuf_newbuf(&linebuf
);
1323 va_start(args
, pattern
);
1324 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s KILL %s :",
1325 get_id(&me
, target_p
), get_id(diedie
, target_p
));
1328 send_linebuf(target_p
, &linebuf
);
1329 rb_linebuf_donebuf(&linebuf
);
1334 * kill_client_serv_butone
1336 * inputs - pointer to client to not send to
1337 * - pointer to client to kill
1339 * side effects - Send a KILL for the given client
1340 * message to all connected servers
1341 * except the client 'one'. Also deal with
1342 * client being unknown to leaf, as in lazylink...
1345 kill_client_serv_butone(struct Client
*one
, struct Client
*target_p
, const char *pattern
, ...)
1347 static char buf
[BUFSIZE
];
1349 struct Client
*client_p
;
1351 rb_dlink_node
*next_ptr
;
1352 buf_head_t rb_linebuf_id
;
1354 rb_linebuf_newbuf(&rb_linebuf_id
);
1356 va_start(args
, pattern
);
1357 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1360 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s KILL %s :%s",
1361 use_id(&me
), use_id(target_p
), buf
);
1363 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
1365 client_p
= ptr
->data
;
1367 /* ok, if the client we're supposed to not send to has an
1368 * ID, then we still want to issue the kill there..
1370 if(one
!= NULL
&& (client_p
== one
->from
) &&
1371 (!has_id(client_p
) || !has_id(target_p
)))
1374 _send_linebuf(client_p
, &rb_linebuf_id
);
1377 rb_linebuf_donebuf(&rb_linebuf_id
);