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
37 #include "s_newconf.h"
42 #define LOG_BUFSIZE 2048
44 /* send the message to the link the target is attached to */
45 #define send_linebuf(a,b) _send_linebuf((a->from ? a->from : a) ,b)
47 static void send_queued_write(rb_fde_t
*F
, void *data
);
49 unsigned long current_serial
= 0L;
51 struct Client
*remote_rehash_oper_p
;
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",
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
),
92 /* just attach the linebuf to the sendq instead of
93 * generating a new one
95 rb_linebuf_attach(&to
->localClient
->buf_sendq
, linebuf
);
99 ** Update statistics. The following is slightly incorrect
100 ** because it counts messages even if queued, but bytes
101 ** only really sent. Queued bytes get updated in SendQueued.
103 to
->localClient
->sendM
+= 1;
104 me
.localClient
->sendM
+= 1;
105 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > 0)
110 /* send_linebuf_remote()
112 * inputs - client to attach to, sender, linebuf
114 * side effects - client has linebuf attached
117 send_linebuf_remote(struct Client
*to
, struct Client
*from
, buf_head_t
*linebuf
)
122 /* we assume the caller has already tested for fake direction */
124 _send_linebuf(to
, linebuf
);
128 /* send_queued_write()
130 * inputs - fd to have queue sent, client we're sending to
131 * outputs - contents of queue
132 * side effects - write is rescheduled if queue isnt emptied
135 send_queued(struct Client
*to
)
138 #ifdef USE_IODEBUG_HOOKS
141 rb_fde_t
*F
= to
->localClient
->F
;
145 /* cant write anything to a dead socket. */
149 /* Something wants us to not send anything currently */
153 /* try to flush later when the write event resets this */
157 #ifdef USE_IODEBUG_HOOKS
159 if(to
->localClient
->buf_sendq
.list
.head
)
160 hd
.arg1
= ((buf_line_t
*) to
->localClient
->buf_sendq
.list
.head
->data
)->buf
+
161 to
->localClient
->buf_sendq
.writeofs
;
164 if(rb_linebuf_len(&to
->localClient
->buf_sendq
))
167 rb_linebuf_flush(F
, &to
->localClient
->buf_sendq
)) > 0)
169 /* We have some data written .. update counters */
170 #ifdef USE_IODEBUG_HOOKS
172 call_hook(h_iosend_id
, &hd
);
174 if(to
->localClient
->buf_sendq
.list
.head
)
176 ((buf_line_t
*) to
->localClient
->buf_sendq
.list
.head
->
177 data
)->buf
+ to
->localClient
->buf_sendq
.writeofs
;
183 to
->localClient
->sendB
+= retlen
;
184 me
.localClient
->sendB
+= retlen
;
185 if(to
->localClient
->sendB
> 1023)
187 to
->localClient
->sendK
+= (to
->localClient
->sendB
>> 10);
188 to
->localClient
->sendB
&= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */
190 else if(me
.localClient
->sendB
> 1023)
192 me
.localClient
->sendK
+= (me
.localClient
->sendB
>> 10);
193 me
.localClient
->sendB
&= 0x03ff;
197 if(retlen
== 0 || (retlen
< 0 && !rb_ignore_errno(errno
)))
204 if(rb_linebuf_len(&to
->localClient
->buf_sendq
))
207 rb_setselect(to
->localClient
->F
, RB_SELECT_WRITE
,
208 send_queued_write
, to
);
215 send_pop_queue(struct Client
*to
)
219 if(!MyConnect(to
) || IsIOError(to
))
221 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > 0)
225 /* send_queued_write()
227 * inputs - fd to have queue sent, client we're sending to
228 * outputs - contents of queue
229 * side effects - write is scheduled if queue isnt emptied
232 send_queued_write(rb_fde_t
*F
, void *data
)
234 struct Client
*to
= data
;
241 * inputs - client to send to, va_args
242 * outputs - client has message put into its queue
246 sendto_one(struct Client
*target_p
, const char *pattern
, ...)
251 /* send remote if to->from non NULL */
252 if(target_p
->from
!= NULL
)
253 target_p
= target_p
->from
;
255 if(IsIOError(target_p
))
258 rb_linebuf_newbuf(&linebuf
);
260 va_start(args
, pattern
);
261 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
264 _send_linebuf(target_p
, &linebuf
);
266 rb_linebuf_donebuf(&linebuf
);
270 /* sendto_one_prefix()
272 * inputs - client to send to, va_args
273 * outputs - client has message put into its queue
274 * side effects - source(us)/target is chosen based on TS6 capability
277 sendto_one_prefix(struct Client
*target_p
, struct Client
*source_p
,
278 const char *command
, const char *pattern
, ...)
280 struct Client
*dest_p
;
284 /* send remote if to->from non NULL */
285 if(target_p
->from
!= NULL
)
286 dest_p
= target_p
->from
;
290 if(IsIOError(dest_p
))
295 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
299 rb_linebuf_newbuf(&linebuf
);
300 va_start(args
, pattern
);
301 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
303 get_id(source_p
, target_p
),
304 command
, get_id(target_p
, target_p
));
307 _send_linebuf(dest_p
, &linebuf
);
308 rb_linebuf_donebuf(&linebuf
);
311 /* sendto_one_notice()
313 * inputs - client to send to, va_args
314 * outputs - client has a NOTICE put into its queue
315 * side effects - source(us)/target is chosen based on TS6 capability
318 sendto_one_notice(struct Client
*target_p
, const char *pattern
, ...)
320 struct Client
*dest_p
;
325 /* send remote if to->from non NULL */
326 if(target_p
->from
!= NULL
)
327 dest_p
= target_p
->from
;
331 if(IsIOError(dest_p
))
336 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
340 rb_linebuf_newbuf(&linebuf
);
341 va_start(args
, pattern
);
342 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
344 get_id(&me
, target_p
), *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
347 _send_linebuf(dest_p
, &linebuf
);
348 rb_linebuf_donebuf(&linebuf
);
352 /* sendto_one_numeric()
354 * inputs - client to send to, va_args
355 * outputs - client has message put into its queue
356 * side effects - source/target is chosen based on TS6 capability
359 sendto_one_numeric(struct Client
*target_p
, int numeric
, const char *pattern
, ...)
361 struct Client
*dest_p
;
366 /* send remote if to->from non NULL */
367 if(target_p
->from
!= NULL
)
368 dest_p
= target_p
->from
;
372 if(IsIOError(dest_p
))
377 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
381 rb_linebuf_newbuf(&linebuf
);
382 va_start(args
, pattern
);
383 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
385 get_id(&me
, target_p
),
386 numeric
, *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
389 _send_linebuf(dest_p
, &linebuf
);
390 rb_linebuf_donebuf(&linebuf
);
396 * inputs - pointer to client to NOT send to
397 * - caps or'd together which must ALL be present
398 * - caps or'd together which must ALL NOT be present
399 * - printf style format string
400 * - args to format string
402 * side effects - Send a message to all connected servers, except the
403 * client 'one' (if non-NULL), as long as the servers
404 * support ALL capabs in 'caps', and NO capabs in 'nocaps'.
406 * This function was written in an attempt to merge together the other
407 * billion sendto_*serv*() functions, which sprung up with capabs, uids etc
411 sendto_server(struct Client
*one
, struct Channel
*chptr
, unsigned long caps
,
412 unsigned long nocaps
, const char *format
, ...)
415 struct Client
*target_p
;
417 rb_dlink_node
*next_ptr
;
420 /* noone to send to.. */
421 if(rb_dlink_list_length(&serv_list
) == 0)
424 if(chptr
!= NULL
&& *chptr
->chname
!= '#')
427 rb_linebuf_newbuf(&linebuf
);
428 va_start(args
, format
);
429 rb_linebuf_putmsg(&linebuf
, format
, &args
, NULL
);
432 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
434 target_p
= ptr
->data
;
436 /* check against 'one' */
437 if(one
!= NULL
&& (target_p
== one
->from
))
440 /* check we have required capabs */
441 if(!IsCapable(target_p
, caps
))
444 /* check we don't have any forbidden capabs */
445 if(!NotCapable(target_p
, nocaps
))
448 _send_linebuf(target_p
, &linebuf
);
451 rb_linebuf_donebuf(&linebuf
);
455 /* sendto_channel_flags()
457 * inputs - server not to send to, flags needed, source, channel, va_args
458 * outputs - message is sent to channel members
462 sendto_channel_flags(struct Client
*one
, int type
, struct Client
*source_p
,
463 struct Channel
*chptr
, const char *pattern
, ...)
465 static char buf
[BUFSIZE
];
467 buf_head_t rb_linebuf_local
;
468 buf_head_t rb_linebuf_id
;
469 struct Client
*target_p
;
470 struct membership
*msptr
;
472 rb_dlink_node
*next_ptr
;
474 rb_linebuf_newbuf(&rb_linebuf_local
);
475 rb_linebuf_newbuf(&rb_linebuf_id
);
479 va_start(args
, pattern
);
480 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
483 if(IsServer(source_p
))
484 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
485 ":%s %s", source_p
->name
, buf
);
487 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
489 source_p
->name
, source_p
->username
,
490 source_p
->host
, buf
);
492 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
494 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->members
.head
)
497 target_p
= msptr
->client_p
;
499 if(IsIOError(target_p
->from
) || target_p
->from
== one
)
502 if(type
&& ((msptr
->flags
& type
) == 0))
508 if(!MyClient(target_p
))
510 /* if we've got a specific type, target must support
513 if(type
&& NotCapable(target_p
->from
, CAP_CHW
))
516 if(target_p
->from
->serial
!= current_serial
)
518 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_id
);
519 target_p
->from
->serial
= current_serial
;
523 _send_linebuf(target_p
, &rb_linebuf_local
);
526 rb_linebuf_donebuf(&rb_linebuf_local
);
527 rb_linebuf_donebuf(&rb_linebuf_id
);
530 /* sendto_channel_flags()
532 * inputs - server not to send to, flags needed, source, channel, va_args
533 * outputs - message is sent to channel members
537 sendto_channel_opmod(struct Client
*one
, struct Client
*source_p
,
538 struct Channel
*chptr
, const char *command
,
541 buf_head_t rb_linebuf_local
;
542 buf_head_t rb_linebuf_old
;
543 buf_head_t rb_linebuf_new
;
544 struct Client
*target_p
;
545 struct membership
*msptr
;
547 rb_dlink_node
*next_ptr
;
549 rb_linebuf_newbuf(&rb_linebuf_local
);
550 rb_linebuf_newbuf(&rb_linebuf_old
);
551 rb_linebuf_newbuf(&rb_linebuf_new
);
555 if(IsServer(source_p
))
556 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
558 source_p
->name
, command
, chptr
->chname
, text
);
560 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
561 ":%s!%s@%s %s %s :%s",
562 source_p
->name
, source_p
->username
,
563 source_p
->host
, command
, chptr
->chname
, text
);
565 if (chptr
->mode
.mode
& MODE_MODERATED
)
566 rb_linebuf_putmsg(&rb_linebuf_old
, NULL
, NULL
,
568 use_id(source_p
), command
, chptr
->chname
, text
);
570 rb_linebuf_putmsg(&rb_linebuf_old
, NULL
, NULL
,
571 ":%s NOTICE @%s :<%s:%s> %s",
572 use_id(source_p
->servptr
), chptr
->chname
,
573 source_p
->name
, chptr
->chname
, text
);
574 rb_linebuf_putmsg(&rb_linebuf_new
, NULL
, NULL
,
576 use_id(source_p
), command
, chptr
->chname
, text
);
578 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->members
.head
)
581 target_p
= msptr
->client_p
;
583 if(IsIOError(target_p
->from
) || target_p
->from
== one
)
586 if(!is_any_op(msptr
))
592 if(!MyClient(target_p
))
594 /* if we've got a specific type, target must support
597 if(NotCapable(target_p
->from
, CAP_CHW
))
600 if(target_p
->from
->serial
!= current_serial
)
602 if (IsCapable(target_p
->from
, CAP_EOPMOD
))
603 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_new
);
605 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_old
);
606 target_p
->from
->serial
= current_serial
;
610 _send_linebuf(target_p
, &rb_linebuf_local
);
613 rb_linebuf_donebuf(&rb_linebuf_local
);
614 rb_linebuf_donebuf(&rb_linebuf_old
);
615 rb_linebuf_donebuf(&rb_linebuf_new
);
618 /* sendto_channel_local()
620 * inputs - flags to send to, channel to send to, va_args
621 * outputs - message to local channel members
625 sendto_channel_local(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
;
645 if(IsIOError(target_p
))
648 if(type
== ONLY_OPERS
)
650 if(!IsOper(target_p
))
653 else if(type
&& ((msptr
->flags
& type
) == 0))
656 _send_linebuf(target_p
, &linebuf
);
659 rb_linebuf_donebuf(&linebuf
);
662 /* sendto_channel_local_butone()
664 * inputs - flags to send to, channel to send to, va_args
665 * - user to ignore when sending
666 * outputs - message to local channel members
670 sendto_channel_local_butone(struct Client
*one
, int type
, struct Channel
*chptr
, const char *pattern
, ...)
674 struct membership
*msptr
;
675 struct Client
*target_p
;
677 rb_dlink_node
*next_ptr
;
679 rb_linebuf_newbuf(&linebuf
);
681 va_start(args
, pattern
);
682 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
685 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
688 target_p
= msptr
->client_p
;
693 if(IsIOError(target_p
))
696 if(type
&& ((msptr
->flags
& type
) == 0))
699 _send_linebuf(target_p
, &linebuf
);
702 rb_linebuf_donebuf(&linebuf
);
706 * sendto_common_channels_local()
708 * inputs - pointer to client
711 * side effects - Sends a message to all people on local server who are
712 * in same channel with user.
713 * used by m_nick.c and exit_one_client.
716 sendto_common_channels_local(struct Client
*user
, const char *pattern
, ...)
720 rb_dlink_node
*next_ptr
;
722 rb_dlink_node
*next_uptr
;
723 struct Channel
*chptr
;
724 struct Client
*target_p
;
725 struct membership
*msptr
;
726 struct membership
*mscptr
;
729 rb_linebuf_newbuf(&linebuf
);
730 va_start(args
, pattern
);
731 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
736 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
739 chptr
= mscptr
->chptr
;
741 RB_DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
744 target_p
= msptr
->client_p
;
746 if(IsIOError(target_p
) ||
747 target_p
->serial
== current_serial
)
750 target_p
->serial
= current_serial
;
751 send_linebuf(target_p
, &linebuf
);
755 /* this can happen when the user isnt in any channels, but we still
756 * need to send them the data, ie a nick change
758 if(MyConnect(user
) && (user
->serial
!= current_serial
))
759 send_linebuf(user
, &linebuf
);
761 rb_linebuf_donebuf(&linebuf
);
765 * sendto_common_channels_local_butone()
767 * inputs - pointer to client
770 * side effects - Sends a message to all people on local server who are
771 * in same channel with user, except for user itself.
774 sendto_common_channels_local_butone(struct Client
*user
, const char *pattern
, ...)
778 rb_dlink_node
*next_ptr
;
780 rb_dlink_node
*next_uptr
;
781 struct Channel
*chptr
;
782 struct Client
*target_p
;
783 struct membership
*msptr
;
784 struct membership
*mscptr
;
787 rb_linebuf_newbuf(&linebuf
);
788 va_start(args
, pattern
);
789 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
793 /* Skip them -- jilles */
794 user
->serial
= current_serial
;
796 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
799 chptr
= mscptr
->chptr
;
801 RB_DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
804 target_p
= msptr
->client_p
;
806 if(IsIOError(target_p
) ||
807 target_p
->serial
== current_serial
)
810 target_p
->serial
= current_serial
;
811 send_linebuf(target_p
, &linebuf
);
815 rb_linebuf_donebuf(&linebuf
);
818 /* sendto_match_butone()
820 * inputs - server not to send to, source, mask, type of mask, va_args
822 * side effects - message is sent to matching clients
825 sendto_match_butone(struct Client
*one
, struct Client
*source_p
,
826 const char *mask
, int what
, const char *pattern
, ...)
828 static char buf
[BUFSIZE
];
830 struct Client
*target_p
;
832 rb_dlink_node
*next_ptr
;
833 buf_head_t rb_linebuf_local
;
834 buf_head_t rb_linebuf_id
;
836 rb_linebuf_newbuf(&rb_linebuf_local
);
837 rb_linebuf_newbuf(&rb_linebuf_id
);
839 va_start(args
, pattern
);
840 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
843 if(IsServer(source_p
))
844 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
845 ":%s %s", source_p
->name
, buf
);
847 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
849 source_p
->name
, source_p
->username
,
850 source_p
->host
, buf
);
852 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
854 if(what
== MATCH_HOST
)
856 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
858 target_p
= ptr
->data
;
860 if(match(mask
, target_p
->host
))
861 _send_linebuf(target_p
, &rb_linebuf_local
);
864 /* what = MATCH_SERVER, if it doesnt match us, just send remote */
865 else if(match(mask
, me
.name
))
867 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
869 target_p
= ptr
->data
;
870 _send_linebuf(target_p
, &rb_linebuf_local
);
874 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
876 target_p
= ptr
->data
;
881 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_id
);
884 rb_linebuf_donebuf(&rb_linebuf_local
);
885 rb_linebuf_donebuf(&rb_linebuf_id
);
888 /* sendto_match_servs()
890 * inputs - source, mask to send to, caps needed, va_args
892 * side effects - message is sent to matching servers with caps.
895 sendto_match_servs(struct Client
*source_p
, const char *mask
, int cap
,
896 int nocap
, const char *pattern
, ...)
898 static char buf
[BUFSIZE
];
901 struct Client
*target_p
;
902 buf_head_t rb_linebuf_id
;
904 if(EmptyString(mask
))
907 rb_linebuf_newbuf(&rb_linebuf_id
);
909 va_start(args
, pattern
);
910 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
913 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
,
914 ":%s %s", use_id(source_p
), buf
);
918 RB_DLINK_FOREACH(ptr
, global_serv_list
.head
)
920 target_p
= ptr
->data
;
922 /* dont send to ourselves, or back to where it came from.. */
923 if(IsMe(target_p
) || target_p
->from
== source_p
->from
)
926 if(target_p
->from
->serial
== current_serial
)
929 if(match(mask
, target_p
->name
))
931 /* if we set the serial here, then we'll never do
932 * a match() again if !IsCapable()
934 target_p
->from
->serial
= current_serial
;
936 if(cap
&& !IsCapable(target_p
->from
, cap
))
939 if(nocap
&& !NotCapable(target_p
->from
, nocap
))
942 _send_linebuf(target_p
->from
, &rb_linebuf_id
);
946 rb_linebuf_donebuf(&rb_linebuf_id
);
951 * inputs - monitor nick to send to, format, va_args
952 * outputs - message to local users monitoring the given nick
956 sendto_monitor(struct monitor
*monptr
, const char *pattern
, ...)
960 struct Client
*target_p
;
962 rb_dlink_node
*next_ptr
;
964 rb_linebuf_newbuf(&linebuf
);
966 va_start(args
, pattern
);
967 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
970 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, monptr
->users
.head
)
972 target_p
= ptr
->data
;
974 if(IsIOError(target_p
))
977 _send_linebuf(target_p
, &linebuf
);
980 rb_linebuf_donebuf(&linebuf
);
985 * inputs - target, source, va_args
987 * side effects - client is sent message with correct prefix.
990 sendto_anywhere(struct Client
*target_p
, struct Client
*source_p
,
991 const char *command
, const char *pattern
, ...)
996 rb_linebuf_newbuf(&linebuf
);
998 va_start(args
, pattern
);
1000 if(MyClient(target_p
))
1002 if(IsServer(source_p
))
1003 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
1004 source_p
->name
, command
,
1007 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1009 source_p
->name
, source_p
->username
,
1010 source_p
->host
, command
,
1014 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
1015 get_id(source_p
, target_p
), command
,
1016 get_id(target_p
, target_p
));
1019 if(MyClient(target_p
))
1020 _send_linebuf(target_p
, &linebuf
);
1022 send_linebuf_remote(target_p
, source_p
, &linebuf
);
1024 rb_linebuf_donebuf(&linebuf
);
1027 /* sendto_realops_snomask()
1029 * inputs - snomask needed, level (opers/admin), va_args
1031 * side effects - message is sent to opers with matching snomasks
1034 sendto_realops_snomask(int flags
, int level
, const char *pattern
, ...)
1036 static char buf
[BUFSIZE
];
1038 struct Client
*client_p
;
1040 rb_dlink_node
*next_ptr
;
1044 rb_linebuf_newbuf(&linebuf
);
1046 /* Be very sure not to do things like "Trying to send to myself"
1047 * L_NETWIDE, otherwise infinite recursion may result! -- jilles */
1048 if (level
& L_NETWIDE
&& ConfigFileEntry
.global_snotices
)
1050 /* rather a lot of copying around, oh well -- jilles */
1051 va_start(args
, pattern
);
1052 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1054 rb_linebuf_putmsg(&linebuf
, pattern
, NULL
,
1055 ":%s NOTICE * :*** Notice -- %s", me
.name
, buf
);
1056 snobuf
= construct_snobuf(flags
);
1057 if (snobuf
[1] != '\0')
1058 sendto_server(NULL
, NULL
, CAP_ENCAP
|CAP_TS6
, NOCAPS
,
1059 ":%s ENCAP * SNOTE %c :%s",
1060 me
.id
, snobuf
[1], buf
);
1062 else if (remote_rehash_oper_p
!= NULL
)
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 sendto_one_notice(remote_rehash_oper_p
, ":*** Notice -- %s", buf
);
1074 va_start(args
, pattern
);
1075 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1076 ":%s NOTICE * :*** Notice -- ", me
.name
);
1079 level
&= ~L_NETWIDE
;
1081 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1083 client_p
= ptr
->data
;
1085 /* If we're sending it to opers and theyre an admin, skip.
1086 * If we're sending it to admins, and theyre not, skip.
1088 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1089 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1092 if(client_p
->snomask
& flags
)
1093 _send_linebuf(client_p
, &linebuf
);
1096 rb_linebuf_donebuf(&linebuf
);
1098 /* sendto_realops_snomask_from()
1100 * inputs - snomask needed, level (opers/admin), source server, va_args
1102 * side effects - message is sent to opers with matching snomask
1105 sendto_realops_snomask_from(int flags
, int level
, struct Client
*source_p
,
1106 const char *pattern
, ...)
1108 struct Client
*client_p
;
1110 rb_dlink_node
*next_ptr
;
1114 rb_linebuf_newbuf(&linebuf
);
1116 va_start(args
, pattern
);
1117 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1118 ":%s NOTICE * :*** Notice -- ", source_p
->name
);
1121 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1123 client_p
= ptr
->data
;
1125 /* If we're sending it to opers and theyre an admin, skip.
1126 * If we're sending it to admins, and theyre not, skip.
1128 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1129 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1132 if(client_p
->snomask
& flags
)
1133 _send_linebuf(client_p
, &linebuf
);
1136 rb_linebuf_donebuf(&linebuf
);
1140 * sendto_wallops_flags
1142 * inputs - flag types of messages to show to real opers
1143 * - client sending request
1144 * - var args input message
1146 * side effects - Send a wallops to local opers
1149 sendto_wallops_flags(int flags
, struct Client
*source_p
, const char *pattern
, ...)
1151 struct Client
*client_p
;
1153 rb_dlink_node
*next_ptr
;
1157 rb_linebuf_newbuf(&linebuf
);
1159 va_start(args
, pattern
);
1161 if(IsPerson(source_p
))
1162 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1163 ":%s!%s@%s WALLOPS :", source_p
->name
,
1164 source_p
->username
, source_p
->host
);
1166 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s WALLOPS :", source_p
->name
);
1170 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, IsPerson(source_p
) && flags
== UMODE_WALLOP
? lclient_list
.head
: local_oper_list
.head
)
1172 client_p
= ptr
->data
;
1174 if(client_p
->umodes
& flags
)
1175 _send_linebuf(client_p
, &linebuf
);
1178 rb_linebuf_donebuf(&linebuf
);
1183 * input - client to send kill to, client to kill, va_args
1185 * side effects - we issue a kill for the client
1188 kill_client(struct Client
*target_p
, struct Client
*diedie
, const char *pattern
, ...)
1193 rb_linebuf_newbuf(&linebuf
);
1195 va_start(args
, pattern
);
1196 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s KILL %s :",
1197 get_id(&me
, target_p
), get_id(diedie
, target_p
));
1200 send_linebuf(target_p
, &linebuf
);
1201 rb_linebuf_donebuf(&linebuf
);
1206 * kill_client_serv_butone
1208 * inputs - pointer to client to not send to
1209 * - pointer to client to kill
1211 * side effects - Send a KILL for the given client
1212 * message to all connected servers
1213 * except the client 'one'. Also deal with
1214 * client being unknown to leaf, as in lazylink...
1217 kill_client_serv_butone(struct Client
*one
, struct Client
*target_p
, const char *pattern
, ...)
1219 static char buf
[BUFSIZE
];
1221 struct Client
*client_p
;
1223 rb_dlink_node
*next_ptr
;
1224 buf_head_t rb_linebuf_id
;
1226 rb_linebuf_newbuf(&rb_linebuf_id
);
1228 va_start(args
, pattern
);
1229 rb_vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1232 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s KILL %s :%s",
1233 use_id(&me
), use_id(target_p
), buf
);
1235 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
1237 client_p
= ptr
->data
;
1239 /* ok, if the client we're supposed to not send to has an
1240 * ID, then we still want to issue the kill there..
1242 if(one
!= NULL
&& (client_p
== one
->from
) &&
1243 (!has_id(client_p
) || !has_id(target_p
)))
1246 _send_linebuf(client_p
, &rb_linebuf_id
);
1249 rb_linebuf_donebuf(&rb_linebuf_id
);