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 #ifdef USE_IODEBUG_HOOKS
154 if(to
->localClient
->buf_sendq
.list
.head
)
155 hd
.arg1
= ((buf_line_t
*) to
->localClient
->buf_sendq
.list
.head
->data
)->buf
+
156 to
->localClient
->buf_sendq
.writeofs
;
159 if(rb_linebuf_len(&to
->localClient
->buf_sendq
))
162 rb_linebuf_flush(F
, &to
->localClient
->buf_sendq
)) > 0)
164 /* We have some data written .. update counters */
165 #ifdef USE_IODEBUG_HOOKS
167 call_hook(h_iosend_id
, &hd
);
169 if(to
->localClient
->buf_sendq
.list
.head
)
171 ((buf_line_t
*) to
->localClient
->buf_sendq
.list
.head
->
172 data
)->buf
+ to
->localClient
->buf_sendq
.writeofs
;
176 to
->localClient
->sendB
+= retlen
;
177 me
.localClient
->sendB
+= retlen
;
178 if(to
->localClient
->sendB
> 1023)
180 to
->localClient
->sendK
+= (to
->localClient
->sendB
>> 10);
181 to
->localClient
->sendB
&= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */
183 else if(me
.localClient
->sendB
> 1023)
185 me
.localClient
->sendK
+= (me
.localClient
->sendB
>> 10);
186 me
.localClient
->sendB
&= 0x03ff;
190 if(retlen
== 0 || (retlen
< 0 && !rb_ignore_errno(errno
)))
196 if(rb_linebuf_len(&to
->localClient
->buf_sendq
))
197 rb_setselect(to
->localClient
->F
, RB_SELECT_WRITE
,
198 send_queued_write
, to
);
201 /* send_queued_write()
203 * inputs - fd to have queue sent, client we're sending to
204 * outputs - contents of queue
205 * side effects - write is scheduled if queue isnt emptied
208 send_queued_write(rb_fde_t
*F
, void *data
)
210 struct Client
*to
= data
;
215 /* send_queued_slink_write()
217 * inputs - fd to have queue sent, client we're sending to
218 * outputs - contents of queue
219 * side effects - write is rescheduled if queue isnt emptied
222 send_queued_slink_write(int fd
, void *data
)
224 struct Client
*to
= data
;
228 ** Once socket is marked dead, we cannot start writing to it,
229 ** even if the error is removed...
234 /* Next, lets try to write some data */
235 if(to
->localClient
->slinkq
)
237 retlen
= write(to
->localClient
->ctrlfd
,
238 to
->localClient
->slinkq
+ to
->localClient
->slinkq_ofs
,
239 to
->localClient
->slinkq_len
);
243 /* If we have a fatal error */
244 if(!rb_ignore_errno(errno
))
250 /* 0 bytes is an EOF .. */
258 to
->localClient
->slinkq_len
-= retlen
;
260 s_assert(to
->localClient
->slinkq_len
>= 0);
261 if(to
->localClient
->slinkq_len
)
262 to
->localClient
->slinkq_ofs
+= retlen
;
265 to
->localClient
->slinkq_ofs
= 0;
266 rb_free(to
->localClient
->slinkq
);
267 to
->localClient
->slinkq
= NULL
;
272 /* if we have any more data, reschedule a write */
273 if(to
->localClient
->slinkq_len
)
274 rb_setselect(to
->localClient
->ctrlfd
,
275 RB_SELECT_WRITE
, send_queued_slink_write
, to
);
280 * inputs - client to send to, va_args
281 * outputs - client has message put into its queue
285 sendto_one(struct Client
*target_p
, const char *pattern
, ...)
290 /* send remote if to->from non NULL */
291 if(target_p
->from
!= NULL
)
292 target_p
= target_p
->from
;
294 if(IsIOError(target_p
))
297 rb_linebuf_newbuf(&linebuf
);
299 va_start(args
, pattern
);
300 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
303 _send_linebuf(target_p
, &linebuf
);
305 rb_linebuf_donebuf(&linebuf
);
309 /* sendto_one_prefix()
311 * inputs - client to send to, va_args
312 * outputs - client has message put into its queue
313 * side effects - source(us)/target is chosen based on TS6 capability
316 sendto_one_prefix(struct Client
*target_p
, struct Client
*source_p
,
317 const char *command
, const char *pattern
, ...)
319 struct Client
*dest_p
;
323 /* send remote if to->from non NULL */
324 if(target_p
->from
!= NULL
)
325 dest_p
= target_p
->from
;
329 if(IsIOError(dest_p
))
334 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
338 rb_linebuf_newbuf(&linebuf
);
339 va_start(args
, pattern
);
340 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
342 get_id(source_p
, target_p
),
343 command
, get_id(target_p
, target_p
));
346 _send_linebuf(dest_p
, &linebuf
);
347 rb_linebuf_donebuf(&linebuf
);
350 /* sendto_one_notice()
352 * inputs - client to send to, va_args
353 * outputs - client has a NOTICE put into its queue
354 * side effects - source(us)/target is chosen based on TS6 capability
357 sendto_one_notice(struct Client
*target_p
, const char *pattern
, ...)
359 struct Client
*dest_p
;
364 /* send remote if to->from non NULL */
365 if(target_p
->from
!= NULL
)
366 dest_p
= target_p
->from
;
370 if(IsIOError(dest_p
))
375 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
379 rb_linebuf_newbuf(&linebuf
);
380 va_start(args
, pattern
);
381 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
383 get_id(&me
, target_p
), *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
386 _send_linebuf(dest_p
, &linebuf
);
387 rb_linebuf_donebuf(&linebuf
);
391 /* sendto_one_numeric()
393 * inputs - client to send to, va_args
394 * outputs - client has message put into its queue
395 * side effects - source/target is chosen based on TS6 capability
398 sendto_one_numeric(struct Client
*target_p
, int numeric
, const char *pattern
, ...)
400 struct Client
*dest_p
;
405 /* send remote if to->from non NULL */
406 if(target_p
->from
!= NULL
)
407 dest_p
= target_p
->from
;
411 if(IsIOError(dest_p
))
416 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
420 rb_linebuf_newbuf(&linebuf
);
421 va_start(args
, pattern
);
422 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
424 get_id(&me
, target_p
),
425 numeric
, *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
428 _send_linebuf(dest_p
, &linebuf
);
429 rb_linebuf_donebuf(&linebuf
);
435 * inputs - pointer to client to NOT send to
436 * - caps or'd together which must ALL be present
437 * - caps or'd together which must ALL NOT be present
438 * - printf style format string
439 * - args to format string
441 * side effects - Send a message to all connected servers, except the
442 * client 'one' (if non-NULL), as long as the servers
443 * support ALL capabs in 'caps', and NO capabs in 'nocaps'.
445 * This function was written in an attempt to merge together the other
446 * billion sendto_*serv*() functions, which sprung up with capabs, uids etc
450 sendto_server(struct Client
*one
, struct Channel
*chptr
, unsigned long caps
,
451 unsigned long nocaps
, const char *format
, ...)
454 struct Client
*target_p
;
456 rb_dlink_node
*next_ptr
;
459 /* noone to send to.. */
460 if(rb_dlink_list_length(&serv_list
) == 0)
463 if(chptr
!= NULL
&& *chptr
->chname
!= '#')
466 rb_linebuf_newbuf(&linebuf
);
467 va_start(args
, format
);
468 rb_linebuf_putmsg(&linebuf
, format
, &args
, NULL
);
471 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
473 target_p
= ptr
->data
;
475 /* check against 'one' */
476 if(one
!= NULL
&& (target_p
== one
->from
))
479 /* check we have required capabs */
480 if(!IsCapable(target_p
, caps
))
483 /* check we don't have any forbidden capabs */
484 if(!NotCapable(target_p
, nocaps
))
487 _send_linebuf(target_p
, &linebuf
);
490 rb_linebuf_donebuf(&linebuf
);
494 /* sendto_channel_flags()
496 * inputs - server not to send to, flags needed, source, channel, va_args
497 * outputs - message is sent to channel members
501 sendto_channel_flags(struct Client
*one
, int type
, struct Client
*source_p
,
502 struct Channel
*chptr
, const char *pattern
, ...)
504 static char buf
[BUFSIZE
];
506 buf_head_t rb_linebuf_local
;
507 buf_head_t rb_linebuf_name
;
508 buf_head_t rb_linebuf_id
;
509 struct Client
*target_p
;
510 struct membership
*msptr
;
512 rb_dlink_node
*next_ptr
;
514 rb_linebuf_newbuf(&rb_linebuf_local
);
515 rb_linebuf_newbuf(&rb_linebuf_name
);
516 rb_linebuf_newbuf(&rb_linebuf_id
);
520 va_start(args
, pattern
);
521 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
524 if(IsServer(source_p
))
525 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
526 ":%s %s", source_p
->name
, buf
);
528 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
530 source_p
->name
, source_p
->username
,
531 source_p
->host
, buf
);
533 rb_linebuf_putmsg(&rb_linebuf_name
, NULL
, NULL
, ":%s %s", source_p
->name
, buf
);
534 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
536 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->members
.head
)
539 target_p
= msptr
->client_p
;
541 if(IsIOError(target_p
->from
) || target_p
->from
== one
)
544 if(type
&& ((msptr
->flags
& type
) == 0))
550 if(!MyClient(target_p
))
552 /* if we've got a specific type, target must support
555 if(type
&& NotCapable(target_p
->from
, CAP_CHW
))
558 if(target_p
->from
->serial
!= current_serial
)
560 if(has_id(target_p
->from
))
561 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_id
);
563 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_name
);
565 target_p
->from
->serial
= current_serial
;
569 _send_linebuf(target_p
, &rb_linebuf_local
);
572 rb_linebuf_donebuf(&rb_linebuf_local
);
573 rb_linebuf_donebuf(&rb_linebuf_name
);
574 rb_linebuf_donebuf(&rb_linebuf_id
);
578 /* sendto_channel_local()
580 * inputs - flags to send to, channel to send to, va_args
581 * outputs - message to local channel members
585 sendto_channel_local(int type
, struct Channel
*chptr
, const char *pattern
, ...)
589 struct membership
*msptr
;
590 struct Client
*target_p
;
592 rb_dlink_node
*next_ptr
;
594 rb_linebuf_newbuf(&linebuf
);
596 va_start(args
, pattern
);
597 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
600 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
603 target_p
= msptr
->client_p
;
605 if(IsIOError(target_p
))
608 if(type
&& ((msptr
->flags
& type
) == 0))
611 _send_linebuf(target_p
, &linebuf
);
614 rb_linebuf_donebuf(&linebuf
);
617 /* sendto_channel_local_butone()
619 * inputs - flags to send to, channel to send to, va_args
620 * - user to ignore when sending
621 * outputs - message to local channel members
625 sendto_channel_local_butone(struct Client
*one
, int type
, struct Channel
*chptr
, const char *pattern
, ...)
629 struct membership
*msptr
;
630 struct Client
*target_p
;
632 rb_dlink_node
*next_ptr
;
634 rb_linebuf_newbuf(&linebuf
);
636 va_start(args
, pattern
);
637 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
640 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
643 target_p
= msptr
->client_p
;
648 if(IsIOError(target_p
))
651 if(type
&& ((msptr
->flags
& type
) == 0))
654 _send_linebuf(target_p
, &linebuf
);
657 rb_linebuf_donebuf(&linebuf
);
661 * sendto_common_channels_local()
663 * inputs - pointer to client
666 * side effects - Sends a message to all people on local server who are
667 * in same channel with user.
668 * used by m_nick.c and exit_one_client.
671 sendto_common_channels_local(struct Client
*user
, const char *pattern
, ...)
675 rb_dlink_node
*next_ptr
;
677 rb_dlink_node
*next_uptr
;
678 struct Channel
*chptr
;
679 struct Client
*target_p
;
680 struct membership
*msptr
;
681 struct membership
*mscptr
;
684 rb_linebuf_newbuf(&linebuf
);
685 va_start(args
, pattern
);
686 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
691 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
694 chptr
= mscptr
->chptr
;
696 RB_DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
699 target_p
= msptr
->client_p
;
701 if(IsIOError(target_p
) ||
702 target_p
->serial
== current_serial
)
705 target_p
->serial
= current_serial
;
706 send_linebuf(target_p
, &linebuf
);
710 /* this can happen when the user isnt in any channels, but we still
711 * need to send them the data, ie a nick change
713 if(MyConnect(user
) && (user
->serial
!= current_serial
))
714 send_linebuf(user
, &linebuf
);
716 rb_linebuf_donebuf(&linebuf
);
720 * sendto_common_channels_local_butone()
722 * inputs - pointer to client
725 * side effects - Sends a message to all people on local server who are
726 * in same channel with user, except for user itself.
729 sendto_common_channels_local_butone(struct Client
*user
, const char *pattern
, ...)
733 rb_dlink_node
*next_ptr
;
735 rb_dlink_node
*next_uptr
;
736 struct Channel
*chptr
;
737 struct Client
*target_p
;
738 struct membership
*msptr
;
739 struct membership
*mscptr
;
742 rb_linebuf_newbuf(&linebuf
);
743 va_start(args
, pattern
);
744 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
748 /* Skip them -- jilles */
749 user
->serial
= current_serial
;
751 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
754 chptr
= mscptr
->chptr
;
756 RB_DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
759 target_p
= msptr
->client_p
;
761 if(IsIOError(target_p
) ||
762 target_p
->serial
== current_serial
)
765 target_p
->serial
= current_serial
;
766 send_linebuf(target_p
, &linebuf
);
770 rb_linebuf_donebuf(&linebuf
);
773 /* sendto_match_butone()
775 * inputs - server not to send to, source, mask, type of mask, va_args
777 * side effects - message is sent to matching clients
780 sendto_match_butone(struct Client
*one
, struct Client
*source_p
,
781 const char *mask
, int what
, const char *pattern
, ...)
783 static char buf
[BUFSIZE
];
785 struct Client
*target_p
;
787 rb_dlink_node
*next_ptr
;
788 buf_head_t rb_linebuf_local
;
789 buf_head_t rb_linebuf_name
;
790 buf_head_t rb_linebuf_id
;
792 rb_linebuf_newbuf(&rb_linebuf_local
);
793 rb_linebuf_newbuf(&rb_linebuf_name
);
794 rb_linebuf_newbuf(&rb_linebuf_id
);
796 va_start(args
, pattern
);
797 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
800 if(IsServer(source_p
))
801 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
802 ":%s %s", source_p
->name
, buf
);
804 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
806 source_p
->name
, source_p
->username
,
807 source_p
->host
, buf
);
809 rb_linebuf_putmsg(&rb_linebuf_name
, NULL
, NULL
, ":%s %s", source_p
->name
, buf
);
810 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
812 if(what
== MATCH_HOST
)
814 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
816 target_p
= ptr
->data
;
818 if(match(mask
, target_p
->host
))
819 _send_linebuf(target_p
, &rb_linebuf_local
);
822 /* what = MATCH_SERVER, if it doesnt match us, just send remote */
823 else if(match(mask
, me
.name
))
825 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
827 target_p
= ptr
->data
;
828 _send_linebuf(target_p
, &rb_linebuf_local
);
832 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
834 target_p
= ptr
->data
;
840 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_id
);
842 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_name
);
845 rb_linebuf_donebuf(&rb_linebuf_local
);
846 rb_linebuf_donebuf(&rb_linebuf_id
);
847 rb_linebuf_donebuf(&rb_linebuf_name
);
850 /* sendto_match_servs()
852 * inputs - source, mask to send to, caps needed, va_args
854 * side effects - message is sent to matching servers with caps.
857 sendto_match_servs(struct Client
*source_p
, const char *mask
, int cap
,
858 int nocap
, const char *pattern
, ...)
860 static char buf
[BUFSIZE
];
863 struct Client
*target_p
;
864 buf_head_t rb_linebuf_id
;
865 buf_head_t rb_linebuf_name
;
867 if(EmptyString(mask
))
870 rb_linebuf_newbuf(&rb_linebuf_id
);
871 rb_linebuf_newbuf(&rb_linebuf_name
);
873 va_start(args
, pattern
);
874 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
877 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
,
878 ":%s %s", use_id(source_p
), buf
);
879 rb_linebuf_putmsg(&rb_linebuf_name
, NULL
, NULL
,
880 ":%s %s", source_p
->name
, buf
);
884 RB_DLINK_FOREACH(ptr
, global_serv_list
.head
)
886 target_p
= ptr
->data
;
888 /* dont send to ourselves, or back to where it came from.. */
889 if(IsMe(target_p
) || target_p
->from
== source_p
->from
)
892 if(target_p
->from
->serial
== current_serial
)
895 if(match(mask
, target_p
->name
))
897 /* if we set the serial here, then we'll never do
898 * a match() again if !IsCapable()
900 target_p
->from
->serial
= current_serial
;
902 if(cap
&& !IsCapable(target_p
->from
, cap
))
905 if(nocap
&& !NotCapable(target_p
->from
, nocap
))
908 if(has_id(target_p
->from
))
909 _send_linebuf(target_p
->from
, &rb_linebuf_id
);
911 _send_linebuf(target_p
->from
, &rb_linebuf_name
);
915 rb_linebuf_donebuf(&rb_linebuf_id
);
916 rb_linebuf_donebuf(&rb_linebuf_name
);
921 * inputs - monitor nick to send to, format, va_args
922 * outputs - message to local users monitoring the given nick
926 sendto_monitor(struct monitor
*monptr
, const char *pattern
, ...)
930 struct Client
*target_p
;
932 rb_dlink_node
*next_ptr
;
934 rb_linebuf_newbuf(&linebuf
);
936 va_start(args
, pattern
);
937 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
940 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, monptr
->users
.head
)
942 target_p
= ptr
->data
;
944 if(IsIOError(target_p
))
947 _send_linebuf(target_p
, &linebuf
);
950 rb_linebuf_donebuf(&linebuf
);
955 * inputs - target, source, va_args
957 * side effects - client is sent message with correct prefix.
960 sendto_anywhere(struct Client
*target_p
, struct Client
*source_p
,
961 const char *command
, const char *pattern
, ...)
966 rb_linebuf_newbuf(&linebuf
);
968 va_start(args
, pattern
);
970 if(MyClient(target_p
))
972 if(IsServer(source_p
))
973 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
974 source_p
->name
, command
,
977 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
979 source_p
->name
, source_p
->username
,
980 source_p
->host
, command
,
984 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
985 get_id(source_p
, target_p
), command
,
986 get_id(target_p
, target_p
));
989 if(MyClient(target_p
))
990 _send_linebuf(target_p
, &linebuf
);
992 send_linebuf_remote(target_p
, source_p
, &linebuf
);
994 rb_linebuf_donebuf(&linebuf
);
997 /* sendto_realops_flags()
999 * inputs - umode needed, level (opers/admin), va_args
1001 * side effects - message is sent to opers with matching umodes
1004 sendto_realops_flags(int flags
, int level
, const char *pattern
, ...)
1006 struct Client
*client_p
;
1008 rb_dlink_node
*next_ptr
;
1012 rb_linebuf_newbuf(&linebuf
);
1014 va_start(args
, pattern
);
1015 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1016 ":%s NOTICE * :*** Notice -- ", me
.name
);
1019 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1021 client_p
= ptr
->data
;
1023 /* If we're sending it to opers and theyre an admin, skip.
1024 * If we're sending it to admins, and theyre not, skip.
1026 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1027 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1030 if(client_p
->umodes
& flags
)
1031 _send_linebuf(client_p
, &linebuf
);
1034 rb_linebuf_donebuf(&linebuf
);
1037 /* sendto_realops_snomask()
1039 * inputs - snomask needed, level (opers/admin), va_args
1041 * side effects - message is sent to opers with matching snomasks
1044 sendto_realops_snomask(int flags
, int level
, const char *pattern
, ...)
1046 static char buf
[BUFSIZE
];
1048 struct Client
*client_p
;
1050 rb_dlink_node
*next_ptr
;
1054 rb_linebuf_newbuf(&linebuf
);
1056 /* Be very sure not to do things like "Trying to send to myself"
1057 * L_NETWIDE, otherwise infinite recursion may result! -- jilles */
1058 if (level
& L_NETWIDE
&& ConfigFileEntry
.global_snotices
)
1060 /* rather a lot of copying around, oh well -- jilles */
1061 va_start(args
, pattern
);
1062 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1064 rb_linebuf_putmsg(&linebuf
, pattern
, NULL
,
1065 ":%s NOTICE * :*** Notice -- %s", me
.name
, buf
);
1066 snobuf
= construct_snobuf(flags
);
1067 if (snobuf
[1] != '\0')
1069 sendto_server(NULL
, NULL
, CAP_ENCAP
|CAP_TS6
, NOCAPS
,
1070 ":%s ENCAP * SNOTE %c :%s",
1071 me
.id
, snobuf
[1], buf
);
1072 sendto_server(NULL
, NULL
, CAP_ENCAP
, CAP_TS6
,
1073 ":%s ENCAP * SNOTE %c :%s",
1074 me
.name
, snobuf
[1], buf
);
1079 va_start(args
, pattern
);
1080 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1081 ":%s NOTICE * :*** Notice -- ", me
.name
);
1084 level
&= ~L_NETWIDE
;
1086 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1088 client_p
= ptr
->data
;
1090 /* If we're sending it to opers and theyre an admin, skip.
1091 * If we're sending it to admins, and theyre not, skip.
1093 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1094 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1097 if(client_p
->snomask
& flags
)
1098 _send_linebuf(client_p
, &linebuf
);
1101 rb_linebuf_donebuf(&linebuf
);
1103 /* sendto_realops_snomask_from()
1105 * inputs - snomask needed, level (opers/admin), source server, va_args
1107 * side effects - message is sent to opers with matching snomask
1110 sendto_realops_snomask_from(int flags
, int level
, struct Client
*source_p
,
1111 const char *pattern
, ...)
1113 struct Client
*client_p
;
1115 rb_dlink_node
*next_ptr
;
1119 rb_linebuf_newbuf(&linebuf
);
1121 va_start(args
, pattern
);
1122 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1123 ":%s NOTICE * :*** Notice -- ", source_p
->name
);
1126 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1128 client_p
= ptr
->data
;
1130 /* If we're sending it to opers and theyre an admin, skip.
1131 * If we're sending it to admins, and theyre not, skip.
1133 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1134 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1137 if(client_p
->snomask
& flags
)
1138 _send_linebuf(client_p
, &linebuf
);
1141 rb_linebuf_donebuf(&linebuf
);
1145 * sendto_wallops_flags
1147 * inputs - flag types of messages to show to real opers
1148 * - client sending request
1149 * - var args input message
1151 * side effects - Send a wallops to local opers
1154 sendto_wallops_flags(int flags
, struct Client
*source_p
, const char *pattern
, ...)
1156 struct Client
*client_p
;
1158 rb_dlink_node
*next_ptr
;
1162 rb_linebuf_newbuf(&linebuf
);
1164 va_start(args
, pattern
);
1166 if(IsPerson(source_p
))
1167 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1168 ":%s!%s@%s WALLOPS :", source_p
->name
,
1169 source_p
->username
, source_p
->host
);
1171 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s WALLOPS :", source_p
->name
);
1175 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, IsPerson(source_p
) && flags
== UMODE_WALLOP
? lclient_list
.head
: local_oper_list
.head
)
1177 client_p
= ptr
->data
;
1179 if(client_p
->umodes
& flags
)
1180 _send_linebuf(client_p
, &linebuf
);
1183 rb_linebuf_donebuf(&linebuf
);
1188 * input - client to send kill to, client to kill, va_args
1190 * side effects - we issue a kill for the client
1193 kill_client(struct Client
*target_p
, struct Client
*diedie
, const char *pattern
, ...)
1198 rb_linebuf_newbuf(&linebuf
);
1200 va_start(args
, pattern
);
1201 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s KILL %s :",
1202 get_id(&me
, target_p
), get_id(diedie
, target_p
));
1205 send_linebuf(target_p
, &linebuf
);
1206 rb_linebuf_donebuf(&linebuf
);
1211 * kill_client_serv_butone
1213 * inputs - pointer to client to not send to
1214 * - pointer to client to kill
1216 * side effects - Send a KILL for the given client
1217 * message to all connected servers
1218 * except the client 'one'. Also deal with
1219 * client being unknown to leaf, as in lazylink...
1222 kill_client_serv_butone(struct Client
*one
, struct Client
*target_p
, const char *pattern
, ...)
1224 static char buf
[BUFSIZE
];
1226 struct Client
*client_p
;
1228 rb_dlink_node
*next_ptr
;
1229 buf_head_t rb_linebuf_id
;
1230 buf_head_t rb_linebuf_name
;
1232 rb_linebuf_newbuf(&rb_linebuf_name
);
1233 rb_linebuf_newbuf(&rb_linebuf_id
);
1235 va_start(args
, pattern
);
1236 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1239 rb_linebuf_putmsg(&rb_linebuf_name
, NULL
, NULL
, ":%s KILL %s :%s",
1240 me
.name
, target_p
->name
, buf
);
1241 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s KILL %s :%s",
1242 use_id(&me
), use_id(target_p
), buf
);
1244 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
1246 client_p
= ptr
->data
;
1248 /* ok, if the client we're supposed to not send to has an
1249 * ID, then we still want to issue the kill there..
1251 if(one
!= NULL
&& (client_p
== one
->from
) &&
1252 (!has_id(client_p
) || !has_id(target_p
)))
1255 if(has_id(client_p
))
1256 _send_linebuf(client_p
, &rb_linebuf_id
);
1258 _send_linebuf(client_p
, &rb_linebuf_name
);
1261 rb_linebuf_donebuf(&rb_linebuf_id
);
1262 rb_linebuf_donebuf(&rb_linebuf_name
);