]>
jfr.im git - solanum.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 /* cant write anything to a dead socket. */
175 #ifdef USE_IODEBUG_HOOKS
177 if(to
->localClient
->buf_sendq
.list
.head
)
178 hd
.arg1
= ((buf_line_t
*) to
->localClient
->buf_sendq
.list
.head
->data
)->buf
+
179 to
->localClient
->buf_sendq
.writeofs
;
182 if(linebuf_len(&to
->localClient
->buf_sendq
))
185 linebuf_flush(to
->localClient
->fd
, &to
->localClient
->buf_sendq
)) > 0)
187 /* We have some data written .. update counters */
188 #ifdef USE_IODEBUG_HOOKS
190 call_hook(h_iosend_id
, &hd
);
192 if(to
->localClient
->buf_sendq
.list
.head
)
194 ((buf_line_t
*) to
->localClient
->buf_sendq
.list
.head
->
195 data
)->buf
+ to
->localClient
->buf_sendq
.writeofs
;
199 to
->localClient
->sendB
+= retlen
;
200 me
.localClient
->sendB
+= retlen
;
201 if(to
->localClient
->sendB
> 1023)
203 to
->localClient
->sendK
+= (to
->localClient
->sendB
>> 10);
204 to
->localClient
->sendB
&= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */
206 else if(me
.localClient
->sendB
> 1023)
208 me
.localClient
->sendK
+= (me
.localClient
->sendB
>> 10);
209 me
.localClient
->sendB
&= 0x03ff;
213 if(retlen
== 0 || (retlen
< 0 && !ignoreErrno(errno
)))
219 if(ignoreErrno(errno
))
220 flags
= COMM_SELECT_WRITE
|COMM_SELECT_RETRY
;
222 flags
= COMM_SELECT_WRITE
;
223 if(linebuf_len(&to
->localClient
->buf_sendq
))
224 comm_setselect(fd
, FDLIST_IDLECLIENT
, flags
,
225 send_queued_write
, to
, 0);
228 /* send_queued_slink_write()
230 * inputs - fd to have queue sent, client we're sending to
231 * outputs - contents of queue
232 * side effects - write is rescheduled if queue isnt emptied
235 send_queued_slink_write(int fd
, void *data
)
237 struct Client
*to
= data
;
241 ** Once socket is marked dead, we cannot start writing to it,
242 ** even if the error is removed...
247 /* Next, lets try to write some data */
248 if(to
->localClient
->slinkq
)
250 retlen
= write(to
->localClient
->ctrlfd
,
251 to
->localClient
->slinkq
+ to
->localClient
->slinkq_ofs
,
252 to
->localClient
->slinkq_len
);
256 /* If we have a fatal error */
257 if(!ignoreErrno(errno
))
263 /* 0 bytes is an EOF .. */
271 to
->localClient
->slinkq_len
-= retlen
;
273 s_assert(to
->localClient
->slinkq_len
>= 0);
274 if(to
->localClient
->slinkq_len
)
275 to
->localClient
->slinkq_ofs
+= retlen
;
278 to
->localClient
->slinkq_ofs
= 0;
279 MyFree(to
->localClient
->slinkq
);
280 to
->localClient
->slinkq
= NULL
;
285 /* if we have any more data, reschedule a write */
286 if(to
->localClient
->slinkq_len
)
287 comm_setselect(to
->localClient
->ctrlfd
, FDLIST_IDLECLIENT
,
288 COMM_SELECT_WRITE
|COMM_SELECT_RETRY
, send_queued_slink_write
, to
, 0);
293 * inputs - client to send to, va_args
294 * outputs - client has message put into its queue
298 sendto_one(struct Client
*target_p
, const char *pattern
, ...)
303 /* send remote if to->from non NULL */
304 if(target_p
->from
!= NULL
)
305 target_p
= target_p
->from
;
307 if(IsIOError(target_p
))
310 linebuf_newbuf(&linebuf
);
312 va_start(args
, pattern
);
313 linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
316 _send_linebuf(target_p
, &linebuf
);
318 linebuf_donebuf(&linebuf
);
322 /* sendto_one_prefix()
324 * inputs - client to send to, va_args
325 * outputs - client has message put into its queue
326 * side effects - source(us)/target is chosen based on TS6 capability
329 sendto_one_prefix(struct Client
*target_p
, struct Client
*source_p
,
330 const char *command
, const char *pattern
, ...)
332 struct Client
*dest_p
;
336 /* send remote if to->from non NULL */
337 if(target_p
->from
!= NULL
)
338 dest_p
= target_p
->from
;
342 if(IsIOError(dest_p
))
347 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
351 linebuf_newbuf(&linebuf
);
352 va_start(args
, pattern
);
353 linebuf_putmsg(&linebuf
, pattern
, &args
,
355 get_id(source_p
, target_p
),
356 command
, get_id(target_p
, target_p
));
359 _send_linebuf(dest_p
, &linebuf
);
360 linebuf_donebuf(&linebuf
);
363 /* sendto_one_notice()
365 * inputs - client to send to, va_args
366 * outputs - client has a NOTICE put into its queue
367 * side effects - source(us)/target is chosen based on TS6 capability
370 sendto_one_notice(struct Client
*target_p
, const char *pattern
, ...)
372 struct Client
*dest_p
;
377 /* send remote if to->from non NULL */
378 if(target_p
->from
!= NULL
)
379 dest_p
= target_p
->from
;
383 if(IsIOError(dest_p
))
388 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
392 linebuf_newbuf(&linebuf
);
393 va_start(args
, pattern
);
394 linebuf_putmsg(&linebuf
, pattern
, &args
,
396 get_id(&me
, target_p
), *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
399 _send_linebuf(dest_p
, &linebuf
);
400 linebuf_donebuf(&linebuf
);
404 /* sendto_one_numeric()
406 * inputs - client to send to, va_args
407 * outputs - client has message put into its queue
408 * side effects - source/target is chosen based on TS6 capability
411 sendto_one_numeric(struct Client
*target_p
, int numeric
, const char *pattern
, ...)
413 struct Client
*dest_p
;
418 /* send remote if to->from non NULL */
419 if(target_p
->from
!= NULL
)
420 dest_p
= target_p
->from
;
424 if(IsIOError(dest_p
))
429 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
433 linebuf_newbuf(&linebuf
);
434 va_start(args
, pattern
);
435 linebuf_putmsg(&linebuf
, pattern
, &args
,
437 get_id(&me
, target_p
),
438 numeric
, *(to
= get_id(target_p
, target_p
)) != '\0' ? to
: "*");
441 _send_linebuf(dest_p
, &linebuf
);
442 linebuf_donebuf(&linebuf
);
448 * inputs - pointer to client to NOT send to
449 * - caps or'd together which must ALL be present
450 * - caps or'd together which must ALL NOT be present
451 * - printf style format string
452 * - args to format string
454 * side effects - Send a message to all connected servers, except the
455 * client 'one' (if non-NULL), as long as the servers
456 * support ALL capabs in 'caps', and NO capabs in 'nocaps'.
458 * This function was written in an attempt to merge together the other
459 * billion sendto_*serv*() functions, which sprung up with capabs, uids etc
463 sendto_server(struct Client
*one
, struct Channel
*chptr
, unsigned long caps
,
464 unsigned long nocaps
, const char *format
, ...)
467 struct Client
*target_p
;
469 dlink_node
*next_ptr
;
472 /* noone to send to.. */
473 if(dlink_list_length(&serv_list
) == 0)
476 if(chptr
!= NULL
&& *chptr
->chname
!= '#')
479 linebuf_newbuf(&linebuf
);
480 va_start(args
, format
);
481 linebuf_putmsg(&linebuf
, format
, &args
, NULL
);
484 DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
486 target_p
= ptr
->data
;
488 /* check against 'one' */
489 if(one
!= NULL
&& (target_p
== one
->from
))
492 /* check we have required capabs */
493 if(!IsCapable(target_p
, caps
))
496 /* check we don't have any forbidden capabs */
497 if(!NotCapable(target_p
, nocaps
))
500 _send_linebuf(target_p
, &linebuf
);
503 linebuf_donebuf(&linebuf
);
507 /* sendto_channel_flags()
509 * inputs - server not to send to, flags needed, source, channel, va_args
510 * outputs - message is sent to channel members
514 sendto_channel_flags(struct Client
*one
, int type
, struct Client
*source_p
,
515 struct Channel
*chptr
, const char *pattern
, ...)
517 static char buf
[BUFSIZE
];
519 buf_head_t linebuf_local
;
520 buf_head_t linebuf_name
;
521 buf_head_t linebuf_id
;
522 struct Client
*target_p
;
523 struct membership
*msptr
;
525 dlink_node
*next_ptr
;
527 linebuf_newbuf(&linebuf_local
);
528 linebuf_newbuf(&linebuf_name
);
529 linebuf_newbuf(&linebuf_id
);
533 va_start(args
, pattern
);
534 ircvsnprintf(buf
, sizeof(buf
), pattern
, args
);
537 if(IsServer(source_p
))
538 linebuf_putmsg(&linebuf_local
, NULL
, NULL
,
539 ":%s %s", source_p
->name
, buf
);
541 linebuf_putmsg(&linebuf_local
, NULL
, NULL
,
543 source_p
->name
, source_p
->username
,
544 source_p
->host
, buf
);
546 linebuf_putmsg(&linebuf_name
, NULL
, NULL
, ":%s %s", source_p
->name
, buf
);
547 linebuf_putmsg(&linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
549 DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->members
.head
)
552 target_p
= msptr
->client_p
;
554 if(IsIOError(target_p
->from
) || target_p
->from
== one
)
557 if(type
&& ((msptr
->flags
& type
) == 0))
563 if(!MyClient(target_p
))
565 /* if we've got a specific type, target must support
568 if(type
&& NotCapable(target_p
->from
, CAP_CHW
))
571 if(target_p
->from
->serial
!= current_serial
)
573 if(has_id(target_p
->from
))
574 send_linebuf_remote(target_p
, source_p
, &linebuf_id
);
576 send_linebuf_remote(target_p
, source_p
, &linebuf_name
);
578 target_p
->from
->serial
= current_serial
;
582 _send_linebuf(target_p
, &linebuf_local
);
585 linebuf_donebuf(&linebuf_local
);
586 linebuf_donebuf(&linebuf_name
);
587 linebuf_donebuf(&linebuf_id
);
591 /* sendto_channel_local()
593 * inputs - flags to send to, channel to send to, va_args
594 * outputs - message to local channel members
598 sendto_channel_local(int type
, struct Channel
*chptr
, const char *pattern
, ...)
602 struct membership
*msptr
;
603 struct Client
*target_p
;
605 dlink_node
*next_ptr
;
607 linebuf_newbuf(&linebuf
);
609 va_start(args
, pattern
);
610 linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
613 DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
616 target_p
= msptr
->client_p
;
618 if(IsIOError(target_p
))
621 if(type
&& ((msptr
->flags
& type
) == 0))
624 _send_linebuf(target_p
, &linebuf
);
627 linebuf_donebuf(&linebuf
);
630 /* sendto_channel_local_butone()
632 * inputs - flags to send to, channel to send to, va_args
633 * - user to ignore when sending
634 * outputs - message to local channel members
638 sendto_channel_local_butone(struct Client
*one
, int type
, struct Channel
*chptr
, const char *pattern
, ...)
642 struct membership
*msptr
;
643 struct Client
*target_p
;
645 dlink_node
*next_ptr
;
647 linebuf_newbuf(&linebuf
);
649 va_start(args
, pattern
);
650 linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
653 DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
656 target_p
= msptr
->client_p
;
661 if(IsIOError(target_p
))
664 if(type
&& ((msptr
->flags
& type
) == 0))
667 _send_linebuf(target_p
, &linebuf
);
670 linebuf_donebuf(&linebuf
);
674 * sendto_common_channels_local()
676 * inputs - pointer to client
679 * side effects - Sends a message to all people on local server who are
680 * in same channel with user.
681 * used by m_nick.c and exit_one_client.
684 sendto_common_channels_local(struct Client
*user
, const char *pattern
, ...)
688 dlink_node
*next_ptr
;
690 dlink_node
*next_uptr
;
691 struct Channel
*chptr
;
692 struct Client
*target_p
;
693 struct membership
*msptr
;
694 struct membership
*mscptr
;
697 linebuf_newbuf(&linebuf
);
698 va_start(args
, pattern
);
699 linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
704 DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
707 chptr
= mscptr
->chptr
;
709 DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
712 target_p
= msptr
->client_p
;
714 if(IsIOError(target_p
) ||
715 target_p
->serial
== current_serial
)
718 target_p
->serial
= current_serial
;
719 send_linebuf(target_p
, &linebuf
);
723 /* this can happen when the user isnt in any channels, but we still
724 * need to send them the data, ie a nick change
726 if(MyConnect(user
) && (user
->serial
!= current_serial
))
727 send_linebuf(user
, &linebuf
);
729 linebuf_donebuf(&linebuf
);
733 * sendto_common_channels_local_butone()
735 * inputs - pointer to client
738 * side effects - Sends a message to all people on local server who are
739 * in same channel with user, except for user itself.
742 sendto_common_channels_local_butone(struct Client
*user
, const char *pattern
, ...)
746 dlink_node
*next_ptr
;
748 dlink_node
*next_uptr
;
749 struct Channel
*chptr
;
750 struct Client
*target_p
;
751 struct membership
*msptr
;
752 struct membership
*mscptr
;
755 linebuf_newbuf(&linebuf
);
756 va_start(args
, pattern
);
757 linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
761 /* Skip them -- jilles */
762 user
->serial
= current_serial
;
764 DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
767 chptr
= mscptr
->chptr
;
769 DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
772 target_p
= msptr
->client_p
;
774 if(IsIOError(target_p
) ||
775 target_p
->serial
== current_serial
)
778 target_p
->serial
= current_serial
;
779 send_linebuf(target_p
, &linebuf
);
783 linebuf_donebuf(&linebuf
);
786 /* sendto_match_butone()
788 * inputs - server not to send to, source, mask, type of mask, va_args
790 * side effects - message is sent to matching clients
793 sendto_match_butone(struct Client
*one
, struct Client
*source_p
,
794 const char *mask
, int what
, const char *pattern
, ...)
796 static char buf
[BUFSIZE
];
798 struct Client
*target_p
;
800 dlink_node
*next_ptr
;
801 buf_head_t linebuf_local
;
802 buf_head_t linebuf_name
;
803 buf_head_t linebuf_id
;
805 linebuf_newbuf(&linebuf_local
);
806 linebuf_newbuf(&linebuf_name
);
807 linebuf_newbuf(&linebuf_id
);
809 va_start(args
, pattern
);
810 ircvsnprintf(buf
, sizeof(buf
), pattern
, args
);
813 if(IsServer(source_p
))
814 linebuf_putmsg(&linebuf_local
, NULL
, NULL
,
815 ":%s %s", source_p
->name
, buf
);
817 linebuf_putmsg(&linebuf_local
, NULL
, NULL
,
819 source_p
->name
, source_p
->username
,
820 source_p
->host
, buf
);
822 linebuf_putmsg(&linebuf_name
, NULL
, NULL
, ":%s %s", source_p
->name
, buf
);
823 linebuf_putmsg(&linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
825 if(what
== MATCH_HOST
)
827 DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
829 target_p
= ptr
->data
;
831 if(match(mask
, target_p
->host
))
832 _send_linebuf(target_p
, &linebuf_local
);
835 /* what = MATCH_SERVER, if it doesnt match us, just send remote */
836 else if(match(mask
, me
.name
))
838 DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
840 target_p
= ptr
->data
;
841 _send_linebuf(target_p
, &linebuf_local
);
845 DLINK_FOREACH(ptr
, serv_list
.head
)
847 target_p
= ptr
->data
;
853 send_linebuf_remote(target_p
, source_p
, &linebuf_id
);
855 send_linebuf_remote(target_p
, source_p
, &linebuf_name
);
858 linebuf_donebuf(&linebuf_local
);
859 linebuf_donebuf(&linebuf_id
);
860 linebuf_donebuf(&linebuf_name
);
863 /* sendto_match_servs()
865 * inputs - source, mask to send to, caps needed, va_args
867 * side effects - message is sent to matching servers with caps.
870 sendto_match_servs(struct Client
*source_p
, const char *mask
, int cap
,
871 int nocap
, const char *pattern
, ...)
873 static char buf
[BUFSIZE
];
876 struct Client
*target_p
;
877 buf_head_t linebuf_id
;
878 buf_head_t linebuf_name
;
880 if(EmptyString(mask
))
883 linebuf_newbuf(&linebuf_id
);
884 linebuf_newbuf(&linebuf_name
);
886 va_start(args
, pattern
);
887 ircvsnprintf(buf
, sizeof(buf
), pattern
, args
);
890 linebuf_putmsg(&linebuf_id
, NULL
, NULL
,
891 ":%s %s", use_id(source_p
), buf
);
892 linebuf_putmsg(&linebuf_name
, NULL
, NULL
,
893 ":%s %s", source_p
->name
, buf
);
897 DLINK_FOREACH(ptr
, global_serv_list
.head
)
899 target_p
= ptr
->data
;
901 /* dont send to ourselves, or back to where it came from.. */
902 if(IsMe(target_p
) || target_p
->from
== source_p
->from
)
905 if(target_p
->from
->serial
== current_serial
)
908 if(match(mask
, target_p
->name
))
910 /* if we set the serial here, then we'll never do
911 * a match() again if !IsCapable()
913 target_p
->from
->serial
= current_serial
;
915 if(cap
&& !IsCapable(target_p
->from
, cap
))
918 if(nocap
&& !NotCapable(target_p
->from
, nocap
))
921 if(has_id(target_p
->from
))
922 _send_linebuf(target_p
->from
, &linebuf_id
);
924 _send_linebuf(target_p
->from
, &linebuf_name
);
928 linebuf_donebuf(&linebuf_id
);
929 linebuf_donebuf(&linebuf_name
);
934 * inputs - monitor nick to send to, format, va_args
935 * outputs - message to local users monitoring the given nick
939 sendto_monitor(struct monitor
*monptr
, const char *pattern
, ...)
943 struct Client
*target_p
;
945 dlink_node
*next_ptr
;
947 linebuf_newbuf(&linebuf
);
949 va_start(args
, pattern
);
950 linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
953 DLINK_FOREACH_SAFE(ptr
, next_ptr
, monptr
->users
.head
)
955 target_p
= ptr
->data
;
957 if(IsIOError(target_p
))
960 _send_linebuf(target_p
, &linebuf
);
963 linebuf_donebuf(&linebuf
);
968 * inputs - target, source, va_args
970 * side effects - client is sent message with correct prefix.
973 sendto_anywhere(struct Client
*target_p
, struct Client
*source_p
,
974 const char *command
, const char *pattern
, ...)
979 linebuf_newbuf(&linebuf
);
981 va_start(args
, pattern
);
983 if(MyClient(target_p
))
985 if(IsServer(source_p
))
986 linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
987 source_p
->name
, command
,
990 linebuf_putmsg(&linebuf
, pattern
, &args
,
992 source_p
->name
, source_p
->username
,
993 source_p
->host
, command
,
997 linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
998 get_id(source_p
, target_p
), command
,
999 get_id(target_p
, target_p
));
1002 if(MyClient(target_p
))
1003 _send_linebuf(target_p
, &linebuf
);
1005 send_linebuf_remote(target_p
, source_p
, &linebuf
);
1007 linebuf_donebuf(&linebuf
);
1010 /* sendto_realops_flags()
1012 * inputs - umode needed, level (opers/admin), va_args
1014 * side effects - message is sent to opers with matching umodes
1017 sendto_realops_flags(int flags
, int level
, const char *pattern
, ...)
1019 struct Client
*client_p
;
1021 dlink_node
*next_ptr
;
1025 linebuf_newbuf(&linebuf
);
1027 va_start(args
, pattern
);
1028 linebuf_putmsg(&linebuf
, pattern
, &args
,
1029 ":%s NOTICE * :*** Notice -- ", me
.name
);
1032 DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1034 client_p
= ptr
->data
;
1036 /* If we're sending it to opers and theyre an admin, skip.
1037 * If we're sending it to admins, and theyre not, skip.
1039 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1040 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1043 if(client_p
->umodes
& flags
)
1044 _send_linebuf(client_p
, &linebuf
);
1047 linebuf_donebuf(&linebuf
);
1050 /* sendto_realops_snomask()
1052 * inputs - snomask needed, level (opers/admin), va_args
1054 * side effects - message is sent to opers with matching snomasks
1057 sendto_realops_snomask(int flags
, int level
, const char *pattern
, ...)
1059 static char buf
[BUFSIZE
];
1061 struct Client
*client_p
;
1063 dlink_node
*next_ptr
;
1067 linebuf_newbuf(&linebuf
);
1069 /* Be very sure not to do things like "Trying to send to myself"
1070 * L_NETWIDE, otherwise infinite recursion may result! -- jilles */
1071 if (level
& L_NETWIDE
&& ConfigFileEntry
.global_snotices
)
1073 /* rather a lot of copying around, oh well -- jilles */
1074 va_start(args
, pattern
);
1075 ircvsnprintf(buf
, sizeof(buf
), pattern
, args
);
1077 linebuf_putmsg(&linebuf
, pattern
, NULL
,
1078 ":%s NOTICE * :*** Notice -- %s", me
.name
, buf
);
1079 snobuf
= construct_snobuf(flags
);
1080 if (snobuf
[1] != '\0')
1082 sendto_server(NULL
, NULL
, CAP_ENCAP
|CAP_TS6
, NOCAPS
,
1083 ":%s ENCAP * SNOTE %c :%s",
1084 me
.id
, snobuf
[1], buf
);
1085 sendto_server(NULL
, NULL
, CAP_ENCAP
, CAP_TS6
,
1086 ":%s ENCAP * SNOTE %c :%s",
1087 me
.name
, snobuf
[1], buf
);
1092 va_start(args
, pattern
);
1093 linebuf_putmsg(&linebuf
, pattern
, &args
,
1094 ":%s NOTICE * :*** Notice -- ", me
.name
);
1097 level
&= ~L_NETWIDE
;
1099 DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1101 client_p
= ptr
->data
;
1103 /* If we're sending it to opers and theyre an admin, skip.
1104 * If we're sending it to admins, and theyre not, skip.
1106 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1107 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1110 if(client_p
->snomask
& flags
)
1111 _send_linebuf(client_p
, &linebuf
);
1114 linebuf_donebuf(&linebuf
);
1116 /* sendto_realops_snomask_from()
1118 * inputs - snomask needed, level (opers/admin), source server, va_args
1120 * side effects - message is sent to opers with matching snomask
1123 sendto_realops_snomask_from(int flags
, int level
, struct Client
*source_p
,
1124 const char *pattern
, ...)
1126 struct Client
*client_p
;
1128 dlink_node
*next_ptr
;
1132 linebuf_newbuf(&linebuf
);
1134 va_start(args
, pattern
);
1135 linebuf_putmsg(&linebuf
, pattern
, &args
,
1136 ":%s NOTICE * :*** Notice -- ", source_p
->name
);
1139 DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1141 client_p
= ptr
->data
;
1143 /* If we're sending it to opers and theyre an admin, skip.
1144 * If we're sending it to admins, and theyre not, skip.
1146 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1147 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1150 if(client_p
->snomask
& flags
)
1151 _send_linebuf(client_p
, &linebuf
);
1154 linebuf_donebuf(&linebuf
);
1158 * sendto_wallops_flags
1160 * inputs - flag types of messages to show to real opers
1161 * - client sending request
1162 * - var args input message
1164 * side effects - Send a wallops to local opers
1167 sendto_wallops_flags(int flags
, struct Client
*source_p
, const char *pattern
, ...)
1169 struct Client
*client_p
;
1171 dlink_node
*next_ptr
;
1175 linebuf_newbuf(&linebuf
);
1177 va_start(args
, pattern
);
1179 if(IsPerson(source_p
))
1180 linebuf_putmsg(&linebuf
, pattern
, &args
,
1181 ":%s!%s@%s WALLOPS :", source_p
->name
,
1182 source_p
->username
, source_p
->host
);
1184 linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s WALLOPS :", source_p
->name
);
1188 DLINK_FOREACH_SAFE(ptr
, next_ptr
, IsPerson(source_p
) && flags
== UMODE_WALLOP
? lclient_list
.head
: local_oper_list
.head
)
1190 client_p
= ptr
->data
;
1192 if(client_p
->umodes
& flags
)
1193 _send_linebuf(client_p
, &linebuf
);
1196 linebuf_donebuf(&linebuf
);
1201 * input - client to send kill to, client to kill, va_args
1203 * side effects - we issue a kill for the client
1206 kill_client(struct Client
*target_p
, struct Client
*diedie
, const char *pattern
, ...)
1211 linebuf_newbuf(&linebuf
);
1213 va_start(args
, pattern
);
1214 linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s KILL %s :",
1215 get_id(&me
, target_p
), get_id(diedie
, target_p
));
1218 send_linebuf(target_p
, &linebuf
);
1219 linebuf_donebuf(&linebuf
);
1224 * kill_client_serv_butone
1226 * inputs - pointer to client to not send to
1227 * - pointer to client to kill
1229 * side effects - Send a KILL for the given client
1230 * message to all connected servers
1231 * except the client 'one'. Also deal with
1232 * client being unknown to leaf, as in lazylink...
1235 kill_client_serv_butone(struct Client
*one
, struct Client
*target_p
, const char *pattern
, ...)
1237 static char buf
[BUFSIZE
];
1239 struct Client
*client_p
;
1241 dlink_node
*next_ptr
;
1242 buf_head_t linebuf_id
;
1243 buf_head_t linebuf_name
;
1245 linebuf_newbuf(&linebuf_name
);
1246 linebuf_newbuf(&linebuf_id
);
1248 va_start(args
, pattern
);
1249 ircvsnprintf(buf
, sizeof(buf
), pattern
, args
);
1252 linebuf_putmsg(&linebuf_name
, NULL
, NULL
, ":%s KILL %s :%s",
1253 me
.name
, target_p
->name
, buf
);
1254 linebuf_putmsg(&linebuf_id
, NULL
, NULL
, ":%s KILL %s :%s",
1255 use_id(&me
), use_id(target_p
), buf
);
1257 DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
1259 client_p
= ptr
->data
;
1261 /* ok, if the client we're supposed to not send to has an
1262 * ID, then we still want to issue the kill there..
1264 if(one
!= NULL
&& (client_p
== one
->from
) &&
1265 (!has_id(client_p
) || !has_id(target_p
)))
1268 if(has_id(client_p
))
1269 _send_linebuf(client_p
, &linebuf_id
);
1271 _send_linebuf(client_p
, &linebuf_name
);
1274 linebuf_donebuf(&linebuf_id
);
1275 linebuf_donebuf(&linebuf_name
);