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 $
34 #include "irc_string.h"
39 #include "sprintf_irc.h"
41 #include "s_newconf.h"
48 #define LOG_BUFSIZE 2048
50 /* send the message to the link the target is attached to */
51 #define send_linebuf(a,b) _send_linebuf((a->from ? a->from : a) ,b)
53 static void send_queued_write(rb_fde_t
*F
, void *data
);
55 unsigned long current_serial
= 0L;
59 * inputs - client to send to, linebuf to attach
61 * side effects - linebuf is attached to client
64 _send_linebuf(struct Client
*to
, buf_head_t
*linebuf
)
68 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send message to myself!");
72 if(!MyConnect(to
) || IsIOError(to
))
75 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > get_sendq(to
))
79 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
80 "Max SendQ limit exceeded for %s: %u > %lu",
81 get_server_name(to
, HIDE_IP
),
82 rb_linebuf_len(&to
->localClient
->buf_sendq
),
85 ilog(L_SERVER
, "Max SendQ limit exceeded for %s: %u > %lu",
86 log_client_name(to
, SHOW_IP
),
87 rb_linebuf_len(&to
->localClient
->buf_sendq
),
92 to
->flags
|= FLAGS_SENDQEX
;
99 /* just attach the linebuf to the sendq instead of
100 * generating a new one
102 rb_linebuf_attach(&to
->localClient
->buf_sendq
, linebuf
);
106 ** Update statistics. The following is slightly incorrect
107 ** because it counts messages even if queued, but bytes
108 ** only really sent. Queued bytes get updated in SendQueued.
110 to
->localClient
->sendM
+= 1;
111 me
.localClient
->sendM
+= 1;
112 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > 0)
117 /* send_linebuf_remote()
119 * inputs - client to attach to, sender, linebuf
121 * side effects - client has linebuf attached
124 send_linebuf_remote(struct Client
*to
, struct Client
*from
, buf_head_t
*linebuf
)
129 /* we assume the caller has already tested for fake direction */
131 _send_linebuf(to
, linebuf
);
135 /* send_queued_write()
137 * inputs - fd to have queue sent, client we're sending to
138 * outputs - contents of queue
139 * side effects - write is rescheduled if queue isnt emptied
142 send_queued(struct Client
*to
)
145 #ifdef USE_IODEBUG_HOOKS
148 rb_fde_t
*F
= to
->localClient
->F
;
152 /* cant write anything to a dead socket. */
156 #ifdef USE_IODEBUG_HOOKS
158 if(to
->localClient
->buf_sendq
.list
.head
)
159 hd
.arg1
= ((buf_line_t
*) to
->localClient
->buf_sendq
.list
.head
->data
)->buf
+
160 to
->localClient
->buf_sendq
.writeofs
;
163 if(rb_linebuf_len(&to
->localClient
->buf_sendq
))
166 rb_linebuf_flush(F
, &to
->localClient
->buf_sendq
)) > 0)
168 /* We have some data written .. update counters */
169 #ifdef USE_IODEBUG_HOOKS
171 call_hook(h_iosend_id
, &hd
);
173 if(to
->localClient
->buf_sendq
.list
.head
)
175 ((buf_line_t
*) to
->localClient
->buf_sendq
.list
.head
->
176 data
)->buf
+ to
->localClient
->buf_sendq
.writeofs
;
180 to
->localClient
->sendB
+= retlen
;
181 me
.localClient
->sendB
+= retlen
;
182 if(to
->localClient
->sendB
> 1023)
184 to
->localClient
->sendK
+= (to
->localClient
->sendB
>> 10);
185 to
->localClient
->sendB
&= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */
187 else if(me
.localClient
->sendB
> 1023)
189 me
.localClient
->sendK
+= (me
.localClient
->sendB
>> 10);
190 me
.localClient
->sendB
&= 0x03ff;
194 if(retlen
== 0 || (retlen
< 0 && !rb_ignore_errno(errno
)))
200 if(rb_linebuf_len(&to
->localClient
->buf_sendq
))
201 rb_setselect(to
->localClient
->F
, RB_SELECT_WRITE
,
202 send_queued_write
, to
);
205 /* send_queued_write()
207 * inputs - fd to have queue sent, client we're sending to
208 * outputs - contents of queue
209 * side effects - write is scheduled if queue isnt emptied
212 send_queued_write(rb_fde_t
*F
, void *data
)
214 struct Client
*to
= data
;
219 /* send_queued_slink_write()
221 * inputs - fd to have queue sent, client we're sending to
222 * outputs - contents of queue
223 * side effects - write is rescheduled if queue isnt emptied
226 send_queued_slink_write(int fd
, void *data
)
228 struct Client
*to
= data
;
232 ** Once socket is marked dead, we cannot start writing to it,
233 ** even if the error is removed...
238 /* Next, lets try to write some data */
239 if(to
->localClient
->slinkq
)
241 retlen
= write(to
->localClient
->ctrlfd
,
242 to
->localClient
->slinkq
+ to
->localClient
->slinkq_ofs
,
243 to
->localClient
->slinkq_len
);
247 /* If we have a fatal error */
248 if(!rb_ignore_errno(errno
))
254 /* 0 bytes is an EOF .. */
262 to
->localClient
->slinkq_len
-= retlen
;
264 s_assert(to
->localClient
->slinkq_len
>= 0);
265 if(to
->localClient
->slinkq_len
)
266 to
->localClient
->slinkq_ofs
+= retlen
;
269 to
->localClient
->slinkq_ofs
= 0;
270 MyFree(to
->localClient
->slinkq
);
271 to
->localClient
->slinkq
= NULL
;
276 /* if we have any more data, reschedule a write */
277 if(to
->localClient
->slinkq_len
)
278 rb_setselect(to
->localClient
->ctrlfd
,
279 RB_SELECT_WRITE
, send_queued_slink_write
, to
);
284 * inputs - client to send to, va_args
285 * outputs - client has message put into its queue
289 sendto_one(struct Client
*target_p
, const char *pattern
, ...)
294 /* send remote if to->from non NULL */
295 if(target_p
->from
!= NULL
)
296 target_p
= target_p
->from
;
298 if(IsIOError(target_p
))
301 rb_linebuf_newbuf(&linebuf
);
303 va_start(args
, pattern
);
304 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
307 _send_linebuf(target_p
, &linebuf
);
309 rb_linebuf_donebuf(&linebuf
);
313 /* sendto_one_prefix()
315 * inputs - client to send to, va_args
316 * outputs - client has message put into its queue
317 * side effects - source(us)/target is chosen based on TS6 capability
320 sendto_one_prefix(struct Client
*target_p
, struct Client
*source_p
,
321 const char *command
, const char *pattern
, ...)
323 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(source_p
, target_p
),
347 command
, get_id(target_p
, target_p
));
350 _send_linebuf(dest_p
, &linebuf
);
351 rb_linebuf_donebuf(&linebuf
);
354 /* sendto_one_notice()
356 * inputs - client to send to, va_args
357 * outputs - client has a NOTICE put into its queue
358 * side effects - source(us)/target is chosen based on TS6 capability
361 sendto_one_notice(struct Client
*target_p
, 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
), *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
390 _send_linebuf(dest_p
, &linebuf
);
391 rb_linebuf_donebuf(&linebuf
);
395 /* sendto_one_numeric()
397 * inputs - client to send to, va_args
398 * outputs - client has message put into its queue
399 * side effects - source/target is chosen based on TS6 capability
402 sendto_one_numeric(struct Client
*target_p
, int numeric
, const char *pattern
, ...)
404 struct Client
*dest_p
;
409 /* send remote if to->from non NULL */
410 if(target_p
->from
!= NULL
)
411 dest_p
= target_p
->from
;
415 if(IsIOError(dest_p
))
420 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
424 rb_linebuf_newbuf(&linebuf
);
425 va_start(args
, pattern
);
426 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
428 get_id(&me
, target_p
),
429 numeric
, *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
432 _send_linebuf(dest_p
, &linebuf
);
433 rb_linebuf_donebuf(&linebuf
);
439 * inputs - pointer to client to NOT send to
440 * - caps or'd together which must ALL be present
441 * - caps or'd together which must ALL NOT be present
442 * - printf style format string
443 * - args to format string
445 * side effects - Send a message to all connected servers, except the
446 * client 'one' (if non-NULL), as long as the servers
447 * support ALL capabs in 'caps', and NO capabs in 'nocaps'.
449 * This function was written in an attempt to merge together the other
450 * billion sendto_*serv*() functions, which sprung up with capabs, uids etc
454 sendto_server(struct Client
*one
, struct Channel
*chptr
, unsigned long caps
,
455 unsigned long nocaps
, const char *format
, ...)
458 struct Client
*target_p
;
460 rb_dlink_node
*next_ptr
;
463 /* noone to send to.. */
464 if(rb_dlink_list_length(&serv_list
) == 0)
467 if(chptr
!= NULL
&& *chptr
->chname
!= '#')
470 rb_linebuf_newbuf(&linebuf
);
471 va_start(args
, format
);
472 rb_linebuf_putmsg(&linebuf
, format
, &args
, NULL
);
475 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
477 target_p
= ptr
->data
;
479 /* check against 'one' */
480 if(one
!= NULL
&& (target_p
== one
->from
))
483 /* check we have required capabs */
484 if(!IsCapable(target_p
, caps
))
487 /* check we don't have any forbidden capabs */
488 if(!NotCapable(target_p
, nocaps
))
491 _send_linebuf(target_p
, &linebuf
);
494 rb_linebuf_donebuf(&linebuf
);
498 /* sendto_channel_flags()
500 * inputs - server not to send to, flags needed, source, channel, va_args
501 * outputs - message is sent to channel members
505 sendto_channel_flags(struct Client
*one
, int type
, struct Client
*source_p
,
506 struct Channel
*chptr
, const char *pattern
, ...)
508 static char buf
[BUFSIZE
];
510 buf_head_t rb_linebuf_local
;
511 buf_head_t rb_linebuf_name
;
512 buf_head_t rb_linebuf_id
;
513 struct Client
*target_p
;
514 struct membership
*msptr
;
516 rb_dlink_node
*next_ptr
;
518 rb_linebuf_newbuf(&rb_linebuf_local
);
519 rb_linebuf_newbuf(&rb_linebuf_name
);
520 rb_linebuf_newbuf(&rb_linebuf_id
);
524 va_start(args
, pattern
);
525 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
528 if(IsServer(source_p
))
529 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
530 ":%s %s", source_p
->name
, buf
);
532 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
534 source_p
->name
, source_p
->username
,
535 source_p
->host
, buf
);
537 rb_linebuf_putmsg(&rb_linebuf_name
, NULL
, NULL
, ":%s %s", source_p
->name
, buf
);
538 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
540 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->members
.head
)
543 target_p
= msptr
->client_p
;
545 if(IsIOError(target_p
->from
) || target_p
->from
== one
)
548 if(type
&& ((msptr
->flags
& type
) == 0))
554 if(!MyClient(target_p
))
556 /* if we've got a specific type, target must support
559 if(type
&& NotCapable(target_p
->from
, CAP_CHW
))
562 if(target_p
->from
->serial
!= current_serial
)
564 if(has_id(target_p
->from
))
565 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_id
);
567 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_name
);
569 target_p
->from
->serial
= current_serial
;
573 _send_linebuf(target_p
, &rb_linebuf_local
);
576 rb_linebuf_donebuf(&rb_linebuf_local
);
577 rb_linebuf_donebuf(&rb_linebuf_name
);
578 rb_linebuf_donebuf(&rb_linebuf_id
);
582 /* sendto_channel_local()
584 * inputs - flags to send to, channel to send to, va_args
585 * outputs - message to local channel members
589 sendto_channel_local(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
;
609 if(IsIOError(target_p
))
612 if(type
&& ((msptr
->flags
& type
) == 0))
615 _send_linebuf(target_p
, &linebuf
);
618 rb_linebuf_donebuf(&linebuf
);
621 /* sendto_channel_local_butone()
623 * inputs - flags to send to, channel to send to, va_args
624 * - user to ignore when sending
625 * outputs - message to local channel members
629 sendto_channel_local_butone(struct Client
*one
, 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
;
652 if(IsIOError(target_p
))
655 if(type
&& ((msptr
->flags
& type
) == 0))
658 _send_linebuf(target_p
, &linebuf
);
661 rb_linebuf_donebuf(&linebuf
);
665 * sendto_common_channels_local()
667 * inputs - pointer to client
670 * side effects - Sends a message to all people on local server who are
671 * in same channel with user.
672 * used by m_nick.c and exit_one_client.
675 sendto_common_channels_local(struct Client
*user
, const char *pattern
, ...)
679 rb_dlink_node
*next_ptr
;
681 rb_dlink_node
*next_uptr
;
682 struct Channel
*chptr
;
683 struct Client
*target_p
;
684 struct membership
*msptr
;
685 struct membership
*mscptr
;
688 rb_linebuf_newbuf(&linebuf
);
689 va_start(args
, pattern
);
690 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
695 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
698 chptr
= mscptr
->chptr
;
700 RB_DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
703 target_p
= msptr
->client_p
;
705 if(IsIOError(target_p
) ||
706 target_p
->serial
== current_serial
)
709 target_p
->serial
= current_serial
;
710 send_linebuf(target_p
, &linebuf
);
714 /* this can happen when the user isnt in any channels, but we still
715 * need to send them the data, ie a nick change
717 if(MyConnect(user
) && (user
->serial
!= current_serial
))
718 send_linebuf(user
, &linebuf
);
720 rb_linebuf_donebuf(&linebuf
);
724 * sendto_common_channels_local_butone()
726 * inputs - pointer to client
729 * side effects - Sends a message to all people on local server who are
730 * in same channel with user, except for user itself.
733 sendto_common_channels_local_butone(struct Client
*user
, const char *pattern
, ...)
737 rb_dlink_node
*next_ptr
;
739 rb_dlink_node
*next_uptr
;
740 struct Channel
*chptr
;
741 struct Client
*target_p
;
742 struct membership
*msptr
;
743 struct membership
*mscptr
;
746 rb_linebuf_newbuf(&linebuf
);
747 va_start(args
, pattern
);
748 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
752 /* Skip them -- jilles */
753 user
->serial
= current_serial
;
755 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
758 chptr
= mscptr
->chptr
;
760 RB_DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
763 target_p
= msptr
->client_p
;
765 if(IsIOError(target_p
) ||
766 target_p
->serial
== current_serial
)
769 target_p
->serial
= current_serial
;
770 send_linebuf(target_p
, &linebuf
);
774 rb_linebuf_donebuf(&linebuf
);
777 /* sendto_match_butone()
779 * inputs - server not to send to, source, mask, type of mask, va_args
781 * side effects - message is sent to matching clients
784 sendto_match_butone(struct Client
*one
, struct Client
*source_p
,
785 const char *mask
, int what
, const char *pattern
, ...)
787 static char buf
[BUFSIZE
];
789 struct Client
*target_p
;
791 rb_dlink_node
*next_ptr
;
792 buf_head_t rb_linebuf_local
;
793 buf_head_t rb_linebuf_name
;
794 buf_head_t rb_linebuf_id
;
796 rb_linebuf_newbuf(&rb_linebuf_local
);
797 rb_linebuf_newbuf(&rb_linebuf_name
);
798 rb_linebuf_newbuf(&rb_linebuf_id
);
800 va_start(args
, pattern
);
801 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
804 if(IsServer(source_p
))
805 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
806 ":%s %s", source_p
->name
, buf
);
808 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
810 source_p
->name
, source_p
->username
,
811 source_p
->host
, buf
);
813 rb_linebuf_putmsg(&rb_linebuf_name
, NULL
, NULL
, ":%s %s", source_p
->name
, buf
);
814 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
816 if(what
== MATCH_HOST
)
818 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
820 target_p
= ptr
->data
;
822 if(match(mask
, target_p
->host
))
823 _send_linebuf(target_p
, &rb_linebuf_local
);
826 /* what = MATCH_SERVER, if it doesnt match us, just send remote */
827 else if(match(mask
, me
.name
))
829 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
831 target_p
= ptr
->data
;
832 _send_linebuf(target_p
, &rb_linebuf_local
);
836 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
838 target_p
= ptr
->data
;
844 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_id
);
846 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_name
);
849 rb_linebuf_donebuf(&rb_linebuf_local
);
850 rb_linebuf_donebuf(&rb_linebuf_id
);
851 rb_linebuf_donebuf(&rb_linebuf_name
);
854 /* sendto_match_servs()
856 * inputs - source, mask to send to, caps needed, va_args
858 * side effects - message is sent to matching servers with caps.
861 sendto_match_servs(struct Client
*source_p
, const char *mask
, int cap
,
862 int nocap
, const char *pattern
, ...)
864 static char buf
[BUFSIZE
];
867 struct Client
*target_p
;
868 buf_head_t rb_linebuf_id
;
869 buf_head_t rb_linebuf_name
;
871 if(EmptyString(mask
))
874 rb_linebuf_newbuf(&rb_linebuf_id
);
875 rb_linebuf_newbuf(&rb_linebuf_name
);
877 va_start(args
, pattern
);
878 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
881 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
,
882 ":%s %s", use_id(source_p
), buf
);
883 rb_linebuf_putmsg(&rb_linebuf_name
, NULL
, NULL
,
884 ":%s %s", source_p
->name
, buf
);
888 RB_DLINK_FOREACH(ptr
, global_serv_list
.head
)
890 target_p
= ptr
->data
;
892 /* dont send to ourselves, or back to where it came from.. */
893 if(IsMe(target_p
) || target_p
->from
== source_p
->from
)
896 if(target_p
->from
->serial
== current_serial
)
899 if(match(mask
, target_p
->name
))
901 /* if we set the serial here, then we'll never do
902 * a match() again if !IsCapable()
904 target_p
->from
->serial
= current_serial
;
906 if(cap
&& !IsCapable(target_p
->from
, cap
))
909 if(nocap
&& !NotCapable(target_p
->from
, nocap
))
912 if(has_id(target_p
->from
))
913 _send_linebuf(target_p
->from
, &rb_linebuf_id
);
915 _send_linebuf(target_p
->from
, &rb_linebuf_name
);
919 rb_linebuf_donebuf(&rb_linebuf_id
);
920 rb_linebuf_donebuf(&rb_linebuf_name
);
925 * inputs - monitor nick to send to, format, va_args
926 * outputs - message to local users monitoring the given nick
930 sendto_monitor(struct monitor
*monptr
, const char *pattern
, ...)
934 struct Client
*target_p
;
936 rb_dlink_node
*next_ptr
;
938 rb_linebuf_newbuf(&linebuf
);
940 va_start(args
, pattern
);
941 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
944 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, monptr
->users
.head
)
946 target_p
= ptr
->data
;
948 if(IsIOError(target_p
))
951 _send_linebuf(target_p
, &linebuf
);
954 rb_linebuf_donebuf(&linebuf
);
959 * inputs - target, source, va_args
961 * side effects - client is sent message with correct prefix.
964 sendto_anywhere(struct Client
*target_p
, struct Client
*source_p
,
965 const char *command
, const char *pattern
, ...)
970 rb_linebuf_newbuf(&linebuf
);
972 va_start(args
, pattern
);
974 if(MyClient(target_p
))
976 if(IsServer(source_p
))
977 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
978 source_p
->name
, command
,
981 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
983 source_p
->name
, source_p
->username
,
984 source_p
->host
, command
,
988 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
989 get_id(source_p
, target_p
), command
,
990 get_id(target_p
, target_p
));
993 if(MyClient(target_p
))
994 _send_linebuf(target_p
, &linebuf
);
996 send_linebuf_remote(target_p
, source_p
, &linebuf
);
998 rb_linebuf_donebuf(&linebuf
);
1001 /* sendto_realops_flags()
1003 * inputs - umode needed, level (opers/admin), va_args
1005 * side effects - message is sent to opers with matching umodes
1008 sendto_realops_flags(int flags
, int level
, const char *pattern
, ...)
1010 struct Client
*client_p
;
1012 rb_dlink_node
*next_ptr
;
1016 rb_linebuf_newbuf(&linebuf
);
1018 va_start(args
, pattern
);
1019 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1020 ":%s NOTICE * :*** Notice -- ", me
.name
);
1023 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1025 client_p
= ptr
->data
;
1027 /* If we're sending it to opers and theyre an admin, skip.
1028 * If we're sending it to admins, and theyre not, skip.
1030 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1031 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1034 if(client_p
->umodes
& flags
)
1035 _send_linebuf(client_p
, &linebuf
);
1038 rb_linebuf_donebuf(&linebuf
);
1041 /* sendto_realops_snomask()
1043 * inputs - snomask needed, level (opers/admin), va_args
1045 * side effects - message is sent to opers with matching snomasks
1048 sendto_realops_snomask(int flags
, int level
, const char *pattern
, ...)
1050 static char buf
[BUFSIZE
];
1052 struct Client
*client_p
;
1054 rb_dlink_node
*next_ptr
;
1058 rb_linebuf_newbuf(&linebuf
);
1060 /* Be very sure not to do things like "Trying to send to myself"
1061 * L_NETWIDE, otherwise infinite recursion may result! -- jilles */
1062 if (level
& L_NETWIDE
&& ConfigFileEntry
.global_snotices
)
1064 /* rather a lot of copying around, oh well -- jilles */
1065 va_start(args
, pattern
);
1066 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1068 rb_linebuf_putmsg(&linebuf
, pattern
, NULL
,
1069 ":%s NOTICE * :*** Notice -- %s", me
.name
, buf
);
1070 snobuf
= construct_snobuf(flags
);
1071 if (snobuf
[1] != '\0')
1073 sendto_server(NULL
, NULL
, CAP_ENCAP
|CAP_TS6
, NOCAPS
,
1074 ":%s ENCAP * SNOTE %c :%s",
1075 me
.id
, snobuf
[1], buf
);
1076 sendto_server(NULL
, NULL
, CAP_ENCAP
, CAP_TS6
,
1077 ":%s ENCAP * SNOTE %c :%s",
1078 me
.name
, snobuf
[1], buf
);
1083 va_start(args
, pattern
);
1084 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1085 ":%s NOTICE * :*** Notice -- ", me
.name
);
1088 level
&= ~L_NETWIDE
;
1090 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1092 client_p
= ptr
->data
;
1094 /* If we're sending it to opers and theyre an admin, skip.
1095 * If we're sending it to admins, and theyre not, skip.
1097 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1098 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1101 if(client_p
->snomask
& flags
)
1102 _send_linebuf(client_p
, &linebuf
);
1105 rb_linebuf_donebuf(&linebuf
);
1107 /* sendto_realops_snomask_from()
1109 * inputs - snomask needed, level (opers/admin), source server, va_args
1111 * side effects - message is sent to opers with matching snomask
1114 sendto_realops_snomask_from(int flags
, int level
, struct Client
*source_p
,
1115 const char *pattern
, ...)
1117 struct Client
*client_p
;
1119 rb_dlink_node
*next_ptr
;
1123 rb_linebuf_newbuf(&linebuf
);
1125 va_start(args
, pattern
);
1126 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1127 ":%s NOTICE * :*** Notice -- ", source_p
->name
);
1130 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1132 client_p
= ptr
->data
;
1134 /* If we're sending it to opers and theyre an admin, skip.
1135 * If we're sending it to admins, and theyre not, skip.
1137 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1138 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1141 if(client_p
->snomask
& flags
)
1142 _send_linebuf(client_p
, &linebuf
);
1145 rb_linebuf_donebuf(&linebuf
);
1149 * sendto_wallops_flags
1151 * inputs - flag types of messages to show to real opers
1152 * - client sending request
1153 * - var args input message
1155 * side effects - Send a wallops to local opers
1158 sendto_wallops_flags(int flags
, struct Client
*source_p
, const char *pattern
, ...)
1160 struct Client
*client_p
;
1162 rb_dlink_node
*next_ptr
;
1166 rb_linebuf_newbuf(&linebuf
);
1168 va_start(args
, pattern
);
1170 if(IsPerson(source_p
))
1171 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1172 ":%s!%s@%s WALLOPS :", source_p
->name
,
1173 source_p
->username
, source_p
->host
);
1175 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s WALLOPS :", source_p
->name
);
1179 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, IsPerson(source_p
) && flags
== UMODE_WALLOP
? lclient_list
.head
: local_oper_list
.head
)
1181 client_p
= ptr
->data
;
1183 if(client_p
->umodes
& flags
)
1184 _send_linebuf(client_p
, &linebuf
);
1187 rb_linebuf_donebuf(&linebuf
);
1192 * input - client to send kill to, client to kill, va_args
1194 * side effects - we issue a kill for the client
1197 kill_client(struct Client
*target_p
, struct Client
*diedie
, const char *pattern
, ...)
1202 rb_linebuf_newbuf(&linebuf
);
1204 va_start(args
, pattern
);
1205 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s KILL %s :",
1206 get_id(&me
, target_p
), get_id(diedie
, target_p
));
1209 send_linebuf(target_p
, &linebuf
);
1210 rb_linebuf_donebuf(&linebuf
);
1215 * kill_client_serv_butone
1217 * inputs - pointer to client to not send to
1218 * - pointer to client to kill
1220 * side effects - Send a KILL for the given client
1221 * message to all connected servers
1222 * except the client 'one'. Also deal with
1223 * client being unknown to leaf, as in lazylink...
1226 kill_client_serv_butone(struct Client
*one
, struct Client
*target_p
, const char *pattern
, ...)
1228 static char buf
[BUFSIZE
];
1230 struct Client
*client_p
;
1232 rb_dlink_node
*next_ptr
;
1233 buf_head_t rb_linebuf_id
;
1234 buf_head_t rb_linebuf_name
;
1236 rb_linebuf_newbuf(&rb_linebuf_name
);
1237 rb_linebuf_newbuf(&rb_linebuf_id
);
1239 va_start(args
, pattern
);
1240 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1243 rb_linebuf_putmsg(&rb_linebuf_name
, NULL
, NULL
, ":%s KILL %s :%s",
1244 me
.name
, target_p
->name
, buf
);
1245 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s KILL %s :%s",
1246 use_id(&me
), use_id(target_p
), buf
);
1248 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
1250 client_p
= ptr
->data
;
1252 /* ok, if the client we're supposed to not send to has an
1253 * ID, then we still want to issue the kill there..
1255 if(one
!= NULL
&& (client_p
== one
->from
) &&
1256 (!has_id(client_p
) || !has_id(target_p
)))
1259 if(has_id(client_p
))
1260 _send_linebuf(client_p
, &rb_linebuf_id
);
1262 _send_linebuf(client_p
, &rb_linebuf_name
);
1265 rb_linebuf_donebuf(&rb_linebuf_id
);
1266 rb_linebuf_donebuf(&rb_linebuf_name
);