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;
54 * inputs - client to send to, linebuf to attach
56 * side effects - linebuf is attached to client
59 _send_linebuf(struct Client
*to
, buf_head_t
*linebuf
)
63 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send message to myself!");
67 if(!MyConnect(to
) || IsIOError(to
))
70 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > get_sendq(to
))
74 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
75 "Max SendQ limit exceeded for %s: %u > %lu",
76 get_server_name(to
, HIDE_IP
),
77 rb_linebuf_len(&to
->localClient
->buf_sendq
),
80 ilog(L_SERVER
, "Max SendQ limit exceeded for %s: %u > %lu",
81 log_client_name(to
, SHOW_IP
),
82 rb_linebuf_len(&to
->localClient
->buf_sendq
),
87 to
->flags
|= FLAGS_SENDQEX
;
94 /* just attach the linebuf to the sendq instead of
95 * generating a new one
97 rb_linebuf_attach(&to
->localClient
->buf_sendq
, linebuf
);
101 ** Update statistics. The following is slightly incorrect
102 ** because it counts messages even if queued, but bytes
103 ** only really sent. Queued bytes get updated in SendQueued.
105 to
->localClient
->sendM
+= 1;
106 me
.localClient
->sendM
+= 1;
107 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > 0)
112 /* send_linebuf_remote()
114 * inputs - client to attach to, sender, linebuf
116 * side effects - client has linebuf attached
119 send_linebuf_remote(struct Client
*to
, struct Client
*from
, buf_head_t
*linebuf
)
124 /* we assume the caller has already tested for fake direction */
126 _send_linebuf(to
, linebuf
);
130 /* send_queued_write()
132 * inputs - fd to have queue sent, client we're sending to
133 * outputs - contents of queue
134 * side effects - write is rescheduled if queue isnt emptied
137 send_queued(struct Client
*to
)
140 #ifdef USE_IODEBUG_HOOKS
143 rb_fde_t
*F
= to
->localClient
->F
;
147 /* cant write anything to a dead socket. */
151 /* Something wants us to not send anything currently */
155 /* try to flush later when the write event resets this */
159 #ifdef USE_IODEBUG_HOOKS
161 if(to
->localClient
->buf_sendq
.list
.head
)
162 hd
.arg1
= ((buf_line_t
*) to
->localClient
->buf_sendq
.list
.head
->data
)->buf
+
163 to
->localClient
->buf_sendq
.writeofs
;
166 if(rb_linebuf_len(&to
->localClient
->buf_sendq
))
169 rb_linebuf_flush(F
, &to
->localClient
->buf_sendq
)) > 0)
171 /* We have some data written .. update counters */
172 #ifdef USE_IODEBUG_HOOKS
174 call_hook(h_iosend_id
, &hd
);
176 if(to
->localClient
->buf_sendq
.list
.head
)
178 ((buf_line_t
*) to
->localClient
->buf_sendq
.list
.head
->
179 data
)->buf
+ to
->localClient
->buf_sendq
.writeofs
;
185 to
->localClient
->sendB
+= retlen
;
186 me
.localClient
->sendB
+= retlen
;
187 if(to
->localClient
->sendB
> 1023)
189 to
->localClient
->sendK
+= (to
->localClient
->sendB
>> 10);
190 to
->localClient
->sendB
&= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */
192 else if(me
.localClient
->sendB
> 1023)
194 me
.localClient
->sendK
+= (me
.localClient
->sendB
>> 10);
195 me
.localClient
->sendB
&= 0x03ff;
199 if(retlen
== 0 || (retlen
< 0 && !rb_ignore_errno(errno
)))
206 if(rb_linebuf_len(&to
->localClient
->buf_sendq
))
209 rb_setselect(to
->localClient
->F
, RB_SELECT_WRITE
,
210 send_queued_write
, to
);
217 send_pop_queue(struct Client
*to
)
221 if(!MyConnect(to
) || IsIOError(to
))
223 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > 0)
227 /* send_queued_write()
229 * inputs - fd to have queue sent, client we're sending to
230 * outputs - contents of queue
231 * side effects - write is scheduled if queue isnt emptied
234 send_queued_write(rb_fde_t
*F
, void *data
)
236 struct Client
*to
= data
;
243 * inputs - client to send to, va_args
244 * outputs - client has message put into its queue
248 sendto_one(struct Client
*target_p
, const char *pattern
, ...)
253 /* send remote if to->from non NULL */
254 if(target_p
->from
!= NULL
)
255 target_p
= target_p
->from
;
257 if(IsIOError(target_p
))
260 rb_linebuf_newbuf(&linebuf
);
262 va_start(args
, pattern
);
263 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
266 _send_linebuf(target_p
, &linebuf
);
268 rb_linebuf_donebuf(&linebuf
);
272 /* sendto_one_prefix()
274 * inputs - client to send to, va_args
275 * outputs - client has message put into its queue
276 * side effects - source(us)/target is chosen based on TS6 capability
279 sendto_one_prefix(struct Client
*target_p
, struct Client
*source_p
,
280 const char *command
, const char *pattern
, ...)
282 struct Client
*dest_p
;
286 /* send remote if to->from non NULL */
287 if(target_p
->from
!= NULL
)
288 dest_p
= target_p
->from
;
292 if(IsIOError(dest_p
))
297 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
301 rb_linebuf_newbuf(&linebuf
);
302 va_start(args
, pattern
);
303 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
305 get_id(source_p
, target_p
),
306 command
, get_id(target_p
, target_p
));
309 _send_linebuf(dest_p
, &linebuf
);
310 rb_linebuf_donebuf(&linebuf
);
313 /* sendto_one_notice()
315 * inputs - client to send to, va_args
316 * outputs - client has a NOTICE put into its queue
317 * side effects - source(us)/target is chosen based on TS6 capability
320 sendto_one_notice(struct Client
*target_p
, const char *pattern
, ...)
322 struct Client
*dest_p
;
327 /* send remote if to->from non NULL */
328 if(target_p
->from
!= NULL
)
329 dest_p
= target_p
->from
;
333 if(IsIOError(dest_p
))
338 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
342 rb_linebuf_newbuf(&linebuf
);
343 va_start(args
, pattern
);
344 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
346 get_id(&me
, target_p
), *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
349 _send_linebuf(dest_p
, &linebuf
);
350 rb_linebuf_donebuf(&linebuf
);
354 /* sendto_one_numeric()
356 * inputs - client to send to, va_args
357 * outputs - client has message put into its queue
358 * side effects - source/target is chosen based on TS6 capability
361 sendto_one_numeric(struct Client
*target_p
, int numeric
, const char *pattern
, ...)
363 struct Client
*dest_p
;
368 /* send remote if to->from non NULL */
369 if(target_p
->from
!= NULL
)
370 dest_p
= target_p
->from
;
374 if(IsIOError(dest_p
))
379 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
383 rb_linebuf_newbuf(&linebuf
);
384 va_start(args
, pattern
);
385 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
387 get_id(&me
, target_p
),
388 numeric
, *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
391 _send_linebuf(dest_p
, &linebuf
);
392 rb_linebuf_donebuf(&linebuf
);
398 * inputs - pointer to client to NOT send to
399 * - caps or'd together which must ALL be present
400 * - caps or'd together which must ALL NOT be present
401 * - printf style format string
402 * - args to format string
404 * side effects - Send a message to all connected servers, except the
405 * client 'one' (if non-NULL), as long as the servers
406 * support ALL capabs in 'caps', and NO capabs in 'nocaps'.
408 * This function was written in an attempt to merge together the other
409 * billion sendto_*serv*() functions, which sprung up with capabs, uids etc
413 sendto_server(struct Client
*one
, struct Channel
*chptr
, unsigned long caps
,
414 unsigned long nocaps
, const char *format
, ...)
417 struct Client
*target_p
;
419 rb_dlink_node
*next_ptr
;
422 /* noone to send to.. */
423 if(rb_dlink_list_length(&serv_list
) == 0)
426 if(chptr
!= NULL
&& *chptr
->chname
!= '#')
429 rb_linebuf_newbuf(&linebuf
);
430 va_start(args
, format
);
431 rb_linebuf_putmsg(&linebuf
, format
, &args
, NULL
);
434 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
436 target_p
= ptr
->data
;
438 /* check against 'one' */
439 if(one
!= NULL
&& (target_p
== one
->from
))
442 /* check we have required capabs */
443 if(!IsCapable(target_p
, caps
))
446 /* check we don't have any forbidden capabs */
447 if(!NotCapable(target_p
, nocaps
))
450 _send_linebuf(target_p
, &linebuf
);
453 rb_linebuf_donebuf(&linebuf
);
457 /* sendto_channel_flags()
459 * inputs - server not to send to, flags needed, source, channel, va_args
460 * outputs - message is sent to channel members
464 sendto_channel_flags(struct Client
*one
, int type
, struct Client
*source_p
,
465 struct Channel
*chptr
, const char *pattern
, ...)
467 static char buf
[BUFSIZE
];
469 buf_head_t rb_linebuf_local
;
470 buf_head_t rb_linebuf_name
;
471 buf_head_t rb_linebuf_id
;
472 struct Client
*target_p
;
473 struct membership
*msptr
;
475 rb_dlink_node
*next_ptr
;
477 rb_linebuf_newbuf(&rb_linebuf_local
);
478 rb_linebuf_newbuf(&rb_linebuf_name
);
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_name
, NULL
, NULL
, ":%s %s", source_p
->name
, buf
);
497 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
499 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->members
.head
)
502 target_p
= msptr
->client_p
;
504 if(IsIOError(target_p
->from
) || target_p
->from
== one
)
507 if(type
&& ((msptr
->flags
& type
) == 0))
513 if(!MyClient(target_p
))
515 /* if we've got a specific type, target must support
518 if(type
&& NotCapable(target_p
->from
, CAP_CHW
))
521 if(target_p
->from
->serial
!= current_serial
)
523 if(has_id(target_p
->from
))
524 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_id
);
526 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_name
);
528 target_p
->from
->serial
= current_serial
;
532 _send_linebuf(target_p
, &rb_linebuf_local
);
535 rb_linebuf_donebuf(&rb_linebuf_local
);
536 rb_linebuf_donebuf(&rb_linebuf_name
);
537 rb_linebuf_donebuf(&rb_linebuf_id
);
541 /* sendto_channel_local()
543 * inputs - flags to send to, channel to send to, va_args
544 * outputs - message to local channel members
548 sendto_channel_local(int type
, struct Channel
*chptr
, const char *pattern
, ...)
552 struct membership
*msptr
;
553 struct Client
*target_p
;
555 rb_dlink_node
*next_ptr
;
557 rb_linebuf_newbuf(&linebuf
);
559 va_start(args
, pattern
);
560 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
563 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
566 target_p
= msptr
->client_p
;
568 if(IsIOError(target_p
))
571 if(type
&& ((msptr
->flags
& type
) == 0))
574 _send_linebuf(target_p
, &linebuf
);
577 rb_linebuf_donebuf(&linebuf
);
580 /* sendto_channel_local_butone()
582 * inputs - flags to send to, channel to send to, va_args
583 * - user to ignore when sending
584 * outputs - message to local channel members
588 sendto_channel_local_butone(struct Client
*one
, int type
, struct Channel
*chptr
, const char *pattern
, ...)
592 struct membership
*msptr
;
593 struct Client
*target_p
;
595 rb_dlink_node
*next_ptr
;
597 rb_linebuf_newbuf(&linebuf
);
599 va_start(args
, pattern
);
600 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
603 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
606 target_p
= msptr
->client_p
;
611 if(IsIOError(target_p
))
614 if(type
&& ((msptr
->flags
& type
) == 0))
617 _send_linebuf(target_p
, &linebuf
);
620 rb_linebuf_donebuf(&linebuf
);
624 * sendto_common_channels_local()
626 * inputs - pointer to client
629 * side effects - Sends a message to all people on local server who are
630 * in same channel with user.
631 * used by m_nick.c and exit_one_client.
634 sendto_common_channels_local(struct Client
*user
, const char *pattern
, ...)
638 rb_dlink_node
*next_ptr
;
640 rb_dlink_node
*next_uptr
;
641 struct Channel
*chptr
;
642 struct Client
*target_p
;
643 struct membership
*msptr
;
644 struct membership
*mscptr
;
647 rb_linebuf_newbuf(&linebuf
);
648 va_start(args
, pattern
);
649 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
654 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
657 chptr
= mscptr
->chptr
;
659 RB_DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
662 target_p
= msptr
->client_p
;
664 if(IsIOError(target_p
) ||
665 target_p
->serial
== current_serial
)
668 target_p
->serial
= current_serial
;
669 send_linebuf(target_p
, &linebuf
);
673 /* this can happen when the user isnt in any channels, but we still
674 * need to send them the data, ie a nick change
676 if(MyConnect(user
) && (user
->serial
!= current_serial
))
677 send_linebuf(user
, &linebuf
);
679 rb_linebuf_donebuf(&linebuf
);
683 * sendto_common_channels_local_butone()
685 * inputs - pointer to client
688 * side effects - Sends a message to all people on local server who are
689 * in same channel with user, except for user itself.
692 sendto_common_channels_local_butone(struct Client
*user
, const char *pattern
, ...)
696 rb_dlink_node
*next_ptr
;
698 rb_dlink_node
*next_uptr
;
699 struct Channel
*chptr
;
700 struct Client
*target_p
;
701 struct membership
*msptr
;
702 struct membership
*mscptr
;
705 rb_linebuf_newbuf(&linebuf
);
706 va_start(args
, pattern
);
707 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
711 /* Skip them -- jilles */
712 user
->serial
= current_serial
;
714 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
717 chptr
= mscptr
->chptr
;
719 RB_DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
722 target_p
= msptr
->client_p
;
724 if(IsIOError(target_p
) ||
725 target_p
->serial
== current_serial
)
728 target_p
->serial
= current_serial
;
729 send_linebuf(target_p
, &linebuf
);
733 rb_linebuf_donebuf(&linebuf
);
736 /* sendto_match_butone()
738 * inputs - server not to send to, source, mask, type of mask, va_args
740 * side effects - message is sent to matching clients
743 sendto_match_butone(struct Client
*one
, struct Client
*source_p
,
744 const char *mask
, int what
, const char *pattern
, ...)
746 static char buf
[BUFSIZE
];
748 struct Client
*target_p
;
750 rb_dlink_node
*next_ptr
;
751 buf_head_t rb_linebuf_local
;
752 buf_head_t rb_linebuf_name
;
753 buf_head_t rb_linebuf_id
;
755 rb_linebuf_newbuf(&rb_linebuf_local
);
756 rb_linebuf_newbuf(&rb_linebuf_name
);
757 rb_linebuf_newbuf(&rb_linebuf_id
);
759 va_start(args
, pattern
);
760 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
763 if(IsServer(source_p
))
764 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
765 ":%s %s", source_p
->name
, buf
);
767 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
769 source_p
->name
, source_p
->username
,
770 source_p
->host
, buf
);
772 rb_linebuf_putmsg(&rb_linebuf_name
, NULL
, NULL
, ":%s %s", source_p
->name
, buf
);
773 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
775 if(what
== MATCH_HOST
)
777 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
779 target_p
= ptr
->data
;
781 if(match(mask
, target_p
->host
))
782 _send_linebuf(target_p
, &rb_linebuf_local
);
785 /* what = MATCH_SERVER, if it doesnt match us, just send remote */
786 else if(match(mask
, me
.name
))
788 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
790 target_p
= ptr
->data
;
791 _send_linebuf(target_p
, &rb_linebuf_local
);
795 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
797 target_p
= ptr
->data
;
803 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_id
);
805 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_name
);
808 rb_linebuf_donebuf(&rb_linebuf_local
);
809 rb_linebuf_donebuf(&rb_linebuf_id
);
810 rb_linebuf_donebuf(&rb_linebuf_name
);
813 /* sendto_match_servs()
815 * inputs - source, mask to send to, caps needed, va_args
817 * side effects - message is sent to matching servers with caps.
820 sendto_match_servs(struct Client
*source_p
, const char *mask
, int cap
,
821 int nocap
, const char *pattern
, ...)
823 static char buf
[BUFSIZE
];
826 struct Client
*target_p
;
827 buf_head_t rb_linebuf_id
;
828 buf_head_t rb_linebuf_name
;
830 if(EmptyString(mask
))
833 rb_linebuf_newbuf(&rb_linebuf_id
);
834 rb_linebuf_newbuf(&rb_linebuf_name
);
836 va_start(args
, pattern
);
837 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
840 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
,
841 ":%s %s", use_id(source_p
), buf
);
842 rb_linebuf_putmsg(&rb_linebuf_name
, NULL
, NULL
,
843 ":%s %s", source_p
->name
, buf
);
847 RB_DLINK_FOREACH(ptr
, global_serv_list
.head
)
849 target_p
= ptr
->data
;
851 /* dont send to ourselves, or back to where it came from.. */
852 if(IsMe(target_p
) || target_p
->from
== source_p
->from
)
855 if(target_p
->from
->serial
== current_serial
)
858 if(match(mask
, target_p
->name
))
860 /* if we set the serial here, then we'll never do
861 * a match() again if !IsCapable()
863 target_p
->from
->serial
= current_serial
;
865 if(cap
&& !IsCapable(target_p
->from
, cap
))
868 if(nocap
&& !NotCapable(target_p
->from
, nocap
))
871 if(has_id(target_p
->from
))
872 _send_linebuf(target_p
->from
, &rb_linebuf_id
);
874 _send_linebuf(target_p
->from
, &rb_linebuf_name
);
878 rb_linebuf_donebuf(&rb_linebuf_id
);
879 rb_linebuf_donebuf(&rb_linebuf_name
);
884 * inputs - monitor nick to send to, format, va_args
885 * outputs - message to local users monitoring the given nick
889 sendto_monitor(struct monitor
*monptr
, const char *pattern
, ...)
893 struct Client
*target_p
;
895 rb_dlink_node
*next_ptr
;
897 rb_linebuf_newbuf(&linebuf
);
899 va_start(args
, pattern
);
900 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
903 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, monptr
->users
.head
)
905 target_p
= ptr
->data
;
907 if(IsIOError(target_p
))
910 _send_linebuf(target_p
, &linebuf
);
913 rb_linebuf_donebuf(&linebuf
);
918 * inputs - target, source, va_args
920 * side effects - client is sent message with correct prefix.
923 sendto_anywhere(struct Client
*target_p
, struct Client
*source_p
,
924 const char *command
, const char *pattern
, ...)
929 rb_linebuf_newbuf(&linebuf
);
931 va_start(args
, pattern
);
933 if(MyClient(target_p
))
935 if(IsServer(source_p
))
936 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
937 source_p
->name
, command
,
940 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
942 source_p
->name
, source_p
->username
,
943 source_p
->host
, command
,
947 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
948 get_id(source_p
, target_p
), command
,
949 get_id(target_p
, target_p
));
952 if(MyClient(target_p
))
953 _send_linebuf(target_p
, &linebuf
);
955 send_linebuf_remote(target_p
, source_p
, &linebuf
);
957 rb_linebuf_donebuf(&linebuf
);
960 /* sendto_realops_snomask()
962 * inputs - snomask needed, level (opers/admin), va_args
964 * side effects - message is sent to opers with matching snomasks
967 sendto_realops_snomask(int flags
, int level
, const char *pattern
, ...)
969 static char buf
[BUFSIZE
];
971 struct Client
*client_p
;
973 rb_dlink_node
*next_ptr
;
977 rb_linebuf_newbuf(&linebuf
);
979 /* Be very sure not to do things like "Trying to send to myself"
980 * L_NETWIDE, otherwise infinite recursion may result! -- jilles */
981 if (level
& L_NETWIDE
&& ConfigFileEntry
.global_snotices
)
983 /* rather a lot of copying around, oh well -- jilles */
984 va_start(args
, pattern
);
985 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
987 rb_linebuf_putmsg(&linebuf
, pattern
, NULL
,
988 ":%s NOTICE * :*** Notice -- %s", me
.name
, buf
);
989 snobuf
= construct_snobuf(flags
);
990 if (snobuf
[1] != '\0')
991 sendto_server(NULL
, NULL
, CAP_ENCAP
|CAP_TS6
, NOCAPS
,
992 ":%s ENCAP * SNOTE %c :%s",
993 me
.id
, snobuf
[1], buf
);
997 va_start(args
, pattern
);
998 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
999 ":%s NOTICE * :*** Notice -- ", me
.name
);
1002 level
&= ~L_NETWIDE
;
1004 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1006 client_p
= ptr
->data
;
1008 /* If we're sending it to opers and theyre an admin, skip.
1009 * If we're sending it to admins, and theyre not, skip.
1011 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1012 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1015 if(client_p
->snomask
& flags
)
1016 _send_linebuf(client_p
, &linebuf
);
1019 rb_linebuf_donebuf(&linebuf
);
1021 /* sendto_realops_snomask_from()
1023 * inputs - snomask needed, level (opers/admin), source server, va_args
1025 * side effects - message is sent to opers with matching snomask
1028 sendto_realops_snomask_from(int flags
, int level
, struct Client
*source_p
,
1029 const char *pattern
, ...)
1031 struct Client
*client_p
;
1033 rb_dlink_node
*next_ptr
;
1037 rb_linebuf_newbuf(&linebuf
);
1039 va_start(args
, pattern
);
1040 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1041 ":%s NOTICE * :*** Notice -- ", source_p
->name
);
1044 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1046 client_p
= ptr
->data
;
1048 /* If we're sending it to opers and theyre an admin, skip.
1049 * If we're sending it to admins, and theyre not, skip.
1051 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1052 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1055 if(client_p
->snomask
& flags
)
1056 _send_linebuf(client_p
, &linebuf
);
1059 rb_linebuf_donebuf(&linebuf
);
1063 * sendto_wallops_flags
1065 * inputs - flag types of messages to show to real opers
1066 * - client sending request
1067 * - var args input message
1069 * side effects - Send a wallops to local opers
1072 sendto_wallops_flags(int flags
, struct Client
*source_p
, const char *pattern
, ...)
1074 struct Client
*client_p
;
1076 rb_dlink_node
*next_ptr
;
1080 rb_linebuf_newbuf(&linebuf
);
1082 va_start(args
, pattern
);
1084 if(IsPerson(source_p
))
1085 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1086 ":%s!%s@%s WALLOPS :", source_p
->name
,
1087 source_p
->username
, source_p
->host
);
1089 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s WALLOPS :", source_p
->name
);
1093 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, IsPerson(source_p
) && flags
== UMODE_WALLOP
? lclient_list
.head
: local_oper_list
.head
)
1095 client_p
= ptr
->data
;
1097 if(client_p
->umodes
& flags
)
1098 _send_linebuf(client_p
, &linebuf
);
1101 rb_linebuf_donebuf(&linebuf
);
1106 * input - client to send kill to, client to kill, va_args
1108 * side effects - we issue a kill for the client
1111 kill_client(struct Client
*target_p
, struct Client
*diedie
, const char *pattern
, ...)
1116 rb_linebuf_newbuf(&linebuf
);
1118 va_start(args
, pattern
);
1119 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s KILL %s :",
1120 get_id(&me
, target_p
), get_id(diedie
, target_p
));
1123 send_linebuf(target_p
, &linebuf
);
1124 rb_linebuf_donebuf(&linebuf
);
1129 * kill_client_serv_butone
1131 * inputs - pointer to client to not send to
1132 * - pointer to client to kill
1134 * side effects - Send a KILL for the given client
1135 * message to all connected servers
1136 * except the client 'one'. Also deal with
1137 * client being unknown to leaf, as in lazylink...
1140 kill_client_serv_butone(struct Client
*one
, struct Client
*target_p
, const char *pattern
, ...)
1142 static char buf
[BUFSIZE
];
1144 struct Client
*client_p
;
1146 rb_dlink_node
*next_ptr
;
1147 buf_head_t rb_linebuf_id
;
1148 buf_head_t rb_linebuf_name
;
1150 rb_linebuf_newbuf(&rb_linebuf_name
);
1151 rb_linebuf_newbuf(&rb_linebuf_id
);
1153 va_start(args
, pattern
);
1154 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1157 rb_linebuf_putmsg(&rb_linebuf_name
, NULL
, NULL
, ":%s KILL %s :%s",
1158 me
.name
, target_p
->name
, buf
);
1159 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s KILL %s :%s",
1160 use_id(&me
), use_id(target_p
), buf
);
1162 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
1164 client_p
= ptr
->data
;
1166 /* ok, if the client we're supposed to not send to has an
1167 * ID, then we still want to issue the kill there..
1169 if(one
!= NULL
&& (client_p
== one
->from
) &&
1170 (!has_id(client_p
) || !has_id(target_p
)))
1173 if(has_id(client_p
))
1174 _send_linebuf(client_p
, &rb_linebuf_id
);
1176 _send_linebuf(client_p
, &rb_linebuf_name
);
1179 rb_linebuf_donebuf(&rb_linebuf_id
);
1180 rb_linebuf_donebuf(&rb_linebuf_name
);