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 $
33 #include "irc_string.h"
37 #include "sprintf_irc.h"
39 #include "s_newconf.h"
44 #define LOG_BUFSIZE 2048
46 /* send the message to the link the target is attached to */
47 #define send_linebuf(a,b) _send_linebuf((a->from ? a->from : a) ,b)
49 static void send_queued_write(rb_fde_t
*F
, void *data
);
51 unsigned long current_serial
= 0L;
55 * inputs - client to send to, linebuf to attach
57 * side effects - linebuf is attached to client
60 _send_linebuf(struct Client
*to
, buf_head_t
*linebuf
)
64 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send message to myself!");
68 if(!MyConnect(to
) || IsIOError(to
))
71 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > get_sendq(to
))
75 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
76 "Max SendQ limit exceeded for %s: %u > %lu",
77 get_server_name(to
, HIDE_IP
),
78 rb_linebuf_len(&to
->localClient
->buf_sendq
),
81 ilog(L_SERVER
, "Max SendQ limit exceeded for %s: %u > %lu",
82 log_client_name(to
, SHOW_IP
),
83 rb_linebuf_len(&to
->localClient
->buf_sendq
),
88 to
->flags
|= FLAGS_SENDQEX
;
95 /* just attach the linebuf to the sendq instead of
96 * generating a new one
98 rb_linebuf_attach(&to
->localClient
->buf_sendq
, linebuf
);
102 ** Update statistics. The following is slightly incorrect
103 ** because it counts messages even if queued, but bytes
104 ** only really sent. Queued bytes get updated in SendQueued.
106 to
->localClient
->sendM
+= 1;
107 me
.localClient
->sendM
+= 1;
108 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > 0)
113 /* send_linebuf_remote()
115 * inputs - client to attach to, sender, linebuf
117 * side effects - client has linebuf attached
120 send_linebuf_remote(struct Client
*to
, struct Client
*from
, buf_head_t
*linebuf
)
125 /* we assume the caller has already tested for fake direction */
127 _send_linebuf(to
, linebuf
);
131 /* send_queued_write()
133 * inputs - fd to have queue sent, client we're sending to
134 * outputs - contents of queue
135 * side effects - write is rescheduled if queue isnt emptied
138 send_queued(struct Client
*to
)
141 #ifdef USE_IODEBUG_HOOKS
144 rb_fde_t
*F
= to
->localClient
->F
;
148 /* cant write anything to a dead socket. */
152 /* Something wants us to not send anything currently */
156 /* try to flush later when the write event resets this */
160 #ifdef USE_IODEBUG_HOOKS
162 if(to
->localClient
->buf_sendq
.list
.head
)
163 hd
.arg1
= ((buf_line_t
*) to
->localClient
->buf_sendq
.list
.head
->data
)->buf
+
164 to
->localClient
->buf_sendq
.writeofs
;
167 if(rb_linebuf_len(&to
->localClient
->buf_sendq
))
170 rb_linebuf_flush(F
, &to
->localClient
->buf_sendq
)) > 0)
172 /* We have some data written .. update counters */
173 #ifdef USE_IODEBUG_HOOKS
175 call_hook(h_iosend_id
, &hd
);
177 if(to
->localClient
->buf_sendq
.list
.head
)
179 ((buf_line_t
*) to
->localClient
->buf_sendq
.list
.head
->
180 data
)->buf
+ to
->localClient
->buf_sendq
.writeofs
;
186 to
->localClient
->sendB
+= retlen
;
187 me
.localClient
->sendB
+= retlen
;
188 if(to
->localClient
->sendB
> 1023)
190 to
->localClient
->sendK
+= (to
->localClient
->sendB
>> 10);
191 to
->localClient
->sendB
&= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */
193 else if(me
.localClient
->sendB
> 1023)
195 me
.localClient
->sendK
+= (me
.localClient
->sendB
>> 10);
196 me
.localClient
->sendB
&= 0x03ff;
200 if(retlen
== 0 || (retlen
< 0 && !rb_ignore_errno(errno
)))
207 if(rb_linebuf_len(&to
->localClient
->buf_sendq
))
210 rb_setselect(to
->localClient
->F
, RB_SELECT_WRITE
,
211 send_queued_write
, to
);
218 send_pop_queue(struct Client
*to
)
222 if(!MyConnect(to
) || IsIOError(to
))
224 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > 0)
228 /* send_queued_write()
230 * inputs - fd to have queue sent, client we're sending to
231 * outputs - contents of queue
232 * side effects - write is scheduled if queue isnt emptied
235 send_queued_write(rb_fde_t
*F
, void *data
)
237 struct Client
*to
= data
;
244 * inputs - client to send to, va_args
245 * outputs - client has message put into its queue
249 sendto_one(struct Client
*target_p
, const char *pattern
, ...)
254 /* send remote if to->from non NULL */
255 if(target_p
->from
!= NULL
)
256 target_p
= target_p
->from
;
258 if(IsIOError(target_p
))
261 rb_linebuf_newbuf(&linebuf
);
263 va_start(args
, pattern
);
264 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
267 _send_linebuf(target_p
, &linebuf
);
269 rb_linebuf_donebuf(&linebuf
);
273 /* sendto_one_prefix()
275 * inputs - client to send to, va_args
276 * outputs - client has message put into its queue
277 * side effects - source(us)/target is chosen based on TS6 capability
280 sendto_one_prefix(struct Client
*target_p
, struct Client
*source_p
,
281 const char *command
, const char *pattern
, ...)
283 struct Client
*dest_p
;
287 /* send remote if to->from non NULL */
288 if(target_p
->from
!= NULL
)
289 dest_p
= target_p
->from
;
293 if(IsIOError(dest_p
))
298 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
302 rb_linebuf_newbuf(&linebuf
);
303 va_start(args
, pattern
);
304 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
306 get_id(source_p
, target_p
),
307 command
, get_id(target_p
, target_p
));
310 _send_linebuf(dest_p
, &linebuf
);
311 rb_linebuf_donebuf(&linebuf
);
314 /* sendto_one_notice()
316 * inputs - client to send to, va_args
317 * outputs - client has a NOTICE put into its queue
318 * side effects - source(us)/target is chosen based on TS6 capability
321 sendto_one_notice(struct Client
*target_p
, const char *pattern
, ...)
323 struct Client
*dest_p
;
328 /* send remote if to->from non NULL */
329 if(target_p
->from
!= NULL
)
330 dest_p
= target_p
->from
;
334 if(IsIOError(dest_p
))
339 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
343 rb_linebuf_newbuf(&linebuf
);
344 va_start(args
, pattern
);
345 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
347 get_id(&me
, target_p
), *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
350 _send_linebuf(dest_p
, &linebuf
);
351 rb_linebuf_donebuf(&linebuf
);
355 /* sendto_one_numeric()
357 * inputs - client to send to, va_args
358 * outputs - client has message put into its queue
359 * side effects - source/target is chosen based on TS6 capability
362 sendto_one_numeric(struct Client
*target_p
, int numeric
, const char *pattern
, ...)
364 struct Client
*dest_p
;
369 /* send remote if to->from non NULL */
370 if(target_p
->from
!= NULL
)
371 dest_p
= target_p
->from
;
375 if(IsIOError(dest_p
))
380 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
384 rb_linebuf_newbuf(&linebuf
);
385 va_start(args
, pattern
);
386 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
388 get_id(&me
, target_p
),
389 numeric
, *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
392 _send_linebuf(dest_p
, &linebuf
);
393 rb_linebuf_donebuf(&linebuf
);
399 * inputs - pointer to client to NOT send to
400 * - caps or'd together which must ALL be present
401 * - caps or'd together which must ALL NOT be present
402 * - printf style format string
403 * - args to format string
405 * side effects - Send a message to all connected servers, except the
406 * client 'one' (if non-NULL), as long as the servers
407 * support ALL capabs in 'caps', and NO capabs in 'nocaps'.
409 * This function was written in an attempt to merge together the other
410 * billion sendto_*serv*() functions, which sprung up with capabs, uids etc
414 sendto_server(struct Client
*one
, struct Channel
*chptr
, unsigned long caps
,
415 unsigned long nocaps
, const char *format
, ...)
418 struct Client
*target_p
;
420 rb_dlink_node
*next_ptr
;
423 /* noone to send to.. */
424 if(rb_dlink_list_length(&serv_list
) == 0)
427 if(chptr
!= NULL
&& *chptr
->chname
!= '#')
430 rb_linebuf_newbuf(&linebuf
);
431 va_start(args
, format
);
432 rb_linebuf_putmsg(&linebuf
, format
, &args
, NULL
);
435 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
437 target_p
= ptr
->data
;
439 /* check against 'one' */
440 if(one
!= NULL
&& (target_p
== one
->from
))
443 /* check we have required capabs */
444 if(!IsCapable(target_p
, caps
))
447 /* check we don't have any forbidden capabs */
448 if(!NotCapable(target_p
, nocaps
))
451 _send_linebuf(target_p
, &linebuf
);
454 rb_linebuf_donebuf(&linebuf
);
458 /* sendto_channel_flags()
460 * inputs - server not to send to, flags needed, source, channel, va_args
461 * outputs - message is sent to channel members
465 sendto_channel_flags(struct Client
*one
, int type
, struct Client
*source_p
,
466 struct Channel
*chptr
, const char *pattern
, ...)
468 static char buf
[BUFSIZE
];
470 buf_head_t rb_linebuf_local
;
471 buf_head_t rb_linebuf_name
;
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_name
);
480 rb_linebuf_newbuf(&rb_linebuf_id
);
484 va_start(args
, pattern
);
485 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
488 if(IsServer(source_p
))
489 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
490 ":%s %s", source_p
->name
, buf
);
492 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
494 source_p
->name
, source_p
->username
,
495 source_p
->host
, buf
);
497 rb_linebuf_putmsg(&rb_linebuf_name
, NULL
, NULL
, ":%s %s", source_p
->name
, buf
);
498 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
500 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->members
.head
)
503 target_p
= msptr
->client_p
;
505 if(IsIOError(target_p
->from
) || target_p
->from
== one
)
508 if(type
&& ((msptr
->flags
& type
) == 0))
514 if(!MyClient(target_p
))
516 /* if we've got a specific type, target must support
519 if(type
&& NotCapable(target_p
->from
, CAP_CHW
))
522 if(target_p
->from
->serial
!= current_serial
)
524 if(has_id(target_p
->from
))
525 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_id
);
527 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_name
);
529 target_p
->from
->serial
= current_serial
;
533 _send_linebuf(target_p
, &rb_linebuf_local
);
536 rb_linebuf_donebuf(&rb_linebuf_local
);
537 rb_linebuf_donebuf(&rb_linebuf_name
);
538 rb_linebuf_donebuf(&rb_linebuf_id
);
542 /* sendto_channel_local()
544 * inputs - flags to send to, channel to send to, va_args
545 * outputs - message to local channel members
549 sendto_channel_local(int type
, struct Channel
*chptr
, const char *pattern
, ...)
553 struct membership
*msptr
;
554 struct Client
*target_p
;
556 rb_dlink_node
*next_ptr
;
558 rb_linebuf_newbuf(&linebuf
);
560 va_start(args
, pattern
);
561 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
564 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
567 target_p
= msptr
->client_p
;
569 if(IsIOError(target_p
))
572 if(type
&& ((msptr
->flags
& type
) == 0))
575 _send_linebuf(target_p
, &linebuf
);
578 rb_linebuf_donebuf(&linebuf
);
581 /* sendto_channel_local_butone()
583 * inputs - flags to send to, channel to send to, va_args
584 * - user to ignore when sending
585 * outputs - message to local channel members
589 sendto_channel_local_butone(struct Client
*one
, int type
, struct Channel
*chptr
, const char *pattern
, ...)
593 struct membership
*msptr
;
594 struct Client
*target_p
;
596 rb_dlink_node
*next_ptr
;
598 rb_linebuf_newbuf(&linebuf
);
600 va_start(args
, pattern
);
601 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
604 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
607 target_p
= msptr
->client_p
;
612 if(IsIOError(target_p
))
615 if(type
&& ((msptr
->flags
& type
) == 0))
618 _send_linebuf(target_p
, &linebuf
);
621 rb_linebuf_donebuf(&linebuf
);
625 * sendto_common_channels_local()
627 * inputs - pointer to client
630 * side effects - Sends a message to all people on local server who are
631 * in same channel with user.
632 * used by m_nick.c and exit_one_client.
635 sendto_common_channels_local(struct Client
*user
, const char *pattern
, ...)
639 rb_dlink_node
*next_ptr
;
641 rb_dlink_node
*next_uptr
;
642 struct Channel
*chptr
;
643 struct Client
*target_p
;
644 struct membership
*msptr
;
645 struct membership
*mscptr
;
648 rb_linebuf_newbuf(&linebuf
);
649 va_start(args
, pattern
);
650 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
655 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
658 chptr
= mscptr
->chptr
;
660 RB_DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
663 target_p
= msptr
->client_p
;
665 if(IsIOError(target_p
) ||
666 target_p
->serial
== current_serial
)
669 target_p
->serial
= current_serial
;
670 send_linebuf(target_p
, &linebuf
);
674 /* this can happen when the user isnt in any channels, but we still
675 * need to send them the data, ie a nick change
677 if(MyConnect(user
) && (user
->serial
!= current_serial
))
678 send_linebuf(user
, &linebuf
);
680 rb_linebuf_donebuf(&linebuf
);
684 * sendto_common_channels_local_butone()
686 * inputs - pointer to client
689 * side effects - Sends a message to all people on local server who are
690 * in same channel with user, except for user itself.
693 sendto_common_channels_local_butone(struct Client
*user
, const char *pattern
, ...)
697 rb_dlink_node
*next_ptr
;
699 rb_dlink_node
*next_uptr
;
700 struct Channel
*chptr
;
701 struct Client
*target_p
;
702 struct membership
*msptr
;
703 struct membership
*mscptr
;
706 rb_linebuf_newbuf(&linebuf
);
707 va_start(args
, pattern
);
708 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
712 /* Skip them -- jilles */
713 user
->serial
= current_serial
;
715 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
718 chptr
= mscptr
->chptr
;
720 RB_DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
723 target_p
= msptr
->client_p
;
725 if(IsIOError(target_p
) ||
726 target_p
->serial
== current_serial
)
729 target_p
->serial
= current_serial
;
730 send_linebuf(target_p
, &linebuf
);
734 rb_linebuf_donebuf(&linebuf
);
737 /* sendto_match_butone()
739 * inputs - server not to send to, source, mask, type of mask, va_args
741 * side effects - message is sent to matching clients
744 sendto_match_butone(struct Client
*one
, struct Client
*source_p
,
745 const char *mask
, int what
, const char *pattern
, ...)
747 static char buf
[BUFSIZE
];
749 struct Client
*target_p
;
751 rb_dlink_node
*next_ptr
;
752 buf_head_t rb_linebuf_local
;
753 buf_head_t rb_linebuf_name
;
754 buf_head_t rb_linebuf_id
;
756 rb_linebuf_newbuf(&rb_linebuf_local
);
757 rb_linebuf_newbuf(&rb_linebuf_name
);
758 rb_linebuf_newbuf(&rb_linebuf_id
);
760 va_start(args
, pattern
);
761 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
764 if(IsServer(source_p
))
765 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
766 ":%s %s", source_p
->name
, buf
);
768 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
770 source_p
->name
, source_p
->username
,
771 source_p
->host
, buf
);
773 rb_linebuf_putmsg(&rb_linebuf_name
, NULL
, NULL
, ":%s %s", source_p
->name
, buf
);
774 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
776 if(what
== MATCH_HOST
)
778 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
780 target_p
= ptr
->data
;
782 if(match(mask
, target_p
->host
))
783 _send_linebuf(target_p
, &rb_linebuf_local
);
786 /* what = MATCH_SERVER, if it doesnt match us, just send remote */
787 else if(match(mask
, me
.name
))
789 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
791 target_p
= ptr
->data
;
792 _send_linebuf(target_p
, &rb_linebuf_local
);
796 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
798 target_p
= ptr
->data
;
804 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_id
);
806 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_name
);
809 rb_linebuf_donebuf(&rb_linebuf_local
);
810 rb_linebuf_donebuf(&rb_linebuf_id
);
811 rb_linebuf_donebuf(&rb_linebuf_name
);
814 /* sendto_match_servs()
816 * inputs - source, mask to send to, caps needed, va_args
818 * side effects - message is sent to matching servers with caps.
821 sendto_match_servs(struct Client
*source_p
, const char *mask
, int cap
,
822 int nocap
, const char *pattern
, ...)
824 static char buf
[BUFSIZE
];
827 struct Client
*target_p
;
828 buf_head_t rb_linebuf_id
;
829 buf_head_t rb_linebuf_name
;
831 if(EmptyString(mask
))
834 rb_linebuf_newbuf(&rb_linebuf_id
);
835 rb_linebuf_newbuf(&rb_linebuf_name
);
837 va_start(args
, pattern
);
838 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
841 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
,
842 ":%s %s", use_id(source_p
), buf
);
843 rb_linebuf_putmsg(&rb_linebuf_name
, NULL
, NULL
,
844 ":%s %s", source_p
->name
, buf
);
848 RB_DLINK_FOREACH(ptr
, global_serv_list
.head
)
850 target_p
= ptr
->data
;
852 /* dont send to ourselves, or back to where it came from.. */
853 if(IsMe(target_p
) || target_p
->from
== source_p
->from
)
856 if(target_p
->from
->serial
== current_serial
)
859 if(match(mask
, target_p
->name
))
861 /* if we set the serial here, then we'll never do
862 * a match() again if !IsCapable()
864 target_p
->from
->serial
= current_serial
;
866 if(cap
&& !IsCapable(target_p
->from
, cap
))
869 if(nocap
&& !NotCapable(target_p
->from
, nocap
))
872 if(has_id(target_p
->from
))
873 _send_linebuf(target_p
->from
, &rb_linebuf_id
);
875 _send_linebuf(target_p
->from
, &rb_linebuf_name
);
879 rb_linebuf_donebuf(&rb_linebuf_id
);
880 rb_linebuf_donebuf(&rb_linebuf_name
);
885 * inputs - monitor nick to send to, format, va_args
886 * outputs - message to local users monitoring the given nick
890 sendto_monitor(struct monitor
*monptr
, const char *pattern
, ...)
894 struct Client
*target_p
;
896 rb_dlink_node
*next_ptr
;
898 rb_linebuf_newbuf(&linebuf
);
900 va_start(args
, pattern
);
901 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
904 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, monptr
->users
.head
)
906 target_p
= ptr
->data
;
908 if(IsIOError(target_p
))
911 _send_linebuf(target_p
, &linebuf
);
914 rb_linebuf_donebuf(&linebuf
);
919 * inputs - target, source, va_args
921 * side effects - client is sent message with correct prefix.
924 sendto_anywhere(struct Client
*target_p
, struct Client
*source_p
,
925 const char *command
, const char *pattern
, ...)
930 rb_linebuf_newbuf(&linebuf
);
932 va_start(args
, pattern
);
934 if(MyClient(target_p
))
936 if(IsServer(source_p
))
937 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
938 source_p
->name
, command
,
941 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
943 source_p
->name
, source_p
->username
,
944 source_p
->host
, command
,
948 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
949 get_id(source_p
, target_p
), command
,
950 get_id(target_p
, target_p
));
953 if(MyClient(target_p
))
954 _send_linebuf(target_p
, &linebuf
);
956 send_linebuf_remote(target_p
, source_p
, &linebuf
);
958 rb_linebuf_donebuf(&linebuf
);
961 /* sendto_realops_snomask()
963 * inputs - snomask needed, level (opers/admin), va_args
965 * side effects - message is sent to opers with matching snomasks
968 sendto_realops_snomask(int flags
, int level
, const char *pattern
, ...)
970 static char buf
[BUFSIZE
];
972 struct Client
*client_p
;
974 rb_dlink_node
*next_ptr
;
978 rb_linebuf_newbuf(&linebuf
);
980 /* Be very sure not to do things like "Trying to send to myself"
981 * L_NETWIDE, otherwise infinite recursion may result! -- jilles */
982 if (level
& L_NETWIDE
&& ConfigFileEntry
.global_snotices
)
984 /* rather a lot of copying around, oh well -- jilles */
985 va_start(args
, pattern
);
986 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
988 rb_linebuf_putmsg(&linebuf
, pattern
, NULL
,
989 ":%s NOTICE * :*** Notice -- %s", me
.name
, buf
);
990 snobuf
= construct_snobuf(flags
);
991 if (snobuf
[1] != '\0')
993 sendto_server(NULL
, NULL
, CAP_ENCAP
|CAP_TS6
, NOCAPS
,
994 ":%s ENCAP * SNOTE %c :%s",
995 me
.id
, snobuf
[1], buf
);
996 sendto_server(NULL
, NULL
, CAP_ENCAP
, CAP_TS6
,
997 ":%s ENCAP * SNOTE %c :%s",
998 me
.name
, snobuf
[1], buf
);
1003 va_start(args
, pattern
);
1004 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1005 ":%s NOTICE * :*** Notice -- ", me
.name
);
1008 level
&= ~L_NETWIDE
;
1010 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1012 client_p
= ptr
->data
;
1014 /* If we're sending it to opers and theyre an admin, skip.
1015 * If we're sending it to admins, and theyre not, skip.
1017 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1018 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1021 if(client_p
->snomask
& flags
)
1022 _send_linebuf(client_p
, &linebuf
);
1025 rb_linebuf_donebuf(&linebuf
);
1027 /* sendto_realops_snomask_from()
1029 * inputs - snomask needed, level (opers/admin), source server, va_args
1031 * side effects - message is sent to opers with matching snomask
1034 sendto_realops_snomask_from(int flags
, int level
, struct Client
*source_p
,
1035 const char *pattern
, ...)
1037 struct Client
*client_p
;
1039 rb_dlink_node
*next_ptr
;
1043 rb_linebuf_newbuf(&linebuf
);
1045 va_start(args
, pattern
);
1046 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1047 ":%s NOTICE * :*** Notice -- ", source_p
->name
);
1050 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1052 client_p
= ptr
->data
;
1054 /* If we're sending it to opers and theyre an admin, skip.
1055 * If we're sending it to admins, and theyre not, skip.
1057 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1058 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1061 if(client_p
->snomask
& flags
)
1062 _send_linebuf(client_p
, &linebuf
);
1065 rb_linebuf_donebuf(&linebuf
);
1069 * sendto_wallops_flags
1071 * inputs - flag types of messages to show to real opers
1072 * - client sending request
1073 * - var args input message
1075 * side effects - Send a wallops to local opers
1078 sendto_wallops_flags(int flags
, struct Client
*source_p
, const char *pattern
, ...)
1080 struct Client
*client_p
;
1082 rb_dlink_node
*next_ptr
;
1086 rb_linebuf_newbuf(&linebuf
);
1088 va_start(args
, pattern
);
1090 if(IsPerson(source_p
))
1091 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1092 ":%s!%s@%s WALLOPS :", source_p
->name
,
1093 source_p
->username
, source_p
->host
);
1095 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s WALLOPS :", source_p
->name
);
1099 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, IsPerson(source_p
) && flags
== UMODE_WALLOP
? lclient_list
.head
: local_oper_list
.head
)
1101 client_p
= ptr
->data
;
1103 if(client_p
->umodes
& flags
)
1104 _send_linebuf(client_p
, &linebuf
);
1107 rb_linebuf_donebuf(&linebuf
);
1112 * input - client to send kill to, client to kill, va_args
1114 * side effects - we issue a kill for the client
1117 kill_client(struct Client
*target_p
, struct Client
*diedie
, const char *pattern
, ...)
1122 rb_linebuf_newbuf(&linebuf
);
1124 va_start(args
, pattern
);
1125 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s KILL %s :",
1126 get_id(&me
, target_p
), get_id(diedie
, target_p
));
1129 send_linebuf(target_p
, &linebuf
);
1130 rb_linebuf_donebuf(&linebuf
);
1135 * kill_client_serv_butone
1137 * inputs - pointer to client to not send to
1138 * - pointer to client to kill
1140 * side effects - Send a KILL for the given client
1141 * message to all connected servers
1142 * except the client 'one'. Also deal with
1143 * client being unknown to leaf, as in lazylink...
1146 kill_client_serv_butone(struct Client
*one
, struct Client
*target_p
, const char *pattern
, ...)
1148 static char buf
[BUFSIZE
];
1150 struct Client
*client_p
;
1152 rb_dlink_node
*next_ptr
;
1153 buf_head_t rb_linebuf_id
;
1154 buf_head_t rb_linebuf_name
;
1156 rb_linebuf_newbuf(&rb_linebuf_name
);
1157 rb_linebuf_newbuf(&rb_linebuf_id
);
1159 va_start(args
, pattern
);
1160 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1163 rb_linebuf_putmsg(&rb_linebuf_name
, NULL
, NULL
, ":%s KILL %s :%s",
1164 me
.name
, target_p
->name
, buf
);
1165 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s KILL %s :%s",
1166 use_id(&me
), use_id(target_p
), buf
);
1168 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
1170 client_p
= ptr
->data
;
1172 /* ok, if the client we're supposed to not send to has an
1173 * ID, then we still want to issue the kill there..
1175 if(one
!= NULL
&& (client_p
== one
->from
) &&
1176 (!has_id(client_p
) || !has_id(target_p
)))
1179 if(has_id(client_p
))
1180 _send_linebuf(client_p
, &rb_linebuf_id
);
1182 _send_linebuf(client_p
, &rb_linebuf_name
);
1185 rb_linebuf_donebuf(&rb_linebuf_id
);
1186 rb_linebuf_donebuf(&rb_linebuf_name
);