]>
jfr.im git - irc/rqf/shadowircd.git/blob - src/send.c
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 unsigned long current_serial
= 0L;
57 * inputs - client to send to, linebuf to attach
59 * side effects - linebuf is attached to client
62 _send_linebuf(struct Client
*to
, buf_head_t
*linebuf
)
66 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send message to myself!");
70 if(!MyConnect(to
) || IsIOError(to
))
73 if(linebuf_len(&to
->localClient
->buf_sendq
) > get_sendq(to
))
77 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
78 "Max SendQ limit exceeded for %s: %u > %lu",
79 get_server_name(to
, HIDE_IP
),
80 linebuf_len(&to
->localClient
->buf_sendq
),
83 ilog(L_SERVER
, "Max SendQ limit exceeded for %s: %u > %lu",
84 log_client_name(to
, SHOW_IP
),
85 linebuf_len(&to
->localClient
->buf_sendq
),
90 to
->flags
|= FLAGS_SENDQEX
;
97 /* just attach the linebuf to the sendq instead of
98 * generating a new one
100 linebuf_attach(&to
->localClient
->buf_sendq
, linebuf
);
104 ** Update statistics. The following is slightly incorrect
105 ** because it counts messages even if queued, but bytes
106 ** only really sent. Queued bytes get updated in SendQueued.
108 to
->localClient
->sendM
+= 1;
109 me
.localClient
->sendM
+= 1;
110 if(linebuf_len(&to
->localClient
->buf_sendq
) > 0)
111 send_queued_write(to
->localClient
->fd
, to
);
115 /* send_linebuf_remote()
117 * inputs - client to attach to, sender, linebuf
119 * side effects - client has linebuf attached
122 send_linebuf_remote(struct Client
*to
, struct Client
*from
, buf_head_t
*linebuf
)
127 /* test for fake direction */
128 if(!MyClient(from
) && IsPerson(to
) && (to
== from
->from
))
132 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
133 "Send message to %s[%s] dropped from %s(Fake Dir)",
134 to
->name
, to
->from
->name
, from
->name
);
138 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
139 "Ghosted: %s[%s@%s] from %s[%s@%s] (%s)",
140 to
->name
, to
->username
, to
->host
,
141 from
->name
, from
->username
, from
->host
, to
->from
->name
);
142 kill_client_serv_butone(NULL
, to
, "%s (%s[%s@%s] Ghosted %s)",
143 me
.name
, to
->name
, to
->username
,
144 to
->host
, to
->from
->name
);
146 to
->flags
|= FLAGS_KILLED
;
148 exit_client(NULL
, to
, &me
, "Ghosted client");
152 _send_linebuf(to
, linebuf
);
156 /* send_queued_write()
158 * inputs - fd to have queue sent, client we're sending to
159 * outputs - contents of queue
160 * side effects - write is rescheduled if queue isnt emptied
163 send_queued_write(int fd
, void *data
)
165 struct Client
*to
= data
;
168 #ifdef USE_IODEBUG_HOOKS
171 fde_t
*F
= comm_locate_fd(to
->localClient
->fd
);
175 /* cant write anything to a dead socket. */
179 #ifdef USE_IODEBUG_HOOKS
181 if(to
->localClient
->buf_sendq
.list
.head
)
182 hd
.arg1
= ((buf_line_t
*) to
->localClient
->buf_sendq
.list
.head
->data
)->buf
+
183 to
->localClient
->buf_sendq
.writeofs
;
186 if(linebuf_len(&to
->localClient
->buf_sendq
))
189 linebuf_flush(F
, &to
->localClient
->buf_sendq
)) > 0)
191 /* We have some data written .. update counters */
192 #ifdef USE_IODEBUG_HOOKS
194 call_hook(h_iosend_id
, &hd
);
196 if(to
->localClient
->buf_sendq
.list
.head
)
198 ((buf_line_t
*) to
->localClient
->buf_sendq
.list
.head
->
199 data
)->buf
+ to
->localClient
->buf_sendq
.writeofs
;
203 to
->localClient
->sendB
+= retlen
;
204 me
.localClient
->sendB
+= retlen
;
205 if(to
->localClient
->sendB
> 1023)
207 to
->localClient
->sendK
+= (to
->localClient
->sendB
>> 10);
208 to
->localClient
->sendB
&= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */
210 else if(me
.localClient
->sendB
> 1023)
212 me
.localClient
->sendK
+= (me
.localClient
->sendB
>> 10);
213 me
.localClient
->sendB
&= 0x03ff;
217 if(retlen
== 0 || (retlen
< 0 && !ignoreErrno(errno
)))
223 if(ignoreErrno(errno
))
224 flags
= COMM_SELECT_WRITE
|COMM_SELECT_RETRY
;
226 flags
= COMM_SELECT_WRITE
;
227 if(linebuf_len(&to
->localClient
->buf_sendq
))
228 comm_setselect(fd
, FDLIST_IDLECLIENT
, flags
,
229 send_queued_write
, to
, 0);
232 /* send_queued_slink_write()
234 * inputs - fd to have queue sent, client we're sending to
235 * outputs - contents of queue
236 * side effects - write is rescheduled if queue isnt emptied
239 send_queued_slink_write(int fd
, void *data
)
241 struct Client
*to
= data
;
245 ** Once socket is marked dead, we cannot start writing to it,
246 ** even if the error is removed...
251 /* Next, lets try to write some data */
252 if(to
->localClient
->slinkq
)
254 retlen
= write(to
->localClient
->ctrlfd
,
255 to
->localClient
->slinkq
+ to
->localClient
->slinkq_ofs
,
256 to
->localClient
->slinkq_len
);
260 /* If we have a fatal error */
261 if(!ignoreErrno(errno
))
267 /* 0 bytes is an EOF .. */
275 to
->localClient
->slinkq_len
-= retlen
;
277 s_assert(to
->localClient
->slinkq_len
>= 0);
278 if(to
->localClient
->slinkq_len
)
279 to
->localClient
->slinkq_ofs
+= retlen
;
282 to
->localClient
->slinkq_ofs
= 0;
283 MyFree(to
->localClient
->slinkq
);
284 to
->localClient
->slinkq
= NULL
;
289 /* if we have any more data, reschedule a write */
290 if(to
->localClient
->slinkq_len
)
291 comm_setselect(to
->localClient
->ctrlfd
, FDLIST_IDLECLIENT
,
292 COMM_SELECT_WRITE
|COMM_SELECT_RETRY
, send_queued_slink_write
, to
, 0);
297 * inputs - client to send to, va_args
298 * outputs - client has message put into its queue
302 sendto_one(struct Client
*target_p
, const char *pattern
, ...)
307 /* send remote if to->from non NULL */
308 if(target_p
->from
!= NULL
)
309 target_p
= target_p
->from
;
311 if(IsIOError(target_p
))
314 linebuf_newbuf(&linebuf
);
316 va_start(args
, pattern
);
317 linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
320 _send_linebuf(target_p
, &linebuf
);
322 linebuf_donebuf(&linebuf
);
326 /* sendto_one_prefix()
328 * inputs - client to send to, va_args
329 * outputs - client has message put into its queue
330 * side effects - source(us)/target is chosen based on TS6 capability
333 sendto_one_prefix(struct Client
*target_p
, struct Client
*source_p
,
334 const char *command
, const char *pattern
, ...)
336 struct Client
*dest_p
;
340 /* send remote if to->from non NULL */
341 if(target_p
->from
!= NULL
)
342 dest_p
= target_p
->from
;
346 if(IsIOError(dest_p
))
351 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
355 linebuf_newbuf(&linebuf
);
356 va_start(args
, pattern
);
357 linebuf_putmsg(&linebuf
, pattern
, &args
,
359 get_id(source_p
, target_p
),
360 command
, get_id(target_p
, target_p
));
363 _send_linebuf(dest_p
, &linebuf
);
364 linebuf_donebuf(&linebuf
);
367 /* sendto_one_notice()
369 * inputs - client to send to, va_args
370 * outputs - client has a NOTICE put into its queue
371 * side effects - source(us)/target is chosen based on TS6 capability
374 sendto_one_notice(struct Client
*target_p
, const char *pattern
, ...)
376 struct Client
*dest_p
;
381 /* send remote if to->from non NULL */
382 if(target_p
->from
!= NULL
)
383 dest_p
= target_p
->from
;
387 if(IsIOError(dest_p
))
392 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
396 linebuf_newbuf(&linebuf
);
397 va_start(args
, pattern
);
398 linebuf_putmsg(&linebuf
, pattern
, &args
,
400 get_id(&me
, target_p
), *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
403 _send_linebuf(dest_p
, &linebuf
);
404 linebuf_donebuf(&linebuf
);
408 /* sendto_one_numeric()
410 * inputs - client to send to, va_args
411 * outputs - client has message put into its queue
412 * side effects - source/target is chosen based on TS6 capability
415 sendto_one_numeric(struct Client
*target_p
, int numeric
, const char *pattern
, ...)
417 struct Client
*dest_p
;
422 /* send remote if to->from non NULL */
423 if(target_p
->from
!= NULL
)
424 dest_p
= target_p
->from
;
428 if(IsIOError(dest_p
))
433 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
437 linebuf_newbuf(&linebuf
);
438 va_start(args
, pattern
);
439 linebuf_putmsg(&linebuf
, pattern
, &args
,
441 get_id(&me
, target_p
),
442 numeric
, *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
445 _send_linebuf(dest_p
, &linebuf
);
446 linebuf_donebuf(&linebuf
);
452 * inputs - pointer to client to NOT send to
453 * - caps or'd together which must ALL be present
454 * - caps or'd together which must ALL NOT be present
455 * - printf style format string
456 * - args to format string
458 * side effects - Send a message to all connected servers, except the
459 * client 'one' (if non-NULL), as long as the servers
460 * support ALL capabs in 'caps', and NO capabs in 'nocaps'.
462 * This function was written in an attempt to merge together the other
463 * billion sendto_*serv*() functions, which sprung up with capabs, uids etc
467 sendto_server(struct Client
*one
, struct Channel
*chptr
, unsigned long caps
,
468 unsigned long nocaps
, const char *format
, ...)
471 struct Client
*target_p
;
473 dlink_node
*next_ptr
;
476 /* noone to send to.. */
477 if(dlink_list_length(&serv_list
) == 0)
480 if(chptr
!= NULL
&& *chptr
->chname
!= '#')
483 linebuf_newbuf(&linebuf
);
484 va_start(args
, format
);
485 linebuf_putmsg(&linebuf
, format
, &args
, NULL
);
488 DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
490 target_p
= ptr
->data
;
492 /* check against 'one' */
493 if(one
!= NULL
&& (target_p
== one
->from
))
496 /* check we have required capabs */
497 if(!IsCapable(target_p
, caps
))
500 /* check we don't have any forbidden capabs */
501 if(!NotCapable(target_p
, nocaps
))
504 _send_linebuf(target_p
, &linebuf
);
507 linebuf_donebuf(&linebuf
);
511 /* sendto_channel_flags()
513 * inputs - server not to send to, flags needed, source, channel, va_args
514 * outputs - message is sent to channel members
518 sendto_channel_flags(struct Client
*one
, int type
, struct Client
*source_p
,
519 struct Channel
*chptr
, const char *pattern
, ...)
521 static char buf
[BUFSIZE
];
523 buf_head_t linebuf_local
;
524 buf_head_t linebuf_name
;
525 buf_head_t linebuf_id
;
526 struct Client
*target_p
;
527 struct membership
*msptr
;
529 dlink_node
*next_ptr
;
531 linebuf_newbuf(&linebuf_local
);
532 linebuf_newbuf(&linebuf_name
);
533 linebuf_newbuf(&linebuf_id
);
537 va_start(args
, pattern
);
538 ircvsnprintf(buf
, sizeof(buf
), pattern
, args
);
541 if(IsServer(source_p
))
542 linebuf_putmsg(&linebuf_local
, NULL
, NULL
,
543 ":%s %s", source_p
->name
, buf
);
545 linebuf_putmsg(&linebuf_local
, NULL
, NULL
,
547 source_p
->name
, source_p
->username
,
548 source_p
->host
, buf
);
550 linebuf_putmsg(&linebuf_name
, NULL
, NULL
, ":%s %s", source_p
->name
, buf
);
551 linebuf_putmsg(&linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
553 DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->members
.head
)
556 target_p
= msptr
->client_p
;
558 if(IsIOError(target_p
->from
) || target_p
->from
== one
)
561 if(type
&& ((msptr
->flags
& type
) == 0))
567 if(!MyClient(target_p
))
569 /* if we've got a specific type, target must support
572 if(type
&& NotCapable(target_p
->from
, CAP_CHW
))
575 if(target_p
->from
->serial
!= current_serial
)
577 if(has_id(target_p
->from
))
578 send_linebuf_remote(target_p
, source_p
, &linebuf_id
);
580 send_linebuf_remote(target_p
, source_p
, &linebuf_name
);
582 target_p
->from
->serial
= current_serial
;
586 _send_linebuf(target_p
, &linebuf_local
);
589 linebuf_donebuf(&linebuf_local
);
590 linebuf_donebuf(&linebuf_name
);
591 linebuf_donebuf(&linebuf_id
);
595 /* sendto_channel_local()
597 * inputs - flags to send to, channel to send to, va_args
598 * outputs - message to local channel members
602 sendto_channel_local(int type
, struct Channel
*chptr
, const char *pattern
, ...)
606 struct membership
*msptr
;
607 struct Client
*target_p
;
609 dlink_node
*next_ptr
;
611 linebuf_newbuf(&linebuf
);
613 va_start(args
, pattern
);
614 linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
617 DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
620 target_p
= msptr
->client_p
;
622 if(IsIOError(target_p
))
625 if(type
&& ((msptr
->flags
& type
) == 0))
628 _send_linebuf(target_p
, &linebuf
);
631 linebuf_donebuf(&linebuf
);
634 /* sendto_channel_local_butone()
636 * inputs - flags to send to, channel to send to, va_args
637 * - user to ignore when sending
638 * outputs - message to local channel members
642 sendto_channel_local_butone(struct Client
*one
, int type
, struct Channel
*chptr
, const char *pattern
, ...)
646 struct membership
*msptr
;
647 struct Client
*target_p
;
649 dlink_node
*next_ptr
;
651 linebuf_newbuf(&linebuf
);
653 va_start(args
, pattern
);
654 linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
657 DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
660 target_p
= msptr
->client_p
;
665 if(IsIOError(target_p
))
668 if(type
&& ((msptr
->flags
& type
) == 0))
671 _send_linebuf(target_p
, &linebuf
);
674 linebuf_donebuf(&linebuf
);
678 * sendto_common_channels_local()
680 * inputs - pointer to client
683 * side effects - Sends a message to all people on local server who are
684 * in same channel with user.
685 * used by m_nick.c and exit_one_client.
688 sendto_common_channels_local(struct Client
*user
, const char *pattern
, ...)
692 dlink_node
*next_ptr
;
694 dlink_node
*next_uptr
;
695 struct Channel
*chptr
;
696 struct Client
*target_p
;
697 struct membership
*msptr
;
698 struct membership
*mscptr
;
701 linebuf_newbuf(&linebuf
);
702 va_start(args
, pattern
);
703 linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
708 DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
711 chptr
= mscptr
->chptr
;
713 DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
716 target_p
= msptr
->client_p
;
718 if(IsIOError(target_p
) ||
719 target_p
->serial
== current_serial
)
722 target_p
->serial
= current_serial
;
723 send_linebuf(target_p
, &linebuf
);
727 /* this can happen when the user isnt in any channels, but we still
728 * need to send them the data, ie a nick change
730 if(MyConnect(user
) && (user
->serial
!= current_serial
))
731 send_linebuf(user
, &linebuf
);
733 linebuf_donebuf(&linebuf
);
737 * sendto_common_channels_local_butone()
739 * inputs - pointer to client
742 * side effects - Sends a message to all people on local server who are
743 * in same channel with user, except for user itself.
746 sendto_common_channels_local_butone(struct Client
*user
, const char *pattern
, ...)
750 dlink_node
*next_ptr
;
752 dlink_node
*next_uptr
;
753 struct Channel
*chptr
;
754 struct Client
*target_p
;
755 struct membership
*msptr
;
756 struct membership
*mscptr
;
759 linebuf_newbuf(&linebuf
);
760 va_start(args
, pattern
);
761 linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
765 /* Skip them -- jilles */
766 user
->serial
= current_serial
;
768 DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
771 chptr
= mscptr
->chptr
;
773 DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
776 target_p
= msptr
->client_p
;
778 if(IsIOError(target_p
) ||
779 target_p
->serial
== current_serial
)
782 target_p
->serial
= current_serial
;
783 send_linebuf(target_p
, &linebuf
);
787 linebuf_donebuf(&linebuf
);
790 /* sendto_match_butone()
792 * inputs - server not to send to, source, mask, type of mask, va_args
794 * side effects - message is sent to matching clients
797 sendto_match_butone(struct Client
*one
, struct Client
*source_p
,
798 const char *mask
, int what
, const char *pattern
, ...)
800 static char buf
[BUFSIZE
];
802 struct Client
*target_p
;
804 dlink_node
*next_ptr
;
805 buf_head_t linebuf_local
;
806 buf_head_t linebuf_name
;
807 buf_head_t linebuf_id
;
809 linebuf_newbuf(&linebuf_local
);
810 linebuf_newbuf(&linebuf_name
);
811 linebuf_newbuf(&linebuf_id
);
813 va_start(args
, pattern
);
814 ircvsnprintf(buf
, sizeof(buf
), pattern
, args
);
817 if(IsServer(source_p
))
818 linebuf_putmsg(&linebuf_local
, NULL
, NULL
,
819 ":%s %s", source_p
->name
, buf
);
821 linebuf_putmsg(&linebuf_local
, NULL
, NULL
,
823 source_p
->name
, source_p
->username
,
824 source_p
->host
, buf
);
826 linebuf_putmsg(&linebuf_name
, NULL
, NULL
, ":%s %s", source_p
->name
, buf
);
827 linebuf_putmsg(&linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
829 if(what
== MATCH_HOST
)
831 DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
833 target_p
= ptr
->data
;
835 if(match(mask
, target_p
->host
))
836 _send_linebuf(target_p
, &linebuf_local
);
839 /* what = MATCH_SERVER, if it doesnt match us, just send remote */
840 else if(match(mask
, me
.name
))
842 DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
844 target_p
= ptr
->data
;
845 _send_linebuf(target_p
, &linebuf_local
);
849 DLINK_FOREACH(ptr
, serv_list
.head
)
851 target_p
= ptr
->data
;
857 send_linebuf_remote(target_p
, source_p
, &linebuf_id
);
859 send_linebuf_remote(target_p
, source_p
, &linebuf_name
);
862 linebuf_donebuf(&linebuf_local
);
863 linebuf_donebuf(&linebuf_id
);
864 linebuf_donebuf(&linebuf_name
);
867 /* sendto_match_servs()
869 * inputs - source, mask to send to, caps needed, va_args
871 * side effects - message is sent to matching servers with caps.
874 sendto_match_servs(struct Client
*source_p
, const char *mask
, int cap
,
875 int nocap
, const char *pattern
, ...)
877 static char buf
[BUFSIZE
];
880 struct Client
*target_p
;
881 buf_head_t linebuf_id
;
882 buf_head_t linebuf_name
;
884 if(EmptyString(mask
))
887 linebuf_newbuf(&linebuf_id
);
888 linebuf_newbuf(&linebuf_name
);
890 va_start(args
, pattern
);
891 ircvsnprintf(buf
, sizeof(buf
), pattern
, args
);
894 linebuf_putmsg(&linebuf_id
, NULL
, NULL
,
895 ":%s %s", use_id(source_p
), buf
);
896 linebuf_putmsg(&linebuf_name
, NULL
, NULL
,
897 ":%s %s", source_p
->name
, buf
);
901 DLINK_FOREACH(ptr
, global_serv_list
.head
)
903 target_p
= ptr
->data
;
905 /* dont send to ourselves, or back to where it came from.. */
906 if(IsMe(target_p
) || target_p
->from
== source_p
->from
)
909 if(target_p
->from
->serial
== current_serial
)
912 if(match(mask
, target_p
->name
))
914 /* if we set the serial here, then we'll never do
915 * a match() again if !IsCapable()
917 target_p
->from
->serial
= current_serial
;
919 if(cap
&& !IsCapable(target_p
->from
, cap
))
922 if(nocap
&& !NotCapable(target_p
->from
, nocap
))
925 if(has_id(target_p
->from
))
926 _send_linebuf(target_p
->from
, &linebuf_id
);
928 _send_linebuf(target_p
->from
, &linebuf_name
);
932 linebuf_donebuf(&linebuf_id
);
933 linebuf_donebuf(&linebuf_name
);
938 * inputs - monitor nick to send to, format, va_args
939 * outputs - message to local users monitoring the given nick
943 sendto_monitor(struct monitor
*monptr
, const char *pattern
, ...)
947 struct Client
*target_p
;
949 dlink_node
*next_ptr
;
951 linebuf_newbuf(&linebuf
);
953 va_start(args
, pattern
);
954 linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
957 DLINK_FOREACH_SAFE(ptr
, next_ptr
, monptr
->users
.head
)
959 target_p
= ptr
->data
;
961 if(IsIOError(target_p
))
964 _send_linebuf(target_p
, &linebuf
);
967 linebuf_donebuf(&linebuf
);
972 * inputs - target, source, va_args
974 * side effects - client is sent message with correct prefix.
977 sendto_anywhere(struct Client
*target_p
, struct Client
*source_p
,
978 const char *command
, const char *pattern
, ...)
983 linebuf_newbuf(&linebuf
);
985 va_start(args
, pattern
);
987 if(MyClient(target_p
))
989 if(IsServer(source_p
))
990 linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
991 source_p
->name
, command
,
994 linebuf_putmsg(&linebuf
, pattern
, &args
,
996 source_p
->name
, source_p
->username
,
997 source_p
->host
, command
,
1001 linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
1002 get_id(source_p
, target_p
), command
,
1003 get_id(target_p
, target_p
));
1006 if(MyClient(target_p
))
1007 _send_linebuf(target_p
, &linebuf
);
1009 send_linebuf_remote(target_p
, source_p
, &linebuf
);
1011 linebuf_donebuf(&linebuf
);
1014 /* sendto_realops_flags()
1016 * inputs - umode needed, level (opers/admin), va_args
1018 * side effects - message is sent to opers with matching umodes
1021 sendto_realops_flags(int flags
, int level
, const char *pattern
, ...)
1023 struct Client
*client_p
;
1025 dlink_node
*next_ptr
;
1029 linebuf_newbuf(&linebuf
);
1031 va_start(args
, pattern
);
1032 linebuf_putmsg(&linebuf
, pattern
, &args
,
1033 ":%s NOTICE * :*** Notice -- ", me
.name
);
1036 DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1038 client_p
= ptr
->data
;
1040 /* If we're sending it to opers and theyre an admin, skip.
1041 * If we're sending it to admins, and theyre not, skip.
1043 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1044 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1047 if(client_p
->umodes
& flags
)
1048 _send_linebuf(client_p
, &linebuf
);
1051 linebuf_donebuf(&linebuf
);
1054 /* sendto_realops_snomask()
1056 * inputs - snomask needed, level (opers/admin), va_args
1058 * side effects - message is sent to opers with matching snomasks
1061 sendto_realops_snomask(int flags
, int level
, const char *pattern
, ...)
1063 static char buf
[BUFSIZE
];
1065 struct Client
*client_p
;
1067 dlink_node
*next_ptr
;
1071 linebuf_newbuf(&linebuf
);
1073 /* Be very sure not to do things like "Trying to send to myself"
1074 * L_NETWIDE, otherwise infinite recursion may result! -- jilles */
1075 if (level
& L_NETWIDE
&& ConfigFileEntry
.global_snotices
)
1077 /* rather a lot of copying around, oh well -- jilles */
1078 va_start(args
, pattern
);
1079 ircvsnprintf(buf
, sizeof(buf
), pattern
, args
);
1081 linebuf_putmsg(&linebuf
, pattern
, NULL
,
1082 ":%s NOTICE * :*** Notice -- %s", me
.name
, buf
);
1083 snobuf
= construct_snobuf(flags
);
1084 if (snobuf
[1] != '\0')
1086 sendto_server(NULL
, NULL
, CAP_ENCAP
|CAP_TS6
, NOCAPS
,
1087 ":%s ENCAP * SNOTE %c :%s",
1088 me
.id
, snobuf
[1], buf
);
1089 sendto_server(NULL
, NULL
, CAP_ENCAP
, CAP_TS6
,
1090 ":%s ENCAP * SNOTE %c :%s",
1091 me
.name
, snobuf
[1], buf
);
1096 va_start(args
, pattern
);
1097 linebuf_putmsg(&linebuf
, pattern
, &args
,
1098 ":%s NOTICE * :*** Notice -- ", me
.name
);
1101 level
&= ~L_NETWIDE
;
1103 DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1105 client_p
= ptr
->data
;
1107 /* If we're sending it to opers and theyre an admin, skip.
1108 * If we're sending it to admins, and theyre not, skip.
1110 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1111 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1114 if(client_p
->snomask
& flags
)
1115 _send_linebuf(client_p
, &linebuf
);
1118 linebuf_donebuf(&linebuf
);
1120 /* sendto_realops_snomask_from()
1122 * inputs - snomask needed, level (opers/admin), source server, va_args
1124 * side effects - message is sent to opers with matching snomask
1127 sendto_realops_snomask_from(int flags
, int level
, struct Client
*source_p
,
1128 const char *pattern
, ...)
1130 struct Client
*client_p
;
1132 dlink_node
*next_ptr
;
1136 linebuf_newbuf(&linebuf
);
1138 va_start(args
, pattern
);
1139 linebuf_putmsg(&linebuf
, pattern
, &args
,
1140 ":%s NOTICE * :*** Notice -- ", source_p
->name
);
1143 DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1145 client_p
= ptr
->data
;
1147 /* If we're sending it to opers and theyre an admin, skip.
1148 * If we're sending it to admins, and theyre not, skip.
1150 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1151 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1154 if(client_p
->snomask
& flags
)
1155 _send_linebuf(client_p
, &linebuf
);
1158 linebuf_donebuf(&linebuf
);
1162 * sendto_wallops_flags
1164 * inputs - flag types of messages to show to real opers
1165 * - client sending request
1166 * - var args input message
1168 * side effects - Send a wallops to local opers
1171 sendto_wallops_flags(int flags
, struct Client
*source_p
, const char *pattern
, ...)
1173 struct Client
*client_p
;
1175 dlink_node
*next_ptr
;
1179 linebuf_newbuf(&linebuf
);
1181 va_start(args
, pattern
);
1183 if(IsPerson(source_p
))
1184 linebuf_putmsg(&linebuf
, pattern
, &args
,
1185 ":%s!%s@%s WALLOPS :", source_p
->name
,
1186 source_p
->username
, source_p
->host
);
1188 linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s WALLOPS :", source_p
->name
);
1192 DLINK_FOREACH_SAFE(ptr
, next_ptr
, IsPerson(source_p
) && flags
== UMODE_WALLOP
? lclient_list
.head
: local_oper_list
.head
)
1194 client_p
= ptr
->data
;
1196 if(client_p
->umodes
& flags
)
1197 _send_linebuf(client_p
, &linebuf
);
1200 linebuf_donebuf(&linebuf
);
1205 * input - client to send kill to, client to kill, va_args
1207 * side effects - we issue a kill for the client
1210 kill_client(struct Client
*target_p
, struct Client
*diedie
, const char *pattern
, ...)
1215 linebuf_newbuf(&linebuf
);
1217 va_start(args
, pattern
);
1218 linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s KILL %s :",
1219 get_id(&me
, target_p
), get_id(diedie
, target_p
));
1222 send_linebuf(target_p
, &linebuf
);
1223 linebuf_donebuf(&linebuf
);
1228 * kill_client_serv_butone
1230 * inputs - pointer to client to not send to
1231 * - pointer to client to kill
1233 * side effects - Send a KILL for the given client
1234 * message to all connected servers
1235 * except the client 'one'. Also deal with
1236 * client being unknown to leaf, as in lazylink...
1239 kill_client_serv_butone(struct Client
*one
, struct Client
*target_p
, const char *pattern
, ...)
1241 static char buf
[BUFSIZE
];
1243 struct Client
*client_p
;
1245 dlink_node
*next_ptr
;
1246 buf_head_t linebuf_id
;
1247 buf_head_t linebuf_name
;
1249 linebuf_newbuf(&linebuf_name
);
1250 linebuf_newbuf(&linebuf_id
);
1252 va_start(args
, pattern
);
1253 ircvsnprintf(buf
, sizeof(buf
), pattern
, args
);
1256 linebuf_putmsg(&linebuf_name
, NULL
, NULL
, ":%s KILL %s :%s",
1257 me
.name
, target_p
->name
, buf
);
1258 linebuf_putmsg(&linebuf_id
, NULL
, NULL
, ":%s KILL %s :%s",
1259 use_id(&me
), use_id(target_p
), buf
);
1261 DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
1263 client_p
= ptr
->data
;
1265 /* ok, if the client we're supposed to not send to has an
1266 * ID, then we still want to issue the kill there..
1268 if(one
!= NULL
&& (client_p
== one
->from
) &&
1269 (!has_id(client_p
) || !has_id(target_p
)))
1272 if(has_id(client_p
))
1273 _send_linebuf(client_p
, &linebuf_id
);
1275 _send_linebuf(client_p
, &linebuf_name
);
1278 linebuf_donebuf(&linebuf_id
);
1279 linebuf_donebuf(&linebuf_name
);