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
36 #include "s_newconf.h"
42 /* send the message to the link the target is attached to */
43 #define send_linebuf(a,b) _send_linebuf((a->from ? a->from : a) ,b)
45 static void send_queued_write(rb_fde_t
*F
, void *data
);
47 unsigned long current_serial
= 0L;
49 struct Client
*remote_rehash_oper_p
;
53 * inputs - client to send to, linebuf to attach
55 * side effects - linebuf is attached to client
58 _send_linebuf(struct Client
*to
, buf_head_t
*linebuf
)
62 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send message to myself!");
66 if(!MyConnect(to
) || IsIOError(to
))
69 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > get_sendq(to
))
73 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
74 "Max SendQ limit exceeded for %s: %u > %lu",
76 rb_linebuf_len(&to
->localClient
->buf_sendq
),
79 ilog(L_SERVER
, "Max SendQ limit exceeded for %s: %u > %lu",
80 log_client_name(to
, SHOW_IP
),
81 rb_linebuf_len(&to
->localClient
->buf_sendq
),
90 /* just attach the linebuf to the sendq instead of
91 * generating a new one
93 rb_linebuf_attach(&to
->localClient
->buf_sendq
, linebuf
);
97 ** Update statistics. The following is slightly incorrect
98 ** because it counts messages even if queued, but bytes
99 ** only really sent. Queued bytes get updated in SendQueued.
101 to
->localClient
->sendM
+= 1;
102 me
.localClient
->sendM
+= 1;
103 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > 0)
108 /* send_linebuf_remote()
110 * inputs - client to attach to, sender, linebuf
112 * side effects - client has linebuf attached
115 send_linebuf_remote(struct Client
*to
, struct Client
*from
, buf_head_t
*linebuf
)
120 /* we assume the caller has already tested for fake direction */
121 _send_linebuf(to
, linebuf
);
124 /* send_queued_write()
126 * inputs - fd to have queue sent, client we're sending to
127 * outputs - contents of queue
128 * side effects - write is rescheduled if queue isnt emptied
131 send_queued(struct Client
*to
)
135 rb_fde_t
*F
= to
->localClient
->F
;
139 /* cant write anything to a dead socket. */
143 /* try to flush later when the write event resets this */
147 if(rb_linebuf_len(&to
->localClient
->buf_sendq
))
150 rb_linebuf_flush(F
, &to
->localClient
->buf_sendq
)) > 0)
152 /* We have some data written .. update counters */
155 to
->localClient
->sendB
+= retlen
;
156 me
.localClient
->sendB
+= retlen
;
157 if(to
->localClient
->sendB
> 1023)
159 to
->localClient
->sendK
+= (to
->localClient
->sendB
>> 10);
160 to
->localClient
->sendB
&= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */
162 else if(me
.localClient
->sendB
> 1023)
164 me
.localClient
->sendK
+= (me
.localClient
->sendB
>> 10);
165 me
.localClient
->sendB
&= 0x03ff;
169 if(retlen
== 0 || (retlen
< 0 && !rb_ignore_errno(errno
)))
176 if(rb_linebuf_len(&to
->localClient
->buf_sendq
))
179 rb_setselect(to
->localClient
->F
, RB_SELECT_WRITE
,
180 send_queued_write
, to
);
187 send_pop_queue(struct Client
*to
)
191 if(!MyConnect(to
) || IsIOError(to
))
193 if(rb_linebuf_len(&to
->localClient
->buf_sendq
) > 0)
197 /* send_queued_write()
199 * inputs - fd to have queue sent, client we're sending to
200 * outputs - contents of queue
201 * side effects - write is scheduled if queue isnt emptied
204 send_queued_write(rb_fde_t
*F
, void *data
)
206 struct Client
*to
= data
;
212 * linebuf_put_msgvbuf
214 * inputs - msgbuf header, linebuf object, capability mask, pattern, arguments
216 * side effects - the linebuf object is cleared, then populated using rb_linebuf_putmsg().
219 linebuf_put_msgvbuf(struct MsgBuf
*msgbuf
, buf_head_t
*linebuf
, unsigned int capmask
, const char *pattern
, va_list *va
)
223 rb_linebuf_newbuf(linebuf
);
224 msgbuf_unparse_prefix(buf
, sizeof buf
, msgbuf
, capmask
);
225 rb_linebuf_putprefix(linebuf
, pattern
, va
, buf
);
228 /* linebuf_put_msgbuf
230 * inputs - msgbuf header, linebuf object, capability mask, pattern, arguments
232 * side effects - the linebuf object is cleared, then populated using rb_linebuf_putmsg().
235 linebuf_put_msgbuf(struct MsgBuf
*msgbuf
, buf_head_t
*linebuf
, unsigned int capmask
, const char *pattern
, ...)
239 va_start(va
, pattern
);
240 linebuf_put_msgvbuf(msgbuf
, linebuf
, capmask
, pattern
, &va
);
246 * inputs - msgbuf object, client the message is from
248 * side effects - a msgbuf object is populated with an origin and relevant tags
249 * notes - to make this reentrant, find a solution for `buf` below
252 build_msgbuf_from(struct MsgBuf
*msgbuf
, struct Client
*from
, const char *cmd
)
254 static char buf
[BUFSIZE
];
259 msgbuf
->origin
= buf
;
262 if (from
!= NULL
&& IsPerson(from
))
263 snprintf(buf
, sizeof buf
, "%s!%s@%s", from
->name
, from
->username
, from
->host
);
264 else if (from
!= NULL
)
265 rb_strlcpy(buf
, from
->name
, sizeof buf
);
267 rb_strlcpy(buf
, me
.name
, sizeof buf
);
272 call_hook(h_outbound_msgbuf
, &hdata
);
277 * inputs - client to send to, va_args
278 * outputs - client has message put into its queue
282 sendto_one(struct Client
*target_p
, const char *pattern
, ...)
287 /* send remote if to->from non NULL */
288 if(target_p
->from
!= NULL
)
289 target_p
= target_p
->from
;
291 if(IsIOError(target_p
))
294 rb_linebuf_newbuf(&linebuf
);
296 va_start(args
, pattern
);
297 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
300 _send_linebuf(target_p
, &linebuf
);
302 rb_linebuf_donebuf(&linebuf
);
305 /* sendto_one_prefix()
307 * inputs - client to send to, va_args
308 * outputs - client has message put into its queue
309 * side effects - source(us)/target is chosen based on TS6 capability
312 sendto_one_prefix(struct Client
*target_p
, struct Client
*source_p
,
313 const char *command
, const char *pattern
, ...)
315 struct Client
*dest_p
= target_p
->from
;
319 if(IsIOError(dest_p
))
324 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
328 rb_linebuf_newbuf(&linebuf
);
329 va_start(args
, pattern
);
330 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
332 get_id(source_p
, target_p
),
333 command
, get_id(target_p
, target_p
));
336 _send_linebuf(dest_p
, &linebuf
);
337 rb_linebuf_donebuf(&linebuf
);
340 /* sendto_one_notice()
342 * inputs - client to send to, va_args
343 * outputs - client has a NOTICE put into its queue
344 * side effects - source(us)/target is chosen based on TS6 capability
347 sendto_one_notice(struct Client
*target_p
, const char *pattern
, ...)
349 struct Client
*dest_p
;
354 /* send remote if to->from non NULL */
355 if(target_p
->from
!= NULL
)
356 dest_p
= target_p
->from
;
360 if(IsIOError(dest_p
))
365 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
369 rb_linebuf_newbuf(&linebuf
);
370 va_start(args
, pattern
);
371 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
373 get_id(&me
, target_p
), *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
376 _send_linebuf(dest_p
, &linebuf
);
377 rb_linebuf_donebuf(&linebuf
);
381 /* sendto_one_numeric()
383 * inputs - client to send to, va_args
384 * outputs - client has message put into its queue
385 * side effects - source/target is chosen based on TS6 capability
388 sendto_one_numeric(struct Client
*target_p
, int numeric
, const char *pattern
, ...)
390 struct Client
*dest_p
= target_p
->from
;
395 if(IsIOError(dest_p
))
400 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
404 rb_linebuf_newbuf(&linebuf
);
405 va_start(args
, pattern
);
406 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
408 get_id(&me
, target_p
),
409 numeric
, *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
412 _send_linebuf(dest_p
, &linebuf
);
413 rb_linebuf_donebuf(&linebuf
);
419 * inputs - pointer to client to NOT send to
420 * - caps or'd together which must ALL be present
421 * - caps or'd together which must ALL NOT be present
422 * - printf style format string
423 * - args to format string
425 * side effects - Send a message to all connected servers, except the
426 * client 'one' (if non-NULL), as long as the servers
427 * support ALL capabs in 'caps', and NO capabs in 'nocaps'.
429 * This function was written in an attempt to merge together the other
430 * billion sendto_*serv*() functions, which sprung up with capabs, uids etc
434 sendto_server(struct Client
*one
, struct Channel
*chptr
, unsigned long caps
,
435 unsigned long nocaps
, const char *format
, ...)
438 struct Client
*target_p
;
440 rb_dlink_node
*next_ptr
;
443 /* noone to send to.. */
444 if(rb_dlink_list_length(&serv_list
) == 0)
447 if(chptr
!= NULL
&& *chptr
->chname
!= '#')
450 rb_linebuf_newbuf(&linebuf
);
451 va_start(args
, format
);
452 rb_linebuf_putmsg(&linebuf
, format
, &args
, NULL
);
455 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
457 target_p
= ptr
->data
;
459 /* check against 'one' */
460 if(one
!= NULL
&& (target_p
== one
->from
))
463 /* check we have required capabs */
464 if(!IsCapable(target_p
, caps
))
467 /* check we don't have any forbidden capabs */
468 if(!NotCapable(target_p
, nocaps
))
471 _send_linebuf(target_p
, &linebuf
);
474 rb_linebuf_donebuf(&linebuf
);
477 /* sendto_channel_flags()
479 * inputs - server not to send to, flags needed, source, channel, va_args
480 * outputs - message is sent to channel members
484 sendto_channel_flags(struct Client
*one
, int type
, struct Client
*source_p
,
485 struct Channel
*chptr
, const char *pattern
, ...)
489 buf_head_t rb_linebuf_local
;
490 buf_head_t rb_linebuf_id
;
491 struct Client
*target_p
;
492 struct membership
*msptr
;
494 rb_dlink_node
*next_ptr
;
495 int current_capmask
= 0;
496 struct MsgBuf msgbuf
;
498 rb_linebuf_newbuf(&rb_linebuf_local
);
499 rb_linebuf_newbuf(&rb_linebuf_id
);
503 build_msgbuf_from(&msgbuf
, source_p
, NULL
);
505 va_start(args
, pattern
);
506 vsnprintf(buf
, sizeof buf
, pattern
, args
);
509 linebuf_put_msgbuf(&msgbuf
, &rb_linebuf_local
, NOCAPS
, "%s", buf
);
510 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
512 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->members
.head
)
515 target_p
= msptr
->client_p
;
517 if(!MyClient(source_p
) && (IsIOError(target_p
->from
) || target_p
->from
== one
))
520 if(MyClient(source_p
) && target_p
== one
)
523 if(type
&& ((msptr
->flags
& type
) == 0))
529 if(!MyClient(target_p
))
531 /* if we've got a specific type, target must support
534 if(type
&& NotCapable(target_p
->from
, CAP_CHW
))
537 if(target_p
->from
->serial
!= current_serial
)
539 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_id
);
540 target_p
->from
->serial
= current_serial
;
545 if (target_p
->localClient
->caps
!= current_capmask
)
547 /* reset the linebuf */
548 rb_linebuf_donebuf(&rb_linebuf_local
);
549 rb_linebuf_newbuf(&rb_linebuf_local
);
551 /* render the new linebuf and attach it */
552 linebuf_put_msgbuf(&msgbuf
, &rb_linebuf_local
, target_p
->localClient
->caps
, "%s", buf
);
553 current_capmask
= target_p
->localClient
->caps
;
556 _send_linebuf(target_p
, &rb_linebuf_local
);
560 /* source client may not be on the channel, send echo separately */
561 if(MyClient(source_p
) && IsCapable(source_p
, CLICAP_ECHO_MESSAGE
))
565 if (target_p
->localClient
->caps
!= current_capmask
)
567 /* reset the linebuf */
568 rb_linebuf_donebuf(&rb_linebuf_local
);
569 rb_linebuf_newbuf(&rb_linebuf_local
);
571 /* render the new linebuf and attach it */
572 linebuf_put_msgbuf(&msgbuf
, &rb_linebuf_local
, target_p
->localClient
->caps
, "%s", buf
);
573 current_capmask
= target_p
->localClient
->caps
;
576 _send_linebuf(target_p
, &rb_linebuf_local
);
579 rb_linebuf_donebuf(&rb_linebuf_local
);
580 rb_linebuf_donebuf(&rb_linebuf_id
);
583 /* sendto_channel_flags()
585 * inputs - server not to send to, flags needed, source, channel, va_args
586 * outputs - message is sent to channel members
590 sendto_channel_opmod(struct Client
*one
, struct Client
*source_p
,
591 struct Channel
*chptr
, const char *command
,
594 buf_head_t rb_linebuf_local
;
595 buf_head_t rb_linebuf_old
;
596 buf_head_t rb_linebuf_new
;
597 struct Client
*target_p
;
598 struct membership
*msptr
;
600 rb_dlink_node
*next_ptr
;
602 rb_linebuf_newbuf(&rb_linebuf_local
);
603 rb_linebuf_newbuf(&rb_linebuf_old
);
604 rb_linebuf_newbuf(&rb_linebuf_new
);
608 if(IsServer(source_p
))
609 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
611 source_p
->name
, command
, chptr
->chname
, text
);
613 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
614 ":%s!%s@%s %s %s :%s",
615 source_p
->name
, source_p
->username
,
616 source_p
->host
, command
, chptr
->chname
, text
);
618 if (chptr
->mode
.mode
& MODE_MODERATED
)
619 rb_linebuf_putmsg(&rb_linebuf_old
, NULL
, NULL
,
621 use_id(source_p
), command
, chptr
->chname
, text
);
623 rb_linebuf_putmsg(&rb_linebuf_old
, NULL
, NULL
,
624 ":%s NOTICE @%s :<%s:%s> %s",
625 use_id(source_p
->servptr
), chptr
->chname
,
626 source_p
->name
, chptr
->chname
, text
);
627 rb_linebuf_putmsg(&rb_linebuf_new
, NULL
, NULL
,
629 use_id(source_p
), command
, chptr
->chname
, text
);
631 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->members
.head
)
634 target_p
= msptr
->client_p
;
636 if(!MyClient(source_p
) && (IsIOError(target_p
->from
) || target_p
->from
== one
))
639 if(MyClient(source_p
) && target_p
== one
)
642 if((msptr
->flags
& CHFL_CHANOP
) == 0)
648 if(!MyClient(target_p
))
650 /* if we've got a specific type, target must support
653 if(NotCapable(target_p
->from
, CAP_CHW
))
656 if(target_p
->from
->serial
!= current_serial
)
658 if (IsCapable(target_p
->from
, CAP_EOPMOD
))
659 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_new
);
661 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_old
);
662 target_p
->from
->serial
= current_serial
;
666 _send_linebuf(target_p
, &rb_linebuf_local
);
669 /* source client may not be on the channel, send echo separately */
670 if(MyClient(source_p
) && IsCapable(source_p
, CLICAP_ECHO_MESSAGE
))
674 _send_linebuf(target_p
, &rb_linebuf_local
);
677 rb_linebuf_donebuf(&rb_linebuf_local
);
678 rb_linebuf_donebuf(&rb_linebuf_old
);
679 rb_linebuf_donebuf(&rb_linebuf_new
);
682 /* sendto_channel_local()
684 * inputs - flags to send to, channel to send to, va_args
685 * outputs - message to local channel members
689 sendto_channel_local(int type
, struct Channel
*chptr
, const char *pattern
, ...)
693 struct membership
*msptr
;
694 struct Client
*target_p
;
696 rb_dlink_node
*next_ptr
;
698 rb_linebuf_newbuf(&linebuf
);
700 va_start(args
, pattern
);
701 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
704 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
707 target_p
= msptr
->client_p
;
709 if(IsIOError(target_p
))
712 if(type
== ONLY_OPERS
)
714 if (!IsOper(target_p
))
717 else if(type
&& ((msptr
->flags
& type
) == 0))
720 _send_linebuf(target_p
, &linebuf
);
723 rb_linebuf_donebuf(&linebuf
);
727 * _sendto_channel_local_with_capability_butone()
729 * Shared implementation of sendto_channel_local_with_capability and sendto_channel_local_with_capability_butone
732 _sendto_channel_local_with_capability_butone(struct Client
*one
, int type
, int caps
, int negcaps
, struct Channel
*chptr
,
733 const char *pattern
, va_list * args
)
736 struct membership
*msptr
;
737 struct Client
*target_p
;
739 rb_dlink_node
*next_ptr
;
741 rb_linebuf_newbuf(&linebuf
);
742 rb_linebuf_putmsg(&linebuf
, pattern
, args
, NULL
);
744 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
747 target_p
= msptr
->client_p
;
752 if(IsIOError(target_p
) ||
753 !IsCapable(target_p
, caps
) ||
754 !NotCapable(target_p
, negcaps
))
757 if(type
&& ((msptr
->flags
& type
) == 0))
760 _send_linebuf(target_p
, &linebuf
);
763 rb_linebuf_donebuf(&linebuf
);
766 /* sendto_channel_local_with_capability()
768 * inputs - flags to send to, caps, negate caps, channel to send to, va_args
769 * outputs - message to local channel members
773 sendto_channel_local_with_capability(int type
, int caps
, int negcaps
, struct Channel
*chptr
, const char *pattern
, ...)
777 va_start(args
, pattern
);
778 _sendto_channel_local_with_capability_butone(NULL
, type
, caps
, negcaps
, chptr
, pattern
, &args
);
783 /* sendto_channel_local_with_capability()
785 * inputs - flags to send to, caps, negate caps, channel to send to, va_args
786 * outputs - message to local channel members
790 sendto_channel_local_with_capability_butone(struct Client
*one
, int type
, int caps
, int negcaps
, struct Channel
*chptr
,
791 const char *pattern
, ...)
795 va_start(args
, pattern
);
796 _sendto_channel_local_with_capability_butone(one
, type
, caps
, negcaps
, chptr
, pattern
, &args
);
801 /* sendto_channel_local_butone()
803 * inputs - flags to send to, channel to send to, va_args
804 * - user to ignore when sending
805 * outputs - message to local channel members
809 sendto_channel_local_butone(struct Client
*one
, int type
, struct Channel
*chptr
, const char *pattern
, ...)
813 struct membership
*msptr
;
814 struct Client
*target_p
;
815 struct MsgBuf msgbuf
;
817 rb_dlink_node
*next_ptr
;
819 rb_linebuf_newbuf(&linebuf
);
821 build_msgbuf_from(&msgbuf
, one
, NULL
);
823 va_start(args
, pattern
);
824 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
827 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
830 target_p
= msptr
->client_p
;
835 if(IsIOError(target_p
))
838 if(type
&& ((msptr
->flags
& type
) == 0))
841 /* attach the present linebuf to the target */
842 _send_linebuf(target_p
, &linebuf
);
845 rb_linebuf_donebuf(&linebuf
);
849 * sendto_common_channels_local()
851 * inputs - pointer to client
853 * - negated capability mask
856 * side effects - Sends a message to all people on local server who are
857 * in same channel with user.
858 * used by m_nick.c and exit_one_client.
861 sendto_common_channels_local(struct Client
*user
, int cap
, int negcap
, const char *pattern
, ...)
865 rb_dlink_node
*next_ptr
;
867 rb_dlink_node
*next_uptr
;
868 struct Channel
*chptr
;
869 struct Client
*target_p
;
870 struct membership
*msptr
;
871 struct membership
*mscptr
;
874 rb_linebuf_newbuf(&linebuf
);
875 va_start(args
, pattern
);
876 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
881 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
884 chptr
= mscptr
->chptr
;
886 RB_DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
889 target_p
= msptr
->client_p
;
891 if(IsIOError(target_p
) ||
892 target_p
->serial
== current_serial
||
893 !IsCapable(target_p
, cap
) ||
894 !NotCapable(target_p
, negcap
))
897 target_p
->serial
= current_serial
;
898 send_linebuf(target_p
, &linebuf
);
902 /* this can happen when the user isnt in any channels, but we still
903 * need to send them the data, ie a nick change
905 if(MyConnect(user
) && (user
->serial
!= current_serial
))
906 send_linebuf(user
, &linebuf
);
908 rb_linebuf_donebuf(&linebuf
);
912 * sendto_common_channels_local_butone()
914 * inputs - pointer to client
916 * - negated capability mask
919 * side effects - Sends a message to all people on local server who are
920 * in same channel with user, except for user itself.
923 sendto_common_channels_local_butone(struct Client
*user
, int cap
, int negcap
, const char *pattern
, ...)
927 rb_dlink_node
*next_ptr
;
929 rb_dlink_node
*next_uptr
;
930 struct Channel
*chptr
;
931 struct Client
*target_p
;
932 struct membership
*msptr
;
933 struct membership
*mscptr
;
936 rb_linebuf_newbuf(&linebuf
);
938 va_start(args
, pattern
);
939 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
943 /* Skip them -- jilles */
944 user
->serial
= current_serial
;
946 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
949 chptr
= mscptr
->chptr
;
951 RB_DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
954 target_p
= msptr
->client_p
;
956 if(IsIOError(target_p
) ||
957 target_p
->serial
== current_serial
||
958 !IsCapable(target_p
, cap
) ||
959 !NotCapable(target_p
, negcap
))
962 target_p
->serial
= current_serial
;
963 send_linebuf(target_p
, &linebuf
);
967 rb_linebuf_donebuf(&linebuf
);
970 /* sendto_match_butone()
972 * inputs - server not to send to, source, mask, type of mask, va_args
974 * side effects - message is sent to matching clients
977 sendto_match_butone(struct Client
*one
, struct Client
*source_p
,
978 const char *mask
, int what
, const char *pattern
, ...)
980 static char buf
[BUFSIZE
];
982 struct Client
*target_p
;
984 rb_dlink_node
*next_ptr
;
985 buf_head_t rb_linebuf_local
;
986 buf_head_t rb_linebuf_id
;
988 rb_linebuf_newbuf(&rb_linebuf_local
);
989 rb_linebuf_newbuf(&rb_linebuf_id
);
991 va_start(args
, pattern
);
992 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
995 if(IsServer(source_p
))
996 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
997 ":%s %s", source_p
->name
, buf
);
999 rb_linebuf_putmsg(&rb_linebuf_local
, NULL
, NULL
,
1001 source_p
->name
, source_p
->username
,
1002 source_p
->host
, buf
);
1004 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
1006 if(what
== MATCH_HOST
)
1008 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
1010 target_p
= ptr
->data
;
1012 if(match(mask
, target_p
->host
))
1013 _send_linebuf(target_p
, &rb_linebuf_local
);
1016 /* what = MATCH_SERVER, if it doesnt match us, just send remote */
1017 else if(match(mask
, me
.name
))
1019 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
1021 target_p
= ptr
->data
;
1022 _send_linebuf(target_p
, &rb_linebuf_local
);
1026 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
1028 target_p
= ptr
->data
;
1033 send_linebuf_remote(target_p
, source_p
, &rb_linebuf_id
);
1036 rb_linebuf_donebuf(&rb_linebuf_local
);
1037 rb_linebuf_donebuf(&rb_linebuf_id
);
1040 /* sendto_match_servs()
1042 * inputs - source, mask to send to, caps needed, va_args
1044 * side effects - message is sent to matching servers with caps.
1047 sendto_match_servs(struct Client
*source_p
, const char *mask
, int cap
,
1048 int nocap
, const char *pattern
, ...)
1050 static char buf
[BUFSIZE
];
1053 struct Client
*target_p
;
1054 buf_head_t rb_linebuf_id
;
1056 if(EmptyString(mask
))
1059 rb_linebuf_newbuf(&rb_linebuf_id
);
1061 va_start(args
, pattern
);
1062 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1065 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
,
1066 ":%s %s", use_id(source_p
), buf
);
1070 RB_DLINK_FOREACH(ptr
, global_serv_list
.head
)
1072 target_p
= ptr
->data
;
1074 /* dont send to ourselves, or back to where it came from.. */
1075 if(IsMe(target_p
) || target_p
->from
== source_p
->from
)
1078 if(target_p
->from
->serial
== current_serial
)
1081 if(match(mask
, target_p
->name
))
1083 /* if we set the serial here, then we'll never do
1084 * a match() again if !IsCapable()
1086 target_p
->from
->serial
= current_serial
;
1088 if(cap
&& !IsCapable(target_p
->from
, cap
))
1091 if(nocap
&& !NotCapable(target_p
->from
, nocap
))
1094 _send_linebuf(target_p
->from
, &rb_linebuf_id
);
1098 rb_linebuf_donebuf(&rb_linebuf_id
);
1101 /* sendto_local_clients_with_capability()
1103 * inputs - caps needed, pattern, va_args
1105 * side effects - message is sent to matching local clients with caps.
1108 sendto_local_clients_with_capability(int cap
, const char *pattern
, ...)
1112 struct Client
*target_p
;
1115 rb_linebuf_newbuf(&linebuf
);
1117 va_start(args
, pattern
);
1118 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
1121 RB_DLINK_FOREACH(ptr
, lclient_list
.head
)
1123 target_p
= ptr
->data
;
1125 if(IsIOError(target_p
) || !IsCapable(target_p
, cap
))
1128 send_linebuf(target_p
, &linebuf
);
1131 rb_linebuf_donebuf(&linebuf
);
1136 * inputs - monitor nick to send to, format, va_args
1137 * outputs - message to local users monitoring the given nick
1141 sendto_monitor(struct monitor
*monptr
, const char *pattern
, ...)
1145 struct Client
*target_p
;
1147 rb_dlink_node
*next_ptr
;
1149 rb_linebuf_newbuf(&linebuf
);
1151 va_start(args
, pattern
);
1152 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
1155 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, monptr
->users
.head
)
1157 target_p
= ptr
->data
;
1159 if(IsIOError(target_p
))
1162 _send_linebuf(target_p
, &linebuf
);
1165 rb_linebuf_donebuf(&linebuf
);
1168 /* _sendto_anywhere()
1170 * inputs - real_target, target, source, va_args
1172 * side effects - client is sent message/own message with correct prefix.
1175 _sendto_anywhere(struct Client
*dest_p
, struct Client
*target_p
,
1176 struct Client
*source_p
, const char *command
,
1177 const char *pattern
, va_list *args
)
1181 rb_linebuf_newbuf(&linebuf
);
1183 if(MyClient(dest_p
))
1185 if(IsServer(source_p
))
1186 rb_linebuf_putmsg(&linebuf
, pattern
, args
, ":%s %s %s ",
1187 source_p
->name
, command
,
1191 struct MsgBuf msgbuf
;
1193 build_msgbuf_from(&msgbuf
, source_p
, command
);
1194 msgbuf
.target
= target_p
->name
;
1196 linebuf_put_msgvbuf(&msgbuf
, &linebuf
, dest_p
->localClient
->caps
, pattern
, args
);
1200 rb_linebuf_putmsg(&linebuf
, pattern
, args
, ":%s %s %s ",
1201 get_id(source_p
, target_p
), command
,
1202 get_id(target_p
, target_p
));
1204 if(MyClient(dest_p
))
1205 _send_linebuf(dest_p
, &linebuf
);
1207 send_linebuf_remote(dest_p
, source_p
, &linebuf
);
1209 rb_linebuf_donebuf(&linebuf
);
1212 /* sendto_anywhere()
1214 * inputs - target, source, va_args
1216 * side effects - client is sent message with correct prefix.
1219 sendto_anywhere(struct Client
*target_p
, struct Client
*source_p
,
1220 const char *command
, const char *pattern
, ...)
1224 va_start(args
, pattern
);
1225 _sendto_anywhere(target_p
, target_p
, source_p
, command
, pattern
, &args
);
1229 /* sendto_anywhere_echo()
1231 * inputs - target, source, va_args
1233 * side effects - client is sent own message with correct prefix.
1236 sendto_anywhere_echo(struct Client
*target_p
, struct Client
*source_p
,
1237 const char *command
, const char *pattern
, ...)
1241 s_assert(MyClient(source_p
));
1242 s_assert(!IsServer(source_p
));
1244 va_start(args
, pattern
);
1245 _sendto_anywhere(source_p
, target_p
, source_p
, command
, pattern
, &args
);
1249 /* sendto_realops_snomask()
1251 * inputs - snomask needed, level (opers/admin), va_args
1253 * side effects - message is sent to opers with matching snomasks
1256 sendto_realops_snomask(int flags
, int level
, const char *pattern
, ...)
1258 static char buf
[BUFSIZE
];
1260 struct Client
*client_p
;
1262 rb_dlink_node
*next_ptr
;
1266 rb_linebuf_newbuf(&linebuf
);
1268 /* Be very sure not to do things like "Trying to send to myself"
1269 * L_NETWIDE, otherwise infinite recursion may result! -- jilles */
1270 if (level
& L_NETWIDE
&& ConfigFileEntry
.global_snotices
)
1272 /* rather a lot of copying around, oh well -- jilles */
1273 va_start(args
, pattern
);
1274 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1276 rb_linebuf_putmsg(&linebuf
, pattern
, NULL
,
1277 ":%s NOTICE * :*** Notice -- %s", me
.name
, buf
);
1278 snobuf
= construct_snobuf(flags
);
1279 if (snobuf
[1] != '\0')
1280 sendto_server(NULL
, NULL
, CAP_ENCAP
|CAP_TS6
, NOCAPS
,
1281 ":%s ENCAP * SNOTE %c :%s",
1282 me
.id
, snobuf
[1], buf
);
1284 else if (remote_rehash_oper_p
!= NULL
)
1286 /* rather a lot of copying around, oh well -- jilles */
1287 va_start(args
, pattern
);
1288 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1290 rb_linebuf_putmsg(&linebuf
, pattern
, NULL
,
1291 ":%s NOTICE * :*** Notice -- %s", me
.name
, buf
);
1292 sendto_one_notice(remote_rehash_oper_p
, ":*** Notice -- %s", buf
);
1296 va_start(args
, pattern
);
1297 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1298 ":%s NOTICE * :*** Notice -- ", me
.name
);
1301 level
&= ~L_NETWIDE
;
1303 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1305 client_p
= ptr
->data
;
1307 /* If we're sending it to opers and theyre an admin, skip.
1308 * If we're sending it to admins, and theyre not, skip.
1310 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1311 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1314 if(client_p
->snomask
& flags
)
1315 _send_linebuf(client_p
, &linebuf
);
1318 rb_linebuf_donebuf(&linebuf
);
1320 /* sendto_realops_snomask_from()
1322 * inputs - snomask needed, level (opers/admin), source server, va_args
1324 * side effects - message is sent to opers with matching snomask
1327 sendto_realops_snomask_from(int flags
, int level
, struct Client
*source_p
,
1328 const char *pattern
, ...)
1330 struct Client
*client_p
;
1332 rb_dlink_node
*next_ptr
;
1336 rb_linebuf_newbuf(&linebuf
);
1338 va_start(args
, pattern
);
1339 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1340 ":%s NOTICE * :*** Notice -- ", source_p
->name
);
1343 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1345 client_p
= ptr
->data
;
1347 /* If we're sending it to opers and theyre an admin, skip.
1348 * If we're sending it to admins, and theyre not, skip.
1350 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1351 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1354 if(client_p
->snomask
& flags
)
1355 _send_linebuf(client_p
, &linebuf
);
1358 rb_linebuf_donebuf(&linebuf
);
1362 * sendto_wallops_flags
1364 * inputs - flag types of messages to show to real opers
1365 * - client sending request
1366 * - var args input message
1368 * side effects - Send a wallops to local opers
1371 sendto_wallops_flags(int flags
, struct Client
*source_p
, const char *pattern
, ...)
1373 struct Client
*client_p
;
1375 rb_dlink_node
*next_ptr
;
1379 rb_linebuf_newbuf(&linebuf
);
1381 va_start(args
, pattern
);
1383 if(IsPerson(source_p
))
1384 rb_linebuf_putmsg(&linebuf
, pattern
, &args
,
1385 ":%s!%s@%s WALLOPS :", source_p
->name
,
1386 source_p
->username
, source_p
->host
);
1388 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s WALLOPS :", source_p
->name
);
1392 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, IsPerson(source_p
) && flags
== UMODE_WALLOP
? lclient_list
.head
: local_oper_list
.head
)
1394 client_p
= ptr
->data
;
1396 if(client_p
->umodes
& flags
)
1397 _send_linebuf(client_p
, &linebuf
);
1400 rb_linebuf_donebuf(&linebuf
);
1405 * input - client to send kill to, client to kill, va_args
1407 * side effects - we issue a kill for the client
1410 kill_client(struct Client
*target_p
, struct Client
*diedie
, const char *pattern
, ...)
1415 rb_linebuf_newbuf(&linebuf
);
1417 va_start(args
, pattern
);
1418 rb_linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s KILL %s :",
1419 get_id(&me
, target_p
), get_id(diedie
, target_p
));
1422 send_linebuf(target_p
, &linebuf
);
1423 rb_linebuf_donebuf(&linebuf
);
1428 * kill_client_serv_butone
1430 * inputs - pointer to client to not send to
1431 * - pointer to client to kill
1433 * side effects - Send a KILL for the given client
1434 * message to all connected servers
1435 * except the client 'one'. Also deal with
1436 * client being unknown to leaf, as in lazylink...
1439 kill_client_serv_butone(struct Client
*one
, struct Client
*target_p
, const char *pattern
, ...)
1441 static char buf
[BUFSIZE
];
1443 struct Client
*client_p
;
1445 rb_dlink_node
*next_ptr
;
1446 buf_head_t rb_linebuf_id
;
1448 rb_linebuf_newbuf(&rb_linebuf_id
);
1450 va_start(args
, pattern
);
1451 vsnprintf(buf
, sizeof(buf
), pattern
, args
);
1454 rb_linebuf_putmsg(&rb_linebuf_id
, NULL
, NULL
, ":%s KILL %s :%s",
1455 use_id(&me
), use_id(target_p
), buf
);
1457 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
1459 client_p
= ptr
->data
;
1461 /* ok, if the client we're supposed to not send to has an
1462 * ID, then we still want to issue the kill there..
1464 if(one
!= NULL
&& (client_p
== one
->from
) &&
1465 (!has_id(client_p
) || !has_id(target_p
)))
1468 _send_linebuf(client_p
, &rb_linebuf_id
);
1471 rb_linebuf_donebuf(&rb_linebuf_id
);