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 108 2006-10-14 18:12:28Z spb $
34 #include "irc_string.h"
39 #include "sprintf_irc.h"
41 #include "s_newconf.h"
47 #define LOG_BUFSIZE 2048
49 /* send the message to the link the target is attached to */
50 #define send_linebuf(a,b) _send_linebuf((a->from ? a->from : a) ,b)
52 unsigned long current_serial
= 0L;
56 * inputs - client to send to, linebuf to attach
58 * side effects - linebuf is attached to client
61 _send_linebuf(struct Client
*to
, buf_head_t
*linebuf
)
65 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send message to myself!");
69 if(!MyConnect(to
) || IsIOError(to
))
72 if(linebuf_len(&to
->localClient
->buf_sendq
) > get_sendq(to
))
76 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
77 "Max SendQ limit exceeded for %s: %u > %lu",
78 get_server_name(to
, HIDE_IP
),
79 linebuf_len(&to
->localClient
->buf_sendq
),
82 ilog(L_SERVER
, "Max SendQ limit exceeded for %s: %u > %lu",
83 log_client_name(to
, SHOW_IP
),
84 linebuf_len(&to
->localClient
->buf_sendq
),
89 to
->flags
|= FLAGS_SENDQEX
;
96 /* just attach the linebuf to the sendq instead of
97 * generating a new one
99 linebuf_attach(&to
->localClient
->buf_sendq
, linebuf
);
103 ** Update statistics. The following is slightly incorrect
104 ** because it counts messages even if queued, but bytes
105 ** only really sent. Queued bytes get updated in SendQueued.
107 to
->localClient
->sendM
+= 1;
108 me
.localClient
->sendM
+= 1;
109 if(linebuf_len(&to
->localClient
->buf_sendq
) > 0)
110 send_queued_write(to
->localClient
->fd
, to
);
114 /* send_linebuf_remote()
116 * inputs - client to attach to, sender, linebuf
118 * side effects - client has linebuf attached
121 send_linebuf_remote(struct Client
*to
, struct Client
*from
, buf_head_t
*linebuf
)
126 /* test for fake direction */
127 if(!MyClient(from
) && IsPerson(to
) && (to
== from
->from
))
131 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
132 "Send message to %s[%s] dropped from %s(Fake Dir)",
133 to
->name
, to
->from
->name
, from
->name
);
137 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
138 "Ghosted: %s[%s@%s] from %s[%s@%s] (%s)",
139 to
->name
, to
->username
, to
->host
,
140 from
->name
, from
->username
, from
->host
, to
->from
->name
);
141 kill_client_serv_butone(NULL
, to
, "%s (%s[%s@%s] Ghosted %s)",
142 me
.name
, to
->name
, to
->username
,
143 to
->host
, to
->from
->name
);
145 to
->flags
|= FLAGS_KILLED
;
147 exit_client(NULL
, to
, &me
, "Ghosted client");
151 _send_linebuf(to
, linebuf
);
155 /* send_queued_write()
157 * inputs - fd to have queue sent, client we're sending to
158 * outputs - contents of queue
159 * side effects - write is rescheduled if queue isnt emptied
162 send_queued_write(int fd
, void *data
)
164 struct Client
*to
= data
;
167 #ifdef USE_IODEBUG_HOOKS
170 /* cant write anything to a dead socket. */
174 #ifdef USE_IODEBUG_HOOKS
176 if(to
->localClient
->buf_sendq
.list
.head
)
177 hd
.arg1
= ((buf_line_t
*) to
->localClient
->buf_sendq
.list
.head
->data
)->buf
+
178 to
->localClient
->buf_sendq
.writeofs
;
181 if(linebuf_len(&to
->localClient
->buf_sendq
))
184 linebuf_flush(to
->localClient
->fd
, &to
->localClient
->buf_sendq
)) > 0)
186 /* We have some data written .. update counters */
187 #ifdef USE_IODEBUG_HOOKS
189 call_hook(h_iosend_id
, &hd
);
191 if(to
->localClient
->buf_sendq
.list
.head
)
193 ((buf_line_t
*) to
->localClient
->buf_sendq
.list
.head
->
194 data
)->buf
+ to
->localClient
->buf_sendq
.writeofs
;
198 to
->localClient
->sendB
+= retlen
;
199 me
.localClient
->sendB
+= retlen
;
200 if(to
->localClient
->sendB
> 1023)
202 to
->localClient
->sendK
+= (to
->localClient
->sendB
>> 10);
203 to
->localClient
->sendB
&= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */
205 else if(me
.localClient
->sendB
> 1023)
207 me
.localClient
->sendK
+= (me
.localClient
->sendB
>> 10);
208 me
.localClient
->sendB
&= 0x03ff;
212 if(retlen
== 0 || (retlen
< 0 && !ignoreErrno(errno
)))
218 if(ignoreErrno(errno
))
219 flags
= COMM_SELECT_WRITE
|COMM_SELECT_RETRY
;
221 flags
= COMM_SELECT_WRITE
;
222 if(linebuf_len(&to
->localClient
->buf_sendq
))
223 comm_setselect(fd
, FDLIST_IDLECLIENT
, flags
,
224 send_queued_write
, to
, 0);
227 /* send_queued_slink_write()
229 * inputs - fd to have queue sent, client we're sending to
230 * outputs - contents of queue
231 * side effects - write is rescheduled if queue isnt emptied
234 send_queued_slink_write(int fd
, void *data
)
236 struct Client
*to
= data
;
240 ** Once socket is marked dead, we cannot start writing to it,
241 ** even if the error is removed...
246 /* Next, lets try to write some data */
247 if(to
->localClient
->slinkq
)
249 retlen
= write(to
->localClient
->ctrlfd
,
250 to
->localClient
->slinkq
+ to
->localClient
->slinkq_ofs
,
251 to
->localClient
->slinkq_len
);
255 /* If we have a fatal error */
256 if(!ignoreErrno(errno
))
262 /* 0 bytes is an EOF .. */
270 to
->localClient
->slinkq_len
-= retlen
;
272 s_assert(to
->localClient
->slinkq_len
>= 0);
273 if(to
->localClient
->slinkq_len
)
274 to
->localClient
->slinkq_ofs
+= retlen
;
277 to
->localClient
->slinkq_ofs
= 0;
278 MyFree(to
->localClient
->slinkq
);
279 to
->localClient
->slinkq
= NULL
;
284 /* if we have any more data, reschedule a write */
285 if(to
->localClient
->slinkq_len
)
286 comm_setselect(to
->localClient
->ctrlfd
, FDLIST_IDLECLIENT
,
287 COMM_SELECT_WRITE
|COMM_SELECT_RETRY
, send_queued_slink_write
, to
, 0);
292 * inputs - client to send to, va_args
293 * outputs - client has message put into its queue
297 sendto_one(struct Client
*target_p
, const char *pattern
, ...)
302 /* send remote if to->from non NULL */
303 if(target_p
->from
!= NULL
)
304 target_p
= target_p
->from
;
306 if(IsIOError(target_p
))
309 linebuf_newbuf(&linebuf
);
311 va_start(args
, pattern
);
312 linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
315 _send_linebuf(target_p
, &linebuf
);
317 linebuf_donebuf(&linebuf
);
321 /* sendto_one_prefix()
323 * inputs - client to send to, va_args
324 * outputs - client has message put into its queue
325 * side effects - source(us)/target is chosen based on TS6 capability
328 sendto_one_prefix(struct Client
*target_p
, struct Client
*source_p
,
329 const char *command
, const char *pattern
, ...)
331 struct Client
*dest_p
;
335 /* send remote if to->from non NULL */
336 if(target_p
->from
!= NULL
)
337 dest_p
= target_p
->from
;
341 if(IsIOError(dest_p
))
346 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
350 linebuf_newbuf(&linebuf
);
351 va_start(args
, pattern
);
352 linebuf_putmsg(&linebuf
, pattern
, &args
,
354 get_id(source_p
, target_p
),
355 command
, get_id(target_p
, target_p
));
358 _send_linebuf(dest_p
, &linebuf
);
359 linebuf_donebuf(&linebuf
);
362 /* sendto_one_notice()
364 * inputs - client to send to, va_args
365 * outputs - client has a NOTICE put into its queue
366 * side effects - source(us)/target is chosen based on TS6 capability
369 sendto_one_notice(struct Client
*target_p
, const char *pattern
, ...)
371 struct Client
*dest_p
;
375 /* send remote if to->from non NULL */
376 if(target_p
->from
!= NULL
)
377 dest_p
= target_p
->from
;
381 if(IsIOError(dest_p
))
386 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
390 linebuf_newbuf(&linebuf
);
391 va_start(args
, pattern
);
392 linebuf_putmsg(&linebuf
, pattern
, &args
,
394 get_id(&me
, target_p
), get_id(target_p
, target_p
));
397 _send_linebuf(dest_p
, &linebuf
);
398 linebuf_donebuf(&linebuf
);
402 /* sendto_one_numeric()
404 * inputs - client to send to, va_args
405 * outputs - client has message put into its queue
406 * side effects - source/target is chosen based on TS6 capability
409 sendto_one_numeric(struct Client
*target_p
, int numeric
, const char *pattern
, ...)
411 struct Client
*dest_p
;
415 /* send remote if to->from non NULL */
416 if(target_p
->from
!= NULL
)
417 dest_p
= target_p
->from
;
421 if(IsIOError(dest_p
))
426 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Trying to send to myself!");
430 linebuf_newbuf(&linebuf
);
431 va_start(args
, pattern
);
432 linebuf_putmsg(&linebuf
, pattern
, &args
,
434 get_id(&me
, target_p
),
435 numeric
, get_id(target_p
, target_p
));
438 _send_linebuf(dest_p
, &linebuf
);
439 linebuf_donebuf(&linebuf
);
445 * inputs - pointer to client to NOT send to
446 * - caps or'd together which must ALL be present
447 * - caps or'd together which must ALL NOT be present
448 * - printf style format string
449 * - args to format string
451 * side effects - Send a message to all connected servers, except the
452 * client 'one' (if non-NULL), as long as the servers
453 * support ALL capabs in 'caps', and NO capabs in 'nocaps'.
455 * This function was written in an attempt to merge together the other
456 * billion sendto_*serv*() functions, which sprung up with capabs, uids etc
460 sendto_server(struct Client
*one
, struct Channel
*chptr
, unsigned long caps
,
461 unsigned long nocaps
, const char *format
, ...)
464 struct Client
*target_p
;
466 dlink_node
*next_ptr
;
469 /* noone to send to.. */
470 if(dlink_list_length(&serv_list
) == 0)
473 if(chptr
!= NULL
&& *chptr
->chname
!= '#')
476 linebuf_newbuf(&linebuf
);
477 va_start(args
, format
);
478 linebuf_putmsg(&linebuf
, format
, &args
, NULL
);
481 DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
483 target_p
= ptr
->data
;
485 /* check against 'one' */
486 if(one
!= NULL
&& (target_p
== one
->from
))
489 /* check we have required capabs */
490 if(!IsCapable(target_p
, caps
))
493 /* check we don't have any forbidden capabs */
494 if(!NotCapable(target_p
, nocaps
))
497 _send_linebuf(target_p
, &linebuf
);
500 linebuf_donebuf(&linebuf
);
504 /* sendto_channel_flags()
506 * inputs - server not to send to, flags needed, source, channel, va_args
507 * outputs - message is sent to channel members
511 sendto_channel_flags(struct Client
*one
, int type
, struct Client
*source_p
,
512 struct Channel
*chptr
, const char *pattern
, ...)
514 static char buf
[BUFSIZE
];
516 buf_head_t linebuf_local
;
517 buf_head_t linebuf_name
;
518 buf_head_t linebuf_id
;
519 struct Client
*target_p
;
520 struct membership
*msptr
;
522 dlink_node
*next_ptr
;
524 linebuf_newbuf(&linebuf_local
);
525 linebuf_newbuf(&linebuf_name
);
526 linebuf_newbuf(&linebuf_id
);
530 va_start(args
, pattern
);
531 ircvsnprintf(buf
, sizeof(buf
), pattern
, args
);
534 if(IsServer(source_p
))
535 linebuf_putmsg(&linebuf_local
, NULL
, NULL
,
536 ":%s %s", source_p
->name
, buf
);
538 linebuf_putmsg(&linebuf_local
, NULL
, NULL
,
540 source_p
->name
, source_p
->username
,
541 source_p
->host
, buf
);
543 linebuf_putmsg(&linebuf_name
, NULL
, NULL
, ":%s %s", source_p
->name
, buf
);
544 linebuf_putmsg(&linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
546 DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->members
.head
)
549 target_p
= msptr
->client_p
;
551 if(IsIOError(target_p
->from
) || target_p
->from
== one
)
554 if(type
&& ((msptr
->flags
& type
) == 0))
560 if(!MyClient(target_p
))
562 /* if we've got a specific type, target must support
565 if(type
&& NotCapable(target_p
->from
, CAP_CHW
))
568 if(target_p
->from
->serial
!= current_serial
)
570 if(has_id(target_p
->from
))
571 send_linebuf_remote(target_p
, source_p
, &linebuf_id
);
573 send_linebuf_remote(target_p
, source_p
, &linebuf_name
);
575 target_p
->from
->serial
= current_serial
;
579 _send_linebuf(target_p
, &linebuf_local
);
582 linebuf_donebuf(&linebuf_local
);
583 linebuf_donebuf(&linebuf_name
);
584 linebuf_donebuf(&linebuf_id
);
588 /* sendto_channel_local()
590 * inputs - flags to send to, channel to send to, va_args
591 * outputs - message to local channel members
595 sendto_channel_local(int type
, struct Channel
*chptr
, const char *pattern
, ...)
599 struct membership
*msptr
;
600 struct Client
*target_p
;
602 dlink_node
*next_ptr
;
604 linebuf_newbuf(&linebuf
);
606 va_start(args
, pattern
);
607 linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
610 DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
613 target_p
= msptr
->client_p
;
615 if(IsIOError(target_p
))
618 if(type
&& ((msptr
->flags
& type
) == 0))
621 _send_linebuf(target_p
, &linebuf
);
624 linebuf_donebuf(&linebuf
);
627 /* sendto_channel_local_butone()
629 * inputs - flags to send to, channel to send to, va_args
630 * - user to ignore when sending
631 * outputs - message to local channel members
635 sendto_channel_local_butone(struct Client
*one
, int type
, struct Channel
*chptr
, const char *pattern
, ...)
639 struct membership
*msptr
;
640 struct Client
*target_p
;
642 dlink_node
*next_ptr
;
644 linebuf_newbuf(&linebuf
);
646 va_start(args
, pattern
);
647 linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
650 DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
653 target_p
= msptr
->client_p
;
658 if(IsIOError(target_p
))
661 if(type
&& ((msptr
->flags
& type
) == 0))
664 _send_linebuf(target_p
, &linebuf
);
667 linebuf_donebuf(&linebuf
);
671 * sendto_common_channels_local()
673 * inputs - pointer to client
676 * side effects - Sends a message to all people on local server who are
677 * in same channel with user.
678 * used by m_nick.c and exit_one_client.
681 sendto_common_channels_local(struct Client
*user
, const char *pattern
, ...)
685 dlink_node
*next_ptr
;
687 dlink_node
*next_uptr
;
688 struct Channel
*chptr
;
689 struct Client
*target_p
;
690 struct membership
*msptr
;
691 struct membership
*mscptr
;
694 linebuf_newbuf(&linebuf
);
695 va_start(args
, pattern
);
696 linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
701 DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
704 chptr
= mscptr
->chptr
;
706 DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
709 target_p
= msptr
->client_p
;
711 if(IsIOError(target_p
) ||
712 target_p
->serial
== current_serial
)
715 target_p
->serial
= current_serial
;
716 send_linebuf(target_p
, &linebuf
);
720 /* this can happen when the user isnt in any channels, but we still
721 * need to send them the data, ie a nick change
723 if(MyConnect(user
) && (user
->serial
!= current_serial
))
724 send_linebuf(user
, &linebuf
);
726 linebuf_donebuf(&linebuf
);
730 * sendto_common_channels_local_butone()
732 * inputs - pointer to client
735 * side effects - Sends a message to all people on local server who are
736 * in same channel with user, except for user itself.
739 sendto_common_channels_local_butone(struct Client
*user
, const char *pattern
, ...)
743 dlink_node
*next_ptr
;
745 dlink_node
*next_uptr
;
746 struct Channel
*chptr
;
747 struct Client
*target_p
;
748 struct membership
*msptr
;
749 struct membership
*mscptr
;
752 linebuf_newbuf(&linebuf
);
753 va_start(args
, pattern
);
754 linebuf_putmsg(&linebuf
, pattern
, &args
, NULL
);
758 /* Skip them -- jilles */
759 user
->serial
= current_serial
;
761 DLINK_FOREACH_SAFE(ptr
, next_ptr
, user
->user
->channel
.head
)
764 chptr
= mscptr
->chptr
;
766 DLINK_FOREACH_SAFE(uptr
, next_uptr
, chptr
->locmembers
.head
)
769 target_p
= msptr
->client_p
;
771 if(IsIOError(target_p
) ||
772 target_p
->serial
== current_serial
)
775 target_p
->serial
= current_serial
;
776 send_linebuf(target_p
, &linebuf
);
780 linebuf_donebuf(&linebuf
);
783 /* sendto_match_butone()
785 * inputs - server not to send to, source, mask, type of mask, va_args
787 * side effects - message is sent to matching clients
790 sendto_match_butone(struct Client
*one
, struct Client
*source_p
,
791 const char *mask
, int what
, const char *pattern
, ...)
793 static char buf
[BUFSIZE
];
795 struct Client
*target_p
;
797 dlink_node
*next_ptr
;
798 buf_head_t linebuf_local
;
799 buf_head_t linebuf_name
;
800 buf_head_t linebuf_id
;
802 linebuf_newbuf(&linebuf_local
);
803 linebuf_newbuf(&linebuf_name
);
804 linebuf_newbuf(&linebuf_id
);
806 va_start(args
, pattern
);
807 ircvsnprintf(buf
, sizeof(buf
), pattern
, args
);
810 if(IsServer(source_p
))
811 linebuf_putmsg(&linebuf_local
, NULL
, NULL
,
812 ":%s %s", source_p
->name
, buf
);
814 linebuf_putmsg(&linebuf_local
, NULL
, NULL
,
816 source_p
->name
, source_p
->username
,
817 source_p
->host
, buf
);
819 linebuf_putmsg(&linebuf_name
, NULL
, NULL
, ":%s %s", source_p
->name
, buf
);
820 linebuf_putmsg(&linebuf_id
, NULL
, NULL
, ":%s %s", use_id(source_p
), buf
);
822 if(what
== MATCH_HOST
)
824 DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
826 target_p
= ptr
->data
;
828 if(match(mask
, target_p
->host
))
829 _send_linebuf(target_p
, &linebuf_local
);
832 /* what = MATCH_SERVER, if it doesnt match us, just send remote */
833 else if(match(mask
, me
.name
))
835 DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
837 target_p
= ptr
->data
;
838 _send_linebuf(target_p
, &linebuf_local
);
842 DLINK_FOREACH(ptr
, serv_list
.head
)
844 target_p
= ptr
->data
;
850 send_linebuf_remote(target_p
, source_p
, &linebuf_id
);
852 send_linebuf_remote(target_p
, source_p
, &linebuf_name
);
855 linebuf_donebuf(&linebuf_local
);
856 linebuf_donebuf(&linebuf_id
);
857 linebuf_donebuf(&linebuf_name
);
860 /* sendto_match_servs()
862 * inputs - source, mask to send to, caps needed, va_args
864 * side effects - message is sent to matching servers with caps.
867 sendto_match_servs(struct Client
*source_p
, const char *mask
, int cap
,
868 int nocap
, const char *pattern
, ...)
870 static char buf
[BUFSIZE
];
873 struct Client
*target_p
;
874 buf_head_t linebuf_id
;
875 buf_head_t linebuf_name
;
877 if(EmptyString(mask
))
880 linebuf_newbuf(&linebuf_id
);
881 linebuf_newbuf(&linebuf_name
);
883 va_start(args
, pattern
);
884 ircvsnprintf(buf
, sizeof(buf
), pattern
, args
);
887 linebuf_putmsg(&linebuf_id
, NULL
, NULL
,
888 ":%s %s", use_id(source_p
), buf
);
889 linebuf_putmsg(&linebuf_name
, NULL
, NULL
,
890 ":%s %s", source_p
->name
, buf
);
894 DLINK_FOREACH(ptr
, global_serv_list
.head
)
896 target_p
= ptr
->data
;
898 /* dont send to ourselves, or back to where it came from.. */
899 if(IsMe(target_p
) || target_p
->from
== source_p
->from
)
902 if(target_p
->from
->serial
== current_serial
)
905 if(match(mask
, target_p
->name
))
907 /* if we set the serial here, then we'll never do
908 * a match() again if !IsCapable()
910 target_p
->from
->serial
= current_serial
;
912 if(cap
&& !IsCapable(target_p
->from
, cap
))
915 if(nocap
&& !NotCapable(target_p
->from
, nocap
))
918 if(has_id(target_p
->from
))
919 _send_linebuf(target_p
->from
, &linebuf_id
);
921 _send_linebuf(target_p
->from
, &linebuf_name
);
925 linebuf_donebuf(&linebuf_id
);
926 linebuf_donebuf(&linebuf_name
);
931 * inputs - target, source, va_args
933 * side effects - client is sent message with correct prefix.
936 sendto_anywhere(struct Client
*target_p
, struct Client
*source_p
,
937 const char *command
, const char *pattern
, ...)
942 linebuf_newbuf(&linebuf
);
944 va_start(args
, pattern
);
946 if(MyClient(target_p
))
948 if(IsServer(source_p
))
949 linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
950 source_p
->name
, command
,
953 linebuf_putmsg(&linebuf
, pattern
, &args
,
955 source_p
->name
, source_p
->username
,
956 source_p
->host
, command
,
960 linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s %s %s ",
961 get_id(source_p
, target_p
), command
,
962 get_id(target_p
, target_p
));
965 if(MyClient(target_p
))
966 _send_linebuf(target_p
, &linebuf
);
968 send_linebuf_remote(target_p
, source_p
, &linebuf
);
970 linebuf_donebuf(&linebuf
);
973 /* sendto_realops_flags()
975 * inputs - umode needed, level (opers/admin), va_args
977 * side effects - message is sent to opers with matching umodes
980 sendto_realops_flags(int flags
, int level
, const char *pattern
, ...)
982 struct Client
*client_p
;
984 dlink_node
*next_ptr
;
988 linebuf_newbuf(&linebuf
);
990 va_start(args
, pattern
);
991 linebuf_putmsg(&linebuf
, pattern
, &args
,
992 ":%s NOTICE * :*** Notice -- ", me
.name
);
995 DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
997 client_p
= ptr
->data
;
999 /* If we're sending it to opers and theyre an admin, skip.
1000 * If we're sending it to admins, and theyre not, skip.
1002 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1003 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1006 if(client_p
->umodes
& flags
)
1007 _send_linebuf(client_p
, &linebuf
);
1010 linebuf_donebuf(&linebuf
);
1013 /* sendto_realops_snomask()
1015 * inputs - snomask needed, level (opers/admin), va_args
1017 * side effects - message is sent to opers with matching snomasks
1020 sendto_realops_snomask(int flags
, int level
, const char *pattern
, ...)
1022 static char buf
[BUFSIZE
];
1024 struct Client
*client_p
;
1026 dlink_node
*next_ptr
;
1030 linebuf_newbuf(&linebuf
);
1032 /* Be very sure not to do things like "Trying to send to myself"
1033 * L_NETWIDE, otherwise infinite recursion may result! -- jilles */
1034 if (level
& L_NETWIDE
&& ConfigFileEntry
.global_snotices
)
1036 /* rather a lot of copying around, oh well -- jilles */
1037 va_start(args
, pattern
);
1038 ircvsnprintf(buf
, sizeof(buf
), pattern
, args
);
1040 linebuf_putmsg(&linebuf
, pattern
, NULL
,
1041 ":%s NOTICE * :*** Notice -- %s", me
.name
, buf
);
1042 snobuf
= construct_snobuf(flags
);
1043 if (snobuf
[1] != '\0')
1045 sendto_server(NULL
, NULL
, CAP_ENCAP
|CAP_TS6
, NOCAPS
,
1046 ":%s ENCAP * SNOTE %c :%s",
1047 me
.id
, snobuf
[1], buf
);
1048 sendto_server(NULL
, NULL
, CAP_ENCAP
, CAP_TS6
,
1049 ":%s ENCAP * SNOTE %c :%s",
1050 me
.name
, snobuf
[1], buf
);
1055 va_start(args
, pattern
);
1056 linebuf_putmsg(&linebuf
, pattern
, &args
,
1057 ":%s NOTICE * :*** Notice -- ", me
.name
);
1060 level
&= ~L_NETWIDE
;
1062 DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1064 client_p
= ptr
->data
;
1066 /* If we're sending it to opers and theyre an admin, skip.
1067 * If we're sending it to admins, and theyre not, skip.
1069 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1070 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1073 if(client_p
->snomask
& flags
)
1074 _send_linebuf(client_p
, &linebuf
);
1077 linebuf_donebuf(&linebuf
);
1079 /* sendto_realops_snomask_from()
1081 * inputs - snomask needed, level (opers/admin), source server, va_args
1083 * side effects - message is sent to opers with matching snomask
1086 sendto_realops_snomask_from(int flags
, int level
, struct Client
*source_p
,
1087 const char *pattern
, ...)
1089 struct Client
*client_p
;
1091 dlink_node
*next_ptr
;
1095 linebuf_newbuf(&linebuf
);
1097 va_start(args
, pattern
);
1098 linebuf_putmsg(&linebuf
, pattern
, &args
,
1099 ":%s NOTICE * :*** Notice -- ", source_p
->name
);
1102 DLINK_FOREACH_SAFE(ptr
, next_ptr
, local_oper_list
.head
)
1104 client_p
= ptr
->data
;
1106 /* If we're sending it to opers and theyre an admin, skip.
1107 * If we're sending it to admins, and theyre not, skip.
1109 if(((level
== L_ADMIN
) && !IsOperAdmin(client_p
)) ||
1110 ((level
== L_OPER
) && IsOperAdmin(client_p
)))
1113 if(client_p
->snomask
& flags
)
1114 _send_linebuf(client_p
, &linebuf
);
1117 linebuf_donebuf(&linebuf
);
1121 * sendto_wallops_flags
1123 * inputs - flag types of messages to show to real opers
1124 * - client sending request
1125 * - var args input message
1127 * side effects - Send a wallops to local opers
1130 sendto_wallops_flags(int flags
, struct Client
*source_p
, const char *pattern
, ...)
1132 struct Client
*client_p
;
1134 dlink_node
*next_ptr
;
1138 linebuf_newbuf(&linebuf
);
1140 va_start(args
, pattern
);
1142 if(IsPerson(source_p
))
1143 linebuf_putmsg(&linebuf
, pattern
, &args
,
1144 ":%s!%s@%s WALLOPS :", source_p
->name
,
1145 source_p
->username
, source_p
->host
);
1147 linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s WALLOPS :", source_p
->name
);
1151 DLINK_FOREACH_SAFE(ptr
, next_ptr
, IsPerson(source_p
) && flags
== UMODE_WALLOP
? lclient_list
.head
: local_oper_list
.head
)
1153 client_p
= ptr
->data
;
1155 if(client_p
->umodes
& flags
)
1156 _send_linebuf(client_p
, &linebuf
);
1159 linebuf_donebuf(&linebuf
);
1164 * input - client to send kill to, client to kill, va_args
1166 * side effects - we issue a kill for the client
1169 kill_client(struct Client
*target_p
, struct Client
*diedie
, const char *pattern
, ...)
1174 linebuf_newbuf(&linebuf
);
1176 va_start(args
, pattern
);
1177 linebuf_putmsg(&linebuf
, pattern
, &args
, ":%s KILL %s :",
1178 get_id(&me
, target_p
), get_id(diedie
, target_p
));
1181 send_linebuf(target_p
, &linebuf
);
1182 linebuf_donebuf(&linebuf
);
1187 * kill_client_serv_butone
1189 * inputs - pointer to client to not send to
1190 * - pointer to client to kill
1192 * side effects - Send a KILL for the given client
1193 * message to all connected servers
1194 * except the client 'one'. Also deal with
1195 * client being unknown to leaf, as in lazylink...
1198 kill_client_serv_butone(struct Client
*one
, struct Client
*target_p
, const char *pattern
, ...)
1200 static char buf
[BUFSIZE
];
1202 struct Client
*client_p
;
1204 dlink_node
*next_ptr
;
1205 buf_head_t linebuf_id
;
1206 buf_head_t linebuf_name
;
1208 linebuf_newbuf(&linebuf_name
);
1209 linebuf_newbuf(&linebuf_id
);
1211 va_start(args
, pattern
);
1212 ircvsnprintf(buf
, sizeof(buf
), pattern
, args
);
1215 linebuf_putmsg(&linebuf_name
, NULL
, NULL
, ":%s KILL %s :%s",
1216 me
.name
, target_p
->name
, buf
);
1217 linebuf_putmsg(&linebuf_id
, NULL
, NULL
, ":%s KILL %s :%s",
1218 use_id(&me
), use_id(target_p
), buf
);
1220 DLINK_FOREACH_SAFE(ptr
, next_ptr
, serv_list
.head
)
1222 client_p
= ptr
->data
;
1224 /* ok, if the client we're supposed to not send to has an
1225 * ID, then we still want to issue the kill there..
1227 if(one
!= NULL
&& (client_p
== one
->from
) &&
1228 (!has_id(client_p
) || !has_id(target_p
)))
1231 if(has_id(client_p
))
1232 _send_linebuf(client_p
, &linebuf_id
);
1234 _send_linebuf(client_p
, &linebuf_name
);
1237 linebuf_donebuf(&linebuf_id
);
1238 linebuf_donebuf(&linebuf_name
);